Java选手,吐槽一下B题
刚才测试了一下,思路没问题,但是必须使用快速读写,不然会提示超时。建议下次出题给 Java 预留3秒,求求了~
import java.util.*;
import java.io.*;
public class Main {
static boolean[] used = new boolean[2000001];
public static void main( String[] args ) throws Exception {
In in = new In( System.in );
Out out = new Out( System.out );
int n = in.in();
int x = in.in();
int now = x, pre = x;
used[now] = true;
//System.out.printf( "%d ", now );
out.out.print(now);
for( int i = 1; i < n; ++i ) {
x = in.in();
if( pre != x ) {
pre = now = x;
} else {
while( used[now] ) {
now += pre;
}
}
used[now] = true;
out.out.print(" "+now);
//System.out.printf( "%d ", now );
}
out.out.close();
}
}
class In{
private StringTokenizer in=new StringTokenizer("");
private InputStream is;
private BufferedReader bf;
public In(File file) throws IOException {
is=new FileInputStream(file);
init();
}
public In(InputStream is) throws IOException
{
this.is=is;
init();
}
private void init() throws IOException {
bf=new BufferedReader(new InputStreamReader(is));
}
boolean hasNext() throws IOException {
return in.hasMoreTokens()||bf.ready();
}
String ins() throws IOException {
while(!in.hasMoreTokens()) {
in=new StringTokenizer(bf.readLine());
}
return in.nextToken();
}
int in() throws IOException {
return Integer.parseInt(ins());
}
long inl() throws IOException {
return Long.parseLong(ins());
}
double ind() throws IOException {
return Double.parseDouble(ins());
}
}
class Out{
public PrintWriter out;
private OutputStream os;
private void init() {
out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(os)));
}
public Out(File file) throws IOException {
os=new FileOutputStream(file);
init();
}
public Out(OutputStream os) throws IOException
{
this.os=os;
init();
}
}
查看20道真题和解析
