(SPOJ) 11003 - Pulo do sapo - Solução
import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
Main processando = new Main();
processando.processa();
System.exit(0);
}
static int leitor(BufferedReader br) throws NumberFormatException, IOException {
int n;
int resp = 0;
while (true) {
n = br.read();
if (n >= '0' && n <= '9') {
break;
}
}
while (true) {
resp = resp*10 + n-'0';
n = br.read();
if (n < '0' || n > '9') {
break;
}
}
return resp;
}
void processa() throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int qteEspacos = leitor(br);
int numSapos = leitor(br);
int[] brejo = new int[qteEspacos];
for (int i = 0; i < numSapos; i++) {
int posicao = leitor(br);
int tamPulo = leitor(br);
for (int j = posicao-1; j < qteEspacos; j += tamPulo) {
brejo[j] = 1;
}
for (int j = posicao-1; j >= 0; j -= tamPulo) {
brejo[j] = 1;
}
}
for (int i = 0; i < qteEspacos; i++) {
bw.write(brejo[i]+"\n");
}
bw.flush();
bw.close();
return;
}
}
import java.util.*;
class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
Main processando = new Main();
processando.processa();
System.exit(0);
}
static int leitor(BufferedReader br) throws NumberFormatException, IOException {
int n;
int resp = 0;
while (true) {
n = br.read();
if (n >= '0' && n <= '9') {
break;
}
}
while (true) {
resp = resp*10 + n-'0';
n = br.read();
if (n < '0' || n > '9') {
break;
}
}
return resp;
}
void processa() throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int qteEspacos = leitor(br);
int numSapos = leitor(br);
int[] brejo = new int[qteEspacos];
for (int i = 0; i < numSapos; i++) {
int posicao = leitor(br);
int tamPulo = leitor(br);
for (int j = posicao-1; j < qteEspacos; j += tamPulo) {
brejo[j] = 1;
}
for (int j = posicao-1; j >= 0; j -= tamPulo) {
brejo[j] = 1;
}
}
for (int i = 0; i < qteEspacos; i++) {
bw.write(brejo[i]+"\n");
}
bw.flush();
bw.close();
return;
}
}
Comments
Post a Comment