问题描述
小明被不明势力劫持。后被扔到x星站再无问津。小明得知每天都有飞船飞往地球,但需要108元的船票,而他却身无分文。
他决定在x星战打工。好心的老板答应包食宿,第1天给他1元钱。
并且,以后的每一天都比前一天多2元钱,直到他有足够的钱买票。
请计算一下,小明在第几天就能凑够108元,返回地球。
答案提交
要求提交的是一个整数,表示第几天。请不要提交任何多余的内容。
11
calcCode:
public class Test {
public static void main(String[] args) {
int i = 1, num = 1, sum = 1;
while (sum < 108) {
sum += num += 2;
i++;
}
System.out.print(i);
}
}
简单模拟
问题描述
5只猴子是好朋友,在海边的椰子树上睡着了。这期间,有商船把一大堆香蕉忘记在沙滩上离去。
第1只猴子醒来,把香蕉均分成5堆,还剩下1个,就吃掉并把自己的一份藏起来继续睡觉。
第2只猴子醒来,重新把香蕉均分成5堆,还剩下2个,就吃掉并把自己的一份藏起来继续睡觉。
第3只猴子醒来,重新把香蕉均分成5堆,还剩下3个,就吃掉并把自己的一份藏起来继续睡觉。
第4只猴子醒来,重新把香蕉均分成5堆,还剩下4个,就吃掉并把自己的一份藏起来继续睡觉。
第5只猴子醒来,重新把香蕉均分成5堆,哈哈,正好不剩!
请计算一开始最少有多少个香蕉。
答案提交
需要提交的是一个整数,不要填写任何多余的内容。
3141
calcCode:
public class Test {
public static void main(String[] args) {
int i, n;
for (i = n = 1; true; n = ++i) {
if (n % 5 != 1) continue;
n = n / 5 * 4;
if (n % 5 != 2) continue;
n = n / 5 * 4;
if (n % 5 != 3) continue;
n = n / 5 * 4;
if (n % 5 != 4) continue;
n = n / 5 * 4;
if (n > 0 && n % 5 == 0) break;
}
System.out.print(i);
}
}
因为整形运算的结果只会保留整数部分,也就是向下取整,而题目中描述的常量都是对除数做的余数,根据Java运算符的结合顺序,这么写就完事了
不优雅,但实用
还是简单模拟
问题描述
仔细寻找,会发现:在下面的8x8的方阵中,隐藏着字母序列:“LANQIAO”。
SLANQIAO
ZOEXCCGB
MOAYWKHI
BCCIPLJQ
SLANQIAO
RSFWFNYA
XIFZVWAL
COAIQNAL
我们约定: 序列可以水平,垂直,或者是斜向;
并且走向不限(实际上就是有一共8种方向)。
上图中一共有4个满足要求的串。
下面有一个更大的(100x100)的字母方阵。
你能算出其中隐藏了多少个“LANQIAO”吗?
FOAIQNALWIKEGNICJWAOSXDHTHZPOLGYELORAUHOHCZIERPTOOJUITQJCFNIYYQHSBEABBQZPNGYQTCLSKZFCYWDGOAIADKLSNGJ
GSOZTQKCCSDWGUWAUOZKNILGVNLMCLXQVBJENIHIVLRPVVXXFTHQUXUAVZZOFFJHYLMGTLANQIAOQQILCDCJERJASNCTLYGRMHGF
TSDFYTLVIBHKLJVVJUDMKGJZGNNSTPVLCKTOFMUEUFSVQIAUVHNVFTGBDDARPKYNNCUOYUAZXQJNOEEYKLFRMOEMHUKJTPETHLES
FKVINSLWEVGAGMKVFVIUBMYOIAFHLVNKNTYKTZWVXQWRWIGPENFXYDTKRVPKRTHMGHVYOCLDCKMEKRLGEKBYUCLOLYPAKPFSOREH
KWPUOLOVMOFBIXYACWRDYBINTMPASPCEOKHXQIGBQQMCEOIVULIEOPFSCSIHENAJCVDPJDOIWIIULFDNOZOFVAMCABVGKAKCOZMG
XWMYRTAFGFOCNHLBGNGOXPJSTWLZUNNAGIRETGXFWAQSSJPFTQAXMTQWMZWYVEPQERKSWTSCHSQOOBGXAQTBCHOEGBDVKGWJIFTG
ZWWJEIISPLMXIMGHOOGDRZFTGNDDWDWMNUFWJYJGULPHNUFSAQNNIUVAAFZIAZKFXXNWCEABGJAUMGYEIEFVQXVHHHEDYUITRCQB
XZHDPZQTOBECJVBZLACVXACZEDYOGVAVQRNWEOWGRAQYUEUESTEDQTYJUTEFOOITSHDDZHONJGBRCWNEQLZUTBNQIADKNFIOMWZR
EBFKCVNLURZSNPOLTISRPDTNUMCDGKTYRGIOVEPTUTSBAWQKWWEUWIWHAANUZUADGZEATZOQICWFUJTWNZDBKLQNELWVTBNDLNFH
PESISEATZNCDFRMXBQUKBFTIGYSFCWVHPMSUSD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VXJJGWBCRAVKZFWFBKMBRVBFD
HKACSZIUWUXLWKFPKOCUQJEPQDZCMUJFLVCLIOQQRVKSWFIAKNHMRLNJTKGVNTGLCVPVMBLJANOBCXUGVWBJYSIXZQVAVFWILWFB
QWNLTPMCYHRSKVHXLONRANWKWXUTHYQLIOFKGDBMSWDRCYRKVSAGGRJMWQYQFLMUIGGCLAUQAACTYLPZEOJBHMWRKHCRXGTGRMUP
CPQKJRBLYDNPUGHCRBVYBAIRVCAWLBWVWCMKNBIRKJOUGYQEBQRHDSTWXDIWGRVMLIJFBWHLHCDAAVUDLZSCGQNOUXVUIVIZZZMD
NMHGYPFUUDWKQGTAKKGCDFJFYJFNRZVXDPGZEAMWQVQZODKTXHIYFVKJSSAWVHYCUCZMLLBPXTILDYJQEMWDRUFKISOUVPUDTYPB
FDAQUBXHUJYTAYNWVIJNUSQDTQDEMUAPWXRYUWONTBDZCHZOUEGPMWEZTQWWSHAYOBWVTDIMZYNVNZKUHOFCQKPHJXWNRCGUJEKO
WSDAUGUTVWCVHEMOIRJJGTANUWTSAIXXEVZTBDHPGSRHHVWCDZVZYRJTLONIJVXEATHQXOUKBIGZONFRSZIOGWNTYAJYLQCGEOWY
答案提交
请提交一个整数,不要填写任何多余的内容。
41
calcCode:
import java.io.IOException;
import java.io.InputStream;
import java.io.FileInputStream;
import java.util.ArrayDeque;
import java.util.Deque;
public class Test {
public static void main(String[] args) throws IOException {
char[] word = {
'L', 'A', 'N', 'Q', 'I', 'A', 'O' };
InputStream data = new FileInputStream("C:\\Users\\admin\\Desktop\\data.txt");
InputReader in = new InputReader(data);
Deque<Integer> ns = new ArrayDeque();
Deque<Integer> ms = new ArrayDeque();
char[][] map = new char[100][100];
for (int i = 0; i < 100; i++)
for (int j = 0; j < 100; j++) {
map[i][j] = in.nextChar();
if (map[i][j] == 'L') {
ns.push(i);
ms.push(j);
}
}
int[] nadd = {
1, -1, 0, 0, 1, 1, -1, -1};
int[] madd = {
0, 0, 1, -1, 1, -1, -1, 1};
int cnt = 0;
while (!ns.isEmpty()) {
int n = ns.pop();
int m = ms.pop();
int i, j, k, z = 8;
while (z-- > 0) {
for (k = 0, i = n, j = m; k < 7 && i >= 0 && i < 100 && j >= 0 && j < 100; k++, i += nadd[z], j += madd[z])
if (map[i][j] != word[k]) break;
if (k == 7) cnt++;
}
}
System.out.print(cnt);
}
static class InputReader {
InputStream in;
int next, len;
byte[] buff;
InputReader(InputStream in) {
this(in, 8192); }
InputReader(InputStream in, int buffSize) {
this.buff = new byte[buffSize];
this.next = this.len = 0;
this.in = in;
}
int getByte() {
if (next >= len)
try {
next = 0;
len = in.read(buff);
if (len == -1) return -1;
} catch (IOException e) {
}
return buff[next++];
}
char nextChar() {
int c = getByte();
while (c <= 32 || c == 127) c = getByte();
return (char)c;
}
}
}
比较恶心的模拟
题目没读全,不过代码质量还行,就挂着吧
import java.io.IOException;
import java.io.InputStream;
import java.io.FileInputStream;
public class Test {
public static void main(String[] args) throws IOException {
char[] word = {
'L', 'A', 'N', 'Q', 'I', 'A', 'O' };
InputStream data = new FileInputStream("C:\\Users\\admin\\Desktop\\data.txt");
InputReader in = new InputReader(data);
int i = 0, c = 0, cnt = 0;
while (-1 != (c = in.getByte())) {
if (c <= 32 || c == 127) continue;
if (i == 7) {
i = 0;
cnt++;
}
if (c == word[i]) i++;
else i = 0;
}
System.out.print(cnt);
}
static class InputReader {
. . . }
}
问题描述
到x星球旅行的游客都被发给一个整数,作为游客编号。
x星的国王有个怪癖,他只喜欢数字3,5和7。
国王规定,游客的编号如果只含有因子:3,5,7,就可以获得一份奖品。
我们来看前10个幸运数字是:
3 5 7 9 15 21 25 27 35 45
因而第11个幸运数字是:49
小明领到了一个幸运数字 59084709587505,他去领奖的时候,人家要求他准确地说出这是第几个幸运数字,否则领不到奖品。
请你帮小明计算一下,59084709587505是第几个幸运数字。
答案提交
需要提交的是一个整数,请不要填写任何多余内容
1905
calcCode:
public class Test {
public static void main(String[] args) {
long n = 59084709587505L, cnt = 0;
for (long a = 1; a <= n; a *= 3)
for (long b = 1; b <= n; b *= 5)
for (long c = 1; c <= n; c *= 7)
if (a * b * c <= n && a * b * c > 0) cnt++;
System.out.print(cnt - 1);
}
}
因为记录了 1,而 1 不包含上述三个因子,因此要减去 1
a * b * c > 0
是比较溢出的值,小于 0 就是大于 Long.MAX_VALUE
,等同于大于 n
问题描述
2004年起,国际ISBN中心出版了《13位国际标准书号指南》。
原有10位书号前加978作为商品分类标识;校验规则也改变。
校验位的加权算法与10位ISBN的算法不同,具体算法是:
用1分别乘ISBN的前12位中的奇数位(从左边开始数起),用3乘以偶数位,乘积之和以10为模,10与模值的差值再对10取模(即取个位的数字)即可得到校验位的值,其值范围应该为0~9。
下面的程序实现了该算法,请仔细阅读源码,填写缺失的部分。
public class A
{
static boolean f(String s){
int k=1;
int sum = 0;
for(int i=0; i<s.length(); i++){
char c = s.charAt(i);
if(c=='-' || c==' ') continue;
sum += ______________________________; //填空
k++;
if(k>12) break;
}
return s.charAt(s.length()-1)-'0' == (10-sum % 10)%10;
}
public static void main(String[] args){
System.out.println(f("978-7-301-04815-3"));
System.out.println(f("978-7-115-38821-6"));
}
}
答案提交
注意:只提交空缺的代码,不要抄写已经存在的代码。
(c - ‘0’) * (1 == (k & 1)? 1: 3);
题目描述的很清晰,没啥好说的
问题描述
如下的程序目的是在控制台打印输出大X。
可以控制两个参数:图形的高度,以及笔宽。
用程序中的测试数据输出效果:
(如果显示有问题,可以参看p1.png)
高度=15, 笔宽=3
*** ***
*** ***
*** ***
*** ***
*** ***
*** ***
*****
***
*****
*** ***
*** ***
*** ***
*** ***
*** ***
*** ***
高度=8, 笔宽=5
***** *****
**********
********
******
******
********
**********
***** *****
public class A
{
static void f(int h, int w){
System.out.println(String.format("高度=%d, 笔宽=%d",h,w));
int a1 = 0;
int a2 = h - 1;
for(int k=0; k<h; k++){
int p = Math.min(a1,a2);
int q = Math.max(a1+w,a2+w);
for(int i=0; i<p; i++) System.out.print(" ");
if(q-p<w*2){
____________________________________________ ; //填空
}
else{
for(int i=0; i<w; i++) System.out.print("*");
for(int i=0; i<q-p-w*2; i++) System.out.print(" ");
for(int i=0; i<w; i++) System.out.print("*");
}
System.out.println();
a1++;
a2--;
}
}
public static void main(String[] args){
f(15,3);
f(8,5);
}
}
答案提交
注意:只填写缺失的代码,不要拷贝已经存在的代码。
while (p++ < q) System.out.print("*");
p,q 代表当前行起始和结束的位置,当 q - p < w * 2
时,代表撇捺已经重合,行开始的缩紧在前面的代码中已经完成了,所以直接循环打印就行
问题描述
在电子计算机普及以前,人们经常用一个粗略的方法来验算四则运算是否正确。
比如:248 * 15 = 3720
把乘数和被乘数分别逐位求和,如果是多位数再逐位求和,直到是1位数,得
2 + 4 + 8 = 14 ==> 1 + 4 = 5;
1 + 5 = 6
5 * 6
而结果逐位求和为 3
5 * 6 的结果逐位求和与3符合,说明正确的可能性很大!!(不能排除错误)
请你写一个计算机程序,对给定的字符串逐位求和
资源约定
峰值内存消耗(含虚拟机) < 256M
CPU消耗 < 1000ms
输入格式
输入为一个由数字组成的串,表示n位数(n<1000);
输出格式
输出为一位数,表示反复逐位求和的结果。
测试样例1
Input:
35379
Output:
9
测试样例2
Input:
7583676109608471656473500295825
Output:
1
code:
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
byte[] buff = new byte[1024];
int len = System.in.read(buff);
int[] a = new int[len];
for (int i = 0; i < len; i++)
a[i] = byteToValue(buff[i]);
while (len > 1) {
for (int i = 1; i < len; i++) a[0] += a[i];
for (int i = 0, pre = a[0]; pre != 0; len = ++i) {
a[i] = pre % 10;
pre /= 10;
}
}
System.out.print(a[0]);
}
static int byteToValue(byte n) {
return n > '0' && n < '9'? n & 0xf: 0; }
}
一定程度上可以归类为高精度,没啥好说的
问题描述
本题目要求你在控制台输出一个由数字组成的等腰三角形。
具体的步骤是:
1
2 1
3 8
4 1
5 7
6 1
7 6
891011121314151
显示不正确时,参看:p1.png
资源约定
峰值内存消耗(含虚拟机) < 256M
CPU消耗 < 1000ms
输入格式
一个正整数n(3
输出格式
用数字填充的等腰三角形。
测试样例1
Input:
5
Output:
....1
...2.1
..3...2
.4.....1
567891011
测试样例2
Input:
10
Output:
.........1
........2.2
.......3...2
......4.....2
.....5.......1
....6.........2
...7...........0
..8.............2
.9...............9
1011121314151617181
测试样例3
Input:
15
Output:
..............1
.............2.3
............3...2
...........4.....3
..........5.......1
.........6.........3
........7...........0
.......8.............3
......9...............9
.....1.................2
....0...................8
...1.....................2
..1.......................7
.1.........................2
21314151617181920212223242526
n < 300
也就是数字串长度不超过 600,可以先打个表
想用 js 打表,但怕犯规
import java.math.BigInteger;
public class Test {
public static void main(String[] args) {
BigInteger n = BigInteger.ZERO;
StringBuilder table = new StringBuilder();
while (table.length() < 600)
table.append(n = n.add(BigInteger.ONE));
for (char i: table.toString().toCharArray())
System.out.print((byte)i + ", ");
}
}
code:
import java.io.*;
public class Main {
static final byte[] table = {
50, 51, 52, 53, 54, 55, 56, 57, 49, 48, 49, 49, 49, 50, 49, 51, 49, 52, 49, 53, 49, 54, 49, 55, 49, 56, 49, 57, 50, 48, 50, 49, 50, 50, 50, 51, 50, 52, 50, 53, 50, 54, 50, 55, 50, 56, 50, 57, 51, 48, 51, 49, 51, 50, 51, 51, 51, 52, 51, 53, 51, 54, 51, 55, 51, 56, 51, 57, 52, 48, 52, 49, 52, 50, 52, 51, 52, 52, 52, 53, 52, 54, 52, 55, 52, 56, 52, 57, 53, 48, 53, 49, 53, 50, 53, 51, 53, 52, 53, 53, 53, 54, 53, 55, 53, 56, 53, 57, 54, 48, 54, 49, 54, 50, 54, 51, 54, 52, 54, 53, 54, 54, 54, 55, 54, 56, 54, 57, 55, 48, 55, 49, 55, 50, 55, 51, 55, 52, 55, 53, 55, 54, 55, 55, 55, 56, 55, 57, 56, 48, 56, 49, 56, 50, 56, 51, 56, 52, 56, 53, 56, 54, 56, 55, 56, 56, 56, 57, 57, 48, 57, 49, 57, 50, 57, 51, 57, 52, 57, 53, 57, 54, 57, 55, 57, 56, 57, 57, 49, 48, 48, 49, 48, 49, 49, 48, 50, 49, 48, 51, 49, 48, 52, 49, 48, 53, 49, 48, 54, 49, 48, 55, 49, 48, 56, 49, 48, 57, 49, 49, 48, 49, 49, 49, 49, 49, 50, 49, 49, 51, 49, 49, 52, 49, 49, 53, 49, 49, 54, 49, 49, 55, 49, 49, 56, 49, 49, 57, 49, 50, 48, 49, 50, 49, 49, 50, 50, 49, 50, 51, 49, 50, 52, 49, 50, 53, 49, 50, 54, 49, 50, 55, 49, 50, 56, 49, 50, 57, 49, 51, 48, 49, 51, 49, 49, 51, 50, 49, 51, 51, 49, 51, 52, 49, 51, 53, 49, 51, 54, 49, 51, 55, 49, 51, 56, 49, 51, 57, 49, 52, 48, 49, 52, 49, 49, 52, 50, 49, 52, 51, 49, 52, 52, 49, 52, 53, 49, 52, 54, 49, 52, 55, 49, 52, 56, 49, 52, 57, 49, 53, 48, 49, 53, 49, 49, 53, 50, 49, 53, 51, 49, 53, 52, 49, 53, 53, 49, 53, 54, 49, 53, 55, 49, 53, 56, 49, 53, 57, 49, 54, 48, 49, 54, 49, 49, 54, 50, 49, 54, 51, 49, 54, 52, 49, 54, 53, 49, 54, 54, 49, 54, 55, 49, 54, 56, 49, 54, 57, 49, 55, 48, 49, 55, 49, 49, 55, 50, 49, 55, 51, 49, 55, 52, 49, 55, 53, 49, 55, 54, 49, 55, 55, 49, 55, 56, 49, 55, 57, 49, 56, 48, 49, 56, 49, 49, 56, 50, 49, 56, 51, 49, 56, 52, 49, 56, 53, 49, 56, 54, 49, 56, 55, 49, 56, 56, 49, 56, 57, 49, 57, 48, 49, 57, 49, 49, 57, 50, 49, 57, 51, 49, 57, 52, 49, 57, 53, 49, 57, 54, 49, 57, 55, 49, 57, 56, 49, 57, 57, 50, 48, 48, 50, 48, 49, 50, 48, 50, 50, 48, 51, 50, 48, 52, 50, 48, 53, 50, 48, 54, 50, 48, 55, 50, 48, 56, 50, 48, 57, 50, 49, 48, 50, 49, 49, 50, 49, 50, 50, 49, 51, 50, 49, 52, 50, 49, 53, 50, 49, 54, 50, 49, 55, 50, 49, 56, 50, 49, 57, 50, 50, 48, 50, 50, 49, 50, 50, 50, 50, 50, 51, 50, 50, 52, 50, 50, 53, 50, 50, 54, 50, 50, 55, 50, 50, 56, 50, 50, 57, 50, 51, 48, 50, 51, 49, 50, 51, 50, 50, 51, 51, 50, 51, 52, 50, 51, 53, 50, 51, 54 };
public static void main(String[] args) throws IOException {
int n = nextInt(System.in);
PrintStream out = System.out;
int start = 0, end = n * 4 - 6, left = n - 2, space = 1;
for (int i = 0; i <= left; i++) out.write(46);
out.print("1\n");
while (left > 0) {
for (int i = 0; i < left; i++) out.write(46);
out.write(table[start]);
for (int i = 0; i < space; i++) out.write(46);
out.write(table[end]);
out.write('\n');
space+=2;
start++;
left--;
end--;
}
out.write(table, start, n * 2 - 1);
}
static int nextInt(InputStream in) throws IOException {
int n = 0, c = in.read();
while (c < '0' || c > '9') c = in.read();
while (c >='0' && c <='9') {
n = n * 10 + (c & 0xf);
c = in.read();
}
return n;
}
}
写着写着就成找规律了
问题描述
班里N个小朋友,每个人都有自己最崇拜的一个小朋友(也可以是自己)。
在一个游戏中,需要小朋友坐一个圈,
每个小朋友都有自己最崇拜的小朋友在他的右手边。
求满足条件的圈最大多少人?
小朋友编号为1,2,3,…N
资源约定
峰值内存消耗(含虚拟机) < 256M
CPU消耗 < 1000ms
输入格式
输入第一行,一个整数N(3
输出格式
要求输出一个整数,表示满足条件的最大圈的人数。
测试样例1
Input:
9
3 4 2 5 3 8 4 6 9
Output:
4
Explanation:
如图p1.png所示,崇拜关系用箭头表示,红色表示不在圈中。
显然,最大圈是[2 4 5 3] 构成的圈
测试样例2
Input:
30
22 28 16 6 27 21 30 1 29 10 9 14 24 11 7 2 8 5 26 4 12 3 25 18 20 19 23 17 13 15
Output:
16
code:
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
InputReader in = new InputReader(System.in, " \n");
int n = in.nextInt(), res = 0;
int[] link = new int[n + 1];
boolean[] marked = new boolean[n + 1];
Arrays.fill(marked, true);
for (int i = 1; i <= n; i++)
marked[link[i] = in.nextInt()] = false;
for (int i = 1, start, end, cnt; i <= n; i++) {
if (marked[i]) continue;
start = end = i;
cnt = 1;
while (link[start] != end) {
marked[start] = true;
start = link[start];
cnt++;
}
if (cnt > res) res = cnt;
}
System.out.print(res);
}
static class InputReader {
BufferedReader read;
StringTokenizer tok;
String delimiters;
InputReader(InputStream in) {
this(in, " \n\r\t\f"); }
InputReader(InputStream in, String delimiters) {
this.read = new BufferedReader(new InputStreamReader(in));
this.tok = new StringTokenizer("", this.delimiters = delimiters);
}
String next() {
while (!tok.hasMoreTokens())
try {
tok = new StringTokenizer(read.readLine(), delimiters);
} catch (IOException e) {
}
return tok.nextToken();
}
int nextInt() {
return Integer.parseInt(next()); }
}
}
排除掉入度为 0 的顶点,图里就只剩环了,接下来慢慢跑大小就行
就是不知道我这个想法对不对,有没有大哥讲下的
问题描述
x星球的居民脾气不太好,但好在他们生气的时候唯一的异常举动是:摔手机。
各大厂商也就纷纷推出各种耐摔型手机。x星球的质监局规定了手机必须经过耐摔测试,并且评定出一个耐摔指数来,之后才允许上市流通。
x星球有很多高耸入云的高塔,刚好可以用来做耐摔测试。塔的每一层高度都是一样的,与地球上稍有不同的是,他们的第一层不是地面,而是相当于我们的2楼。
如果手机从第7层扔下去没摔坏,但第8层摔坏了,则手机耐摔指数=7。
特别地,如果手机从第1层扔下去就坏了,则耐摔指数=0。
如果到了塔的最高层第n层扔没摔坏,则耐摔指数=n
为了减少测试次数,从每个厂家抽样3部手机参加测试。
如果已知了测试塔的高度,并且采用最佳策略,在最坏的运气下最多需要测试多少次才能确定手机的耐摔指数呢?
资源约定
峰值内存消耗(含虚拟机) < 256M
CPU消耗 < 1000ms
输入格式
一个整数n(3 输出格式 输出一个整数,表示最多测试多少次。 测试样例1 测试样例2 code:
Input:
3
Output:
2
Explanation:
手机a从2楼扔下去,坏了,就把b手机从1楼扔;否则a手机继续3层扔下
Input:
7
Output:
3
Explanation:
a手机从4层扔,坏了,则下面有3层,b,c 两部手机2次足可以测出指数;
若是没坏,手机充足,上面5,6,7 三层2次也容易测出。
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
int n = nextInt(System.in);
int[][] dp = new int[3][n + 1];
for (int i = 1; i <= n; i++)
dp[0][i] = i;
for (int k = 1; k < 3; k++) {
for (int i = 1; i <= n; i++) {
dp[k][i] = dp[k][i - 1] + 1;
for (int j = 1; j < i; j++)
dp[k][i] = min(dp[k][i], max(dp[k - 1][j - 1], dp[k][i - j]) + 1);
}
}
System.out.print(dp[2][n]);
}
static int min(int a, int b) {
return a < b? a: b; }
static int max(int a, int b) {
return a > b? a: b; }
static int nextInt(InputStream in) throws IOException {
int n = 0, c = in.read();
while (c < '0' || c > '9') c = in.read();
while (c >='0' && c <='9') {
n = n * 10 + (c & 0xf);
c = in.read();
}
return n;
}
}