题目很简单,需要注意的是在大dataset规模下的怎样让程序运行时间不超时
package Round_1_A;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
public class Bullseye {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = null;
PrintWriter out = null;
try {
in = new Scanner(new File("A-large-practice.in"));
out = new PrintWriter(new File("a_large.out"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
int cases = in.nextInt();
for (int i=1; i<=cases; i++) {
long r = in.nextLong();
long t = in.nextLong();
long s = 2*r+1;
long n = 0;
while (t >= s) {
if (s<100000000000l) {
long value = 50000 * (2*s + 4*99999);
if (t >= value) {
t -= value;
s += 400000;
n += 100000;
}
}
if (t >= s) {
t -= s;
s += 4;
n++;
}
}
out.println("Case #"+i+": " + n);
out.flush();
}
}
}
通过这部分优化代码每一次增加100000个数,减少循环的执行次数
if (s<100000000000l) {
long value = 50000 * (2*s + 4*99999);
if (t >= value) {
t -= value;
s += 400000;
n += 100000;
}
}