Search is not available for this dataset
name
stringlengths 2
112
| description
stringlengths 29
13k
| source
int64 1
7
| difficulty
int64 0
25
| solution
stringlengths 7
983k
| language
stringclasses 4
values |
---|---|---|---|---|---|
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.*;
public class quizLeague {
public static void main(String[] args) throws Exception {
File file = new File("input.txt");
Scanner sc = new Scanner(file);
PrintWriter pw = new PrintWriter(new FileWriter("output.txt"));
int n = sc.nextInt();
int k = sc.nextInt();
int[] a = new int[n];
for (int i = 0; i < a.length; i++)
{
a[i] = sc.nextInt();
}
for(int i=k-1;true;i++)
{
if(i==n)
i=0;
if(a[i]==1)
{
pw.println(i+1);
break;
}
}
sc.close();
pw.close();
}
} | JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class CF1 {
public static void main(String[] args) {
Scanner scanner = null;
try {
scanner = new Scanner(new FileInputStream(new File("input.txt")));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int n = scanner.nextInt();
int k = scanner.nextInt();
List<Integer> dones = new ArrayList<Integer>();
for (int i = 0; i < n; i++) {
dones.add(scanner.nextInt());
}
int ans = k;
while (dones.get(ans-1) == 0) {
ans++;
if (ans > dones.size())
ans = 1;
}
try {
BufferedWriter out = new BufferedWriter(
new FileWriter("output.txt"));
out.write(String.valueOf(ans));
out.close();
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 |
import java.util.*;
import java.io.*;
public class B
{
public static void main(String[] args) throws Exception
{
new B(new Scanner(new File("input.txt")));
}
public B(Scanner in) throws Exception
{
PrintWriter out = new PrintWriter("output.txt");
int N = in.nextInt();
int K = in.nextInt()-1;
int[] vs = new int[N];
for (int i=0; i<N; i++)
vs[i] = in.nextInt();
int pos = K;
while (vs[pos] != 1)
pos = (pos+1)%N;
out.printf("%d%n", pos+1);
out.close();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import static java.lang.Math.*;
import java.util.*;
import java.io.*;
public class B {
public void solve() throws Exception {
int n = nextInt(), k = nextInt()-1;
int[] p = nextArr(n);
for (int i=k;; i++) {
if (i>=n) i=0;
if (p[i]==1) halt(i+1);
}
}
////////////////////////////////////////////////////////////////////////////
boolean showDebug = true;
static boolean useFiles = !false;
static String inFile = "input.txt";
static String outFile = "output.txt";
double EPS = 1e-7;
int INF = Integer.MAX_VALUE;
long INFL = Long.MAX_VALUE;
double INFD = Double.MAX_VALUE;
int absPos(int num) {
return num<0 ? 0:num;
}
long absPos(long num) {
return num<0 ? 0:num;
}
double absPos(double num) {
return num<0 ? 0:num;
}
int min(int... nums) {
int r = INF;
for (int i: nums)
if (i<r) r=i;
return r;
}
int max(int... nums) {
int r = -INF;
for (int i: nums)
if (i>r) r=i;
return r;
}
long minL(long... nums) {
long r = INFL;
for (long i: nums)
if (i<r) r=i;
return r;
}
long maxL(long... nums) {
long r = -INFL;
for (long i: nums)
if (i>r) r=i;
return r;
}
double minD(double... nums) {
double r = INFD;
for (double i: nums)
if (i<r) r=i;
return r;
}
double maxD(double... nums) {
double r = -INFD;
for (double i: nums)
if (i>r) r=i;
return r;
}
long sumArr(int[] arr) {
long res = 0;
for (int i: arr)
res+=i;
return res;
}
long sumArr(long[] arr) {
long res = 0;
for (long i: arr)
res+=i;
return res;
}
double sumArr(double[] arr) {
double res = 0;
for (double i: arr)
res+=i;
return res;
}
long partsFitCnt(long partSize, long wholeSize) {
return (partSize+wholeSize-1)/partSize;
}
boolean odd(long num) {
return (num&1)==1;
}
boolean hasBit(int num, int pos) {
return (num&(1<<pos))>0;
}
long binpow(long a, int n) {
long r = 1;
while (n>0) {
if ((n&1)!=0) r*=a;
a*=a;
n>>=1;
}
return r;
}
boolean isLetter(char c) {
return (c>='a' && c<='z') || (c>='A' && c<='Z');
}
boolean isLowercase(char c) {
return (c>='a' && c<='z');
}
boolean isUppercase(char c) {
return (c>='A' && c<='Z');
}
boolean isDigit(char c) {
return (c>='0' && c<='9');
}
String stringn(String s, int n) {
if (n<1) return "";
StringBuilder sb = new StringBuilder(s.length()*n);
for (int i=0; i<n; ++i) sb.append(s);
return sb.toString();
}
String str(Object o) {
return o.toString();
}
long timer = System.currentTimeMillis();
void startTimer() {
timer = System.currentTimeMillis();
}
void stopTimer() {
System.err.println("time: "+(System.currentTimeMillis()-timer)/1000.0);
}
static class InputReader {
private byte[] buf;
private int bufPos = 0, bufLim = -1;
private InputStream stream;
public InputReader(InputStream stream, int size) {
buf = new byte[size];
this.stream = stream;
}
private void fillBuf() throws IOException {
bufLim = stream.read(buf);
bufPos = 0;
}
char read() throws IOException {
if (bufPos>=bufLim) fillBuf();
return (char)buf[bufPos++];
}
boolean hasInput() throws IOException {
if (bufPos>=bufLim) fillBuf();
return bufPos<bufLim;
}
}
static InputReader inputReader;
static BufferedWriter outputWriter;
char nextChar() throws IOException {
return inputReader.read();
}
char nextNonWhitespaceChar() throws IOException {
char c = inputReader.read();
while (c<=' ') c=inputReader.read();
return c;
}
String nextWord() throws IOException {
StringBuilder sb = new StringBuilder();
char c = inputReader.read();
while (c<=' ') c=inputReader.read();
while (c>' ') {
sb.append(c);
c = inputReader.read();
}
return new String(sb);
}
String nextLine() throws IOException {
StringBuilder sb = new StringBuilder();
char c = inputReader.read();
while (c<=' ') c=inputReader.read();
while (c!='\n' && c!='\r') {
sb.append(c);
c = inputReader.read();
}
return new String(sb);
}
int nextInt() throws IOException {
int r = 0;
char c = nextNonWhitespaceChar();
boolean neg = false;
if (c=='-') neg=true;
else r=c-48;
c = nextChar();
while (c>='0' && c<='9') {
r*=10;
r+=c-48;
c=nextChar();
}
return neg ? -r:r;
}
long nextLong() throws IOException {
long r = 0;
char c = nextNonWhitespaceChar();
boolean neg = false;
if (c=='-') neg=true;
else r = c-48;
c = nextChar();
while (c>='0' && c<='9') {
r*=10L;
r+=c-48L;
c=nextChar();
}
return neg ? -r:r;
}
double nextDouble() throws NumberFormatException, IOException {
return Double.parseDouble(nextWord());
}
int[] nextArr(int size) throws NumberFormatException, IOException {
int[] arr = new int[size];
for (int i=0; i<size; ++i)
arr[i] = nextInt();
return arr;
}
long[] nextArrL(int size) throws NumberFormatException, IOException {
long[] arr = new long[size];
for (int i=0; i<size; ++i)
arr[i] = nextLong();
return arr;
}
double[] nextArrD(int size) throws NumberFormatException, IOException {
double[] arr = new double[size];
for (int i=0; i<size; ++i)
arr[i] = nextDouble();
return arr;
}
String[] nextArrS(int size) throws NumberFormatException, IOException {
String[] arr = new String[size];
for (int i=0; i<size; ++i)
arr[i] = nextWord();
return arr;
}
char[] nextArrCh(int size) throws IOException {
char[] arr = new char[size];
for (int i=0; i<size; ++i)
arr[i] = nextNonWhitespaceChar();
return arr;
}
char[][] nextArrCh(int rows, int columns) throws IOException {
char[][] arr = new char[rows][columns];
for (int i=0; i<rows; ++i)
for (int j=0; j<columns; ++j)
arr[i][j] = nextNonWhitespaceChar();
return arr;
}
char[][] nextArrChBorders(int rows, int columns, char border) throws IOException {
char[][] arr = new char[rows+2][columns+2];
for (int i=1; i<=rows; ++i)
for (int j=1; j<=columns; ++j)
arr[i][j] = nextNonWhitespaceChar();
for (int i=0; i<columns+2; ++i) {
arr[0][i] = border;
arr[rows+1][i] = border;
}
for (int i=0; i<rows+2; ++i) {
arr[i][0] = border;
arr[i][columns+1] = border;
}
return arr;
}
void printf(String format, Object... args) throws IOException {
outputWriter.write(String.format(format, args));
}
void print(Object o) throws IOException {
outputWriter.write(o.toString());
}
void println(Object o) throws IOException {
outputWriter.write(o.toString());
outputWriter.newLine();
}
void print(Object... o) throws IOException {
for (int i=0; i<o.length; ++i) {
if (i!=0) outputWriter.write(' ');
outputWriter.write(o[i].toString());
}
}
void println(Object... o) throws IOException {
print(o);
outputWriter.newLine();
}
void printn(Object o, int n) throws IOException {
String s = o.toString();
for (int i=0; i<n; ++i) {
outputWriter.write(s);
if (i!=n-1) outputWriter.write(' ');
}
}
void printnln(Object o, int n) throws IOException {
printn(o, n);
outputWriter.newLine();
}
void printArr(int[] arr) throws IOException {
for (int i=0; i<arr.length; ++i) {
if (i!=0) outputWriter.write(' ');
outputWriter.write(Integer.toString(arr[i]));
}
}
void printArr(long[] arr) throws IOException {
for (int i=0; i<arr.length; ++i) {
if (i!=0) outputWriter.write(' ');
outputWriter.write(Long.toString(arr[i]));
}
}
void printArr(double[] arr) throws IOException {
for (int i=0; i<arr.length; ++i) {
if (i!=0) outputWriter.write(' ');
outputWriter.write(Double.toString(arr[i]));
}
}
void printArr(String[] arr) throws IOException {
for (int i=0; i<arr.length; ++i) {
if (i!=0) outputWriter.write(' ');
outputWriter.write(arr[i]);
}
}
void printArr(char[] arr) throws IOException {
for (char c: arr) outputWriter.write(c);
}
void printlnArr(int[] arr) throws IOException {
printArr(arr);
outputWriter.newLine();
}
void printlnArr(long[] arr) throws IOException {
printArr(arr);
outputWriter.newLine();
}
void printlnArr(double[] arr) throws IOException {
printArr(arr);
outputWriter.newLine();
}
void printlnArr(String[] arr) throws IOException {
printArr(arr);
outputWriter.newLine();
}
void printlnArr(char[] arr) throws IOException {
printArr(arr);
outputWriter.newLine();
}
void halt(Object... o) throws IOException {
if (o.length!=0) println(o);
outputWriter.flush(); outputWriter.close();
System.exit(0);
}
void debug(Object... o) {
if (showDebug) System.err.println(Arrays.deepToString(o));
}
public static void main(String[] args) throws Exception {
Locale.setDefault(Locale.US);
if (!useFiles) {
inputReader = new InputReader(System.in, 1<<16);
outputWriter = new BufferedWriter(new OutputStreamWriter(System.out), 1<<16);
} else {
inputReader = new InputReader(new FileInputStream(new File(inFile)), 1<<16);
outputWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(outFile))), 1<<16);
}
new B().solve();
outputWriter.flush(); outputWriter.close();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;
import java.io.IOException;import java.io.InputStream;import java.io.PrintStream;
import java.io.PrintWriter;import java.security.AccessControlException;import java.util.Arrays;
public class _p000120B {static public void main(final String[] args) throws IOException
{p000120B._main(args);}
static private class p000120B extends Solver{public p000120B(){singleTest=true;nameIn
="input.txt";nameOut="output.txt";}@Override public void solve()throws IOException
{int n=sc.nextInt();int k=sc.nextInt();sc.nextLine();int[]a=Arrays.stream(sc.nextLine().trim().split("\\s+")).mapToInt(Integer::parseInt).toArray();
k--;while(a[k%n]==0){k++;}pw.println(k%n+1);}static public void _main(String[]args)
throws IOException{new p000120B().run();}}static private class MyScanner{private
StringBuilder cache=new StringBuilder();int cache_pos=0;private int first_linebreak
=-1;private int second_linebreak=-1;private StringBuilder sb=new StringBuilder();
private InputStream is=null;public MyScanner(final InputStream is){this.is=is;}private
String charToString(final int c){return String.format("'%s'",c=='\n'?"\\n":(c=='\r'
?"\\r":String.valueOf((char)c)));}public int get(){int res=-1;if(cache_pos<cache.length())
{res=cache.charAt(cache_pos);cache_pos++;if(cache_pos==cache.length()){cache.delete(0,
cache_pos);cache_pos=0;}}else{try{res=is.read();}catch(IOException ex){throw new
RuntimeException(ex);}}return res;}private void unget(final int c){if(cache_pos==
0){cache.insert(0,(char)c);}else{cache_pos--;}}public String nextLine(){sb.delete(0,
sb.length());int c;boolean done=false;boolean end=false;while((c=get())!=-1){if(check_linebreak(c))
{done=true;if(c==first_linebreak){if(!end){end=true;}else{cache.append((char)c);
break;}}else if(second_linebreak!=-1 && c==second_linebreak){break;}}if(end && c
!=first_linebreak && c!=second_linebreak){cache.append((char)c);break;}if(!done)
{sb.append((char)c);}}return sb.toString();}private boolean check_linebreak(int
c){if(c=='\n'|| c=='\r'){if(first_linebreak==-1){first_linebreak=c;}else if(c!=first_linebreak
&& second_linebreak==-1){second_linebreak=c;}return true;}return false;}public int
nextInt(){return Integer.parseInt(next());}public long nextLong(){return Long.parseLong(next());
}public boolean hasNext(){boolean res=false;int c;while((c=get())!=-1){if(!check_linebreak(c)
&& c!=' '&& c!='\t'){res=true;unget(c);break;}}return res;}public String next(){
sb.delete(0,sb.length());boolean started=false;int c;while((c=get())!=-1){if(check_linebreak(c)
|| c==' '|| c=='\t'){if(started){unget(c);break;}}else{started=true;sb.append((char)c);
}}return sb.toString();}public int nextChar(){return get();}public boolean eof()
{int c=get();boolean res=false;if(c!=-1){unget(c);}else{res=true;}return res;}public
double nextDouble(){return Double.parseDouble(next());}}static private abstract class
Solver{protected String nameIn=null;protected String nameOut=null;protected boolean
singleTest=false;protected boolean preprocessDebug=false;protected boolean doNotPreprocess
=false;protected PrintStream debugPrintStream=null;protected MyScanner sc=null;protected
PrintWriter pw=null;private int current_test=0;private int count_tests=0;protected
int currentTest(){return current_test;}protected int countTests(){return count_tests;
}private void process()throws IOException{if(!singleTest){count_tests=sc.nextInt();
sc.nextLine();for(current_test=1;current_test<=count_tests;current_test++){solve();
pw.flush();}}else{count_tests=1;current_test=1;solve();pw.flush();}}abstract protected
void solve()throws IOException;protected void run()throws IOException{boolean done
=false;try{if(nameIn!=null && new File(nameIn).exists()){try(FileInputStream fis
=new FileInputStream(nameIn);PrintWriter pw0=select_output();){done=true;sc=new
MyScanner(fis);pw=pw0;process();}}}catch(IOException ex){}catch(AccessControlException
ex){}if(!done){try(PrintWriter pw0=select_output();){sc=new MyScanner(System.in);
pw=pw0;process();}}}private PrintWriter select_output()throws FileNotFoundException
{if(nameOut!=null){return new PrintWriter(nameOut);}return new PrintWriter(System.out);
}}}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.*;
public class QuizLeague {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader r=new BufferedReader(new FileReader("input.txt"));
BufferedWriter wr=new BufferedWriter(new FileWriter("output.txt"));
String s=r.readLine();
String[] sp=s.split("[ ]+");
int k=new Integer(sp[1])-1;
s=r.readLine();
sp=s.split("[ ]+");
int[] questions=new int[sp.length];
for (int i = 0; i < questions.length; i++) {
questions[i]=new Integer(sp[i]);
}
while(questions[k]==0){
k++;
k%=questions.length;
}
wr.write(""+(k+1));
wr.newLine();
wr.flush();
wr.close();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Locale;
import java.util.StringTokenizer;
public class Main implements Runnable {
void solve() throws IOException {
int n = nextInt();
int k = nextInt() - 1;
boolean[] a = new boolean[n];
for (int i = 0; i < a.length; i++) {
a[i] = nextInt() == 0;
}
while (a[k]) {
k = (k + 1) % n;
}
out.println(k + 1);
}
private BufferedReader in;
private PrintWriter out;
private StringTokenizer st;
private void eat(String s) {
st = new StringTokenizer(s);
}
String next() throws IOException {
while (!st.hasMoreTokens()) {
String line = in.readLine();
if (line == null) {
return null;
}
eat(line);
}
return st.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public static void main(String[] args) throws IOException {
new Thread(null, new Main(), "Main", 1 << 23).start();
}
public void run() {
try {
Locale.setDefault(Locale.US);
// in = new BufferedReader(new InputStreamReader(System.in));
// out = new PrintWriter(System.out);
in = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter("output.txt");
eat("");
solve();
in.close();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} | JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;
public class Main implements Runnable {
StreamTokenizer in;
BufferedReader reader;
PrintWriter out;
StringTokenizer tok;
Scanner sc;
boolean timus = true;//System.getProperty("ONLINE_JUDGE")!=null;
boolean codeforces = false;
final double eps = 1e-9;
public static void main(String[] args) throws Exception {
new Thread(new Main()).start();
}
@Override
public void run() {
try {
if (codeforces) {
sc = new Scanner(System.in);
reader = new BufferedReader(new InputStreamReader(System.in));
in = new StreamTokenizer(reader);
out= new PrintWriter (new OutputStreamWriter(System.out));
tok = new StringTokenizer("");
solve();
out.flush();
} else
if (timus) {
sc = new Scanner("input.txt");
reader = new BufferedReader(new FileReader("input.txt"));
in = new StreamTokenizer(reader);
out= new PrintWriter (new FileWriter("output.txt"));
tok = new StringTokenizer("");
solve();
out.flush();
out.close();
} else
if (!timus) {
long begMem = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
long t1 = System.currentTimeMillis();
reader = new BufferedReader(new InputStreamReader(System.in));
in = new StreamTokenizer(reader);
sc = new Scanner(System.in);
out= new PrintWriter (new OutputStreamWriter(System.out));
tok = new StringTokenizer("");
solve();
long endMem = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
out.flush();
long t2 = System.currentTimeMillis();
System.out.println("Time:"+(t2-t1));
System.out.println("Memory:"+(endMem-begMem));
System.out.println("Total memory: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));
}
}
catch (Exception ex) {
System.out.println("fail");
System.exit(1);
}
}
public class Chess {
String coord;
public Chess(String s){
this.coord=s;
}
public int toInteger(char s) {
if (s=='a'||s=='A') return 1;
else if (s=='b'||s=='B') return 2;
else if (s=='c'||s=='C') return 3;
else if (s=='d'||s=='D') return 4;
else if (s=='e'||s=='E') return 5;
else if (s=='f'||s=='F') return 6;
else if (s=='g'||s=='G') return 7;
else if (s=='h'||s=='H') return 8;
else return -1;
}
public String toString(int s) {
if (s==1) return "a";
else if (s==2) return "b";
else if (s==3) return "c";
else if (s==4) return "d";
else if (s==5) return "e";
else if (s==6) return "f";
else if (s==7) return "g";
else if (s==8) return "h";
else return "0";
}
public pair getPair() {
String j="";
j+=coord.charAt(1);
pair p = new pair(toInteger(coord.charAt(0)),Integer.parseInt(j));
if (p.x!=-1)
return p; else
return new pair(0,0);
}
public String returnPair(pair p) {
return toString(p.x)+p.y;
}
}
public int nextInt() throws Exception {
in.nextToken();
return (int) in.nval;
}
public String next() throws Exception {
in.nextToken();
return in.sval;
}
public String nextLine() throws Exception {
return reader.readLine();
}
public String nextString() throws Exception {
while (!tok.hasMoreTokens())
tok = new StringTokenizer(reader.readLine());
return tok.nextToken();
}
public long nextLong() throws Exception {
return Long.parseLong(nextString());
}
public double nextDouble() throws Exception {
in.nextToken();
return in.nval;
}
public class pair {
int x;
int y;
public pair(int x, int y) {
this.x=x;
this.y=y;
}
}
public int gcd(int a, int b) {
if (a== 0||b==0) return 1;
if (a<b) {
int c=b;
b=a;
a=c;
}
while (a%b!=0) {
a =a%b;
if (a<b) {
int c=b;
b=a;
a=c;
}
}
return b;
}
public int pow(int a, int n) {
if (n==0) return 1;
int k=n, b=1, c=a;
while (k!=0) {
if (k%2==0) {
k/=2;
c*=c;
} else {
k--;
b*=c;
}
}
return b;
}
public int lcm(int a, int b) {
return a*b/gcd(a,b);
}
public class pairs implements Comparable<pairs> {
int x;
int y;
public pairs(int x, int y) {
this.x=x;
this.y=y;
}
@Override
public int compareTo(pairs obj) {
if (this.x<((pairs)obj).x) return 1;
else if (this.x==(obj).x&&this.y<(obj).y) return 1;
else if (this.x==(obj).x&&this.y==(obj).y)return 0; else
return -1;
}
}
public class Graf {
int [][] a;
int [] colors;
ArrayList <String> points = new ArrayList<String>();
LinkedList <Integer> queue = new LinkedList <Integer>();
boolean [] used;
boolean cycle;
int numberOfCycle;
public Graf(int [][]a,String s[]) {
this.a=new int [s.length][s.length];
this.a=a;
this.colors=new int [s.length];
this.used=new boolean[s.length];
for (int i=0; i<s.length;i++) {
this.colors[i]=0;
this.points.add(s[i]);
}
Arrays.fill(this.used, false);
}
public void bfs(int i) {
this.queue.add(i);
while (!this.queue.isEmpty())
{
i = this.queue.pop();
out.print(points.get(i)+" ");
this.used[i]=true;
for (int j=0; j<this.points.size();j++) {
if (this.a[i][j]==1&&!this.queue.contains(j)&&!this.used[j]) {
this.a[i][j]=0;
this.a[j][i]=0;
this.queue.addLast(j);
}
}
}
}
public void dfs(int i) {
this.colors[i]=1;
out.print(points.get(i)+" ");
for (int j=0; j<this.colors.length;j++) {
if (this.a[i][j]==1&&this.colors[j]==0) {
this.colors[j]=1;
this.a[i][j]=0;
this.a[j][i]=0;
dfs(j);
} else if (this.a[i][j]==1&&this.colors[j]==1) {
this.cycle=true;
this.numberOfCycle++;
}
}
this.colors[i]=2;
}
}
public class Time {
int h;
int min;
int sec;
public Time(String s) {
String [] st = s.split(":");
this.h =Integer.parseInt(st[0]);
this.min =Integer.parseInt(st[1]);
this.sec =(st[2]!=null)? Integer.parseInt(st[2]):0;
}
public String toString(int a) {
String h = Integer.toString(this.h);
String min = Integer.toString(this.min);
String sec = Integer.toString(this.sec);
if (h.length()==1) {
h='0'+h;
}
if (min.length()==1) {
min='0'+min;
}
if (sec.length()==1) {
sec='0'+sec;
}
if (a==5) {
return h+":"+min;
} else {
return h+":"+min+":"+sec;
}
}
public void to12HoursFormat () {
h%=12;
}
public void add (int h,int min,int s) {
this.sec+=s;
if (this.sec>=60) {
this.min++;
this.sec%=60;
}
this.min+=min;
if (this.min>=60) {
this.h++;
this.min%=60;
}
this.h+=h;
if (this.h>=24) {
this.h%=24;
}
}
}
public int[] findPrimes(int x) {
boolean[] erat = new boolean[x-1];
List<Integer> t = new ArrayList<Integer>();
int l=0, j=0;
for (int i=2;i<x; i++) {
if (erat[i-2]) continue;
t.add(i);
l++;
j=i*2;
while (j<x) {
erat[j-2]=true;
j+=i;
}
}
int[] primes = new int[l];
Iterator<Integer> iterator = t.iterator();
for (int i = 0; iterator.hasNext(); i++) {
primes[i]=iterator.next().intValue();
}
return primes;
}
public double dist(pair a,pair b) {
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int max_val=Integer.MIN_VALUE;
public void dfs (int current, int prev, int max,int a[][]) {
int n = a[0].length;
for (int i=0; i<n;i++) {
if (a[current][i]==1&&prev!=i) {
dfs(i,current,max+1,a);
}
}
max_val = max(max_val,max);
}
public void solve() throws Exception {
int n = nextInt();
int k = nextInt()-1;
int a[] = new int [n];
for (int i=0; i<n;i++) {
a[i] = nextInt();
}
while (a[k]!=1) {
k++;
if (k==n) {
k=0;
}
}
out.println(k+1);
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | #include <bits/stdc++.h>
using namespace std;
const bool online_judge = true;
const long long inf = 1LL << 60;
long long toInt(string s) {
long long res;
stringstream ss;
ss << s;
ss >> res;
return res;
}
string toString(long long n) {
stringstream ss;
ss << n;
return ss.str();
}
void run() {
long long n, k;
cin >> n >> k;
vector<long long> v;
for (long long i = 0; i < n; i++) {
long long tmp;
cin >> tmp;
v.push_back(tmp);
}
for (long long i = k - 1;; i = (i + 1) % n) {
if (v[i] == 1) {
cout << (i + 1) << endl;
return;
}
}
}
int main(int argc, char *argv[]) {
if (online_judge) {
ifstream ifile("input.txt");
if (ifile) freopen("input.txt", "rt", stdin);
if (ifile) freopen("output.txt", "wt", stdout);
}
run();
return 0;
}
| CPP |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.Scanner;
public class E {
public static void main(String[] args) throws IOException {
in = new Scanner(new File("input.txt"));
PrintWriter out = new PrintWriter("output.txt");
int n = in.nextInt(), k = in.nextInt();
boolean[] b = new boolean [n];
for (int i = 0; i < n; ++i) {
b[i] = (1 == in.nextInt());
}
--k;
while (!b[k]) {
k = (k + 1) % n;
}
out.println(k + 1);
out.close();
}
static Scanner in;
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 |
/*
********QUESTION DESCRIPTION*************
* @author (codeKNIGHT)
*/
import java.util.*;
import java.math.*;
import java.io.*;
public class saratov_b
{
public static void main(String args[])throws IOException
{
//Scanner in=new Scanner(System.in);
PrintWriter out=new PrintWriter("output.txt");
//PrintWriter out=new PrintWriter(System.out);
FileReader f=new FileReader("input.txt");
Scanner in=new Scanner(f);
//int t=in.nextInt();
int i;
String s;
int n,k;
n=in.nextInt();
k=in.nextInt();
int a[]=new int [n+1];
for(i=1;i<=n;i++)
{
a[i]=in.nextInt();
}
while(a[k]!=1)
{
k++;
if(k==n+1)
k=1;
}
out.println(k);
out.flush();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class B {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(new File("input.txt"));
PrintWriter pw = new PrintWriter(new File("output.txt"));
int n = sc.nextInt();
int k = sc.nextInt();
int[]a = new int[n+1];
for (int i = 1; i <= n; i++) {
a[i] = sc.nextInt();
}
if (a[k]==1)
pw.println(k);
else {
while (true) {
k++;
if (k==n+1)
k = 1;
if (a[k]==1) {
pw.println(k);
break;
}
}
}
pw.close();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.*;
import java.util.*;
public class test {
public static void main(String[] args) throws Exception{
Scanner sc = new Scanner(new File("input.txt"));
PrintWriter out = new PrintWriter(new File("output.txt"));
int quest = sc.nextInt();
int start = sc.nextInt()-1;
boolean[] questions = new boolean[quest];
for(int a=0;a<quest;a++){
if(sc.next().compareTo("1")==0)questions[a]=true;
}
while(questions[start]!=true){
start++;
start=start%quest;
}
out.println(start+1);
out.close();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
Scanner in = new Scanner(new FileReader("input.txt"));
BufferedWriter out = new BufferedWriter(new FileWriter("output.txt"));
int n = in.nextInt();
int k = in.nextInt();
boolean[] a = new boolean[n];
k--;
for (int i = 0; i < n; i++)
a[i] = (in.nextInt() == 0 ? true : false);
int i;
for (i = k; i <= n; i++) {
i %= n;
if (!a[i])
break;
}
String s = ""+(i+1);
out.write(s);
out.close();
}
} | JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.io.FileInputStream;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author "Johan Sannemo"
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream;
try {
inputStream = new FileInputStream("input.txt");
} catch (IOException e) {
throw new RuntimeException(e);
}
OutputStream outputStream;
try {
outputStream = new FileOutputStream("output.txt");
} catch (IOException e) {
throw new RuntimeException(e);
}
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
}
class TaskB {
public void solve(int testNumber, Scanner in, PrintWriter out) {
int n = in.nextInt(), k = in.nextInt();
boolean [] used = new boolean[n];
for(int i = 0; i<n; i++) used[i] = in.nextInt() == 1;
int at = k-1;
while(!used[at]) at = (at+1)%n;
out.println(at+1);
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 |
import java.io.*;
import java.math.BigInteger;
import static java.math.BigInteger.*;
import java.util.*;
public class ForFile
{
void solve()throws Exception
{
int n=nextInt();
int at=nextInt()-1;
int[]a=new int[n];
for(int i=0;i<n;i++)
a[i]=nextInt();
while(a[at]==0)
{
at++;
at%=n;
}
writer.println(at+1);
}
int doIt()throws Exception
{
int n=nextInt();
int[][]g=new int[n][n];
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(i!=j)
g[i][j]=Integer.MAX_VALUE/10;
for(int i=0;i<n-1;i++)
{
int a=nextInt()-1;
int b=nextInt()-1;
g[a][b]=g[b][a]=1;
}
for(int k=0;k<n;k++)
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
g[i][j]=Math.min(g[i][j],g[i][k]+g[k][j]);
int res=0;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
res=Math.max(res,g[i][j]);
return res;
}
////////////
BufferedReader reader;
PrintWriter writer;
StringTokenizer stk;
void run()throws Exception
{
reader=new BufferedReader(new FileReader("input.txt"));
stk=null;
writer=new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
solve();
reader.close();
writer.close();
}
int nextInt()throws Exception
{
return Integer.parseInt(nextToken());
}
long nextLong()throws Exception
{
return Long.parseLong(nextToken());
}
double nextDouble()throws Exception
{
return Double.parseDouble(nextToken());
}
String nextString()throws Exception
{
return nextToken();
}
String nextLine()throws Exception
{
return reader.readLine();
}
String nextToken()throws Exception
{
if(stk==null || !stk.hasMoreTokens())
{
stk=new StringTokenizer(nextLine());
return nextToken();
}
return stk.nextToken();
}
public static void main(String[]args) throws Exception
{
new ForFile().run();
}
} | JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.util.*;
import java.io.*;
public class CodeForces {
public static void main(String[] args) throws FileNotFoundException {
Scanner scanner = new Scanner(new File("input.txt"));
PrintWriter printWriter = new PrintWriter(new File("output.txt"));
ArrayList<Integer> al = new ArrayList<Integer>();
int n = scanner.nextInt();
int k = scanner.nextInt();
for (int i = 0; i < n; i++) {
int a = scanner.nextInt();
al.add(a);
}
boolean b = false;
int h = k;
while (!b) {
if ((n == 1) && (k == 1)) {
printWriter.print(h);
break;
}
if (al.get(k - 1) == 1) {
printWriter.print(h);
break;
}
if (h == n) {
h = 0;
}
if (al.get(h) == 1) {
printWriter.print(h + 1);
b = true;
} else {
h++;
}
}
printWriter.close();
}
} | JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args)throws IOException {
Scanner in = new Scanner((new FileReader("input.txt")));
FileWriter out = new FileWriter("output.txt");
int n = in.nextInt(); int k = in.nextInt()-1;
int[]a = new int[n];
for(int i=0;i<n;i++)
a[i] = in.nextInt();
boolean f = false;
int i;
for(i=k;i<n;i++)
{
if(a[i] ==1){f = true;break;}
}
if(f)
out.write((i+1)+"\n");
else
{
for(i=0;i<k;i++)
{
if(a[i] ==1){f = true;break;}
}
out.write((i+1)+"\n");
}
out.close();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class QuizLeague {
public static void main(String[] args) throws IOException {
BufferedReader f = new BufferedReader(new FileReader("input.txt"));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
StringTokenizer st = new StringTokenizer(f.readLine());
int n = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
boolean[] a = new boolean[n];
st = new StringTokenizer(f.readLine());
for (int i = 0; i < n; i++)
a[i] = st.nextToken().equals("1");
while (!a[k-1]) {
k++;
if (k == (n+1))
k = 1;
}
out.println(k);
out.close();
f.close();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.util.*;
import java.io.*;
public class Main {
// File file = new File("input.txt");
// Scanner in = new Scanner(file);
// PrintWriter out = new PrintWriter(new FileWriter("output.txt"));
public static void main(String[] args) throws Exception {
File file = new File("input.txt");
Scanner in = new Scanner(file);
PrintWriter out = new PrintWriter(new FileWriter("output.txt"));
int n = in.nextInt();
int k = in.nextInt();
int[] ques = new int[n];
for(int i = 0; i<n; i++)
ques[i] = in.nextInt();
if(ques[k-1]==1){
out.print(k);
}else{
int currentIndex = k-1;
while(true){
if(currentIndex == n){
currentIndex = 0;
}
if(ques[currentIndex]==1){
out.print(currentIndex+1);
break;
}else{
currentIndex++;
}
}
}
out.close();
}
} | JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Locale;
import java.util.StringTokenizer;
public class B {
BufferedReader in;
StringTokenizer st;
PrintWriter out;
String _token() throws IOException {
while (in.ready() && !st.hasMoreTokens()) {
st = new StringTokenizer(in.readLine());
}
return st.nextToken();
}
int _int() throws NumberFormatException, IOException {
return Integer.parseInt(_token());
}
long _long() throws NumberFormatException, IOException {
return Long.parseLong(_token());
}
double _double() throws NumberFormatException, IOException {
return Double.parseDouble(_token());
}
void deb(String s) {
System.err.println(s);
}
void deb(Object a) {
System.err.println(a.toString());
}
void init(boolean FILE, String name) throws NumberFormatException,
IOException {
Locale.setDefault(Locale.US);
if (FILE) {
in = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter("output.txt");
} else {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
}
st = new StringTokenizer("");
}
void mainProgram() throws NumberFormatException, IOException {
init(true, "");
int n =_int();
int k = _int()-1;
int was[] =new int[n+n];
for(int i=0;i<n;i++) {
was[i] = was[i+n] = _int();
}
while(was[k] == 0)
k++;
out.println(k%n+1);
out.close();
}
public static void main(String[] args) throws NumberFormatException,
IOException {
long T = System.currentTimeMillis();
new B().mainProgram();
System.err.println("Time of working: "
+ (System.currentTimeMillis() - T) + " ms");
}
BigInteger add(BigInteger A, BigInteger B) {
return A.add(B);
}
BigInteger mult(BigInteger A, BigInteger B) {
return A.multiply(B);
}
BigInteger sub(BigInteger A, BigInteger B) {
return A.subtract(B);
}
BigInteger div(BigInteger A, BigInteger B) {
return A.divide(B);
}
BigInteger mi(BigInteger A) {
return (BigInteger.ZERO).subtract(A);
}
BigInteger sq(BigInteger A) {
return A.multiply(A);
}
BigInteger val(long a) {
return BigInteger.valueOf(a);
}
int cmp(BigInteger a, BigInteger b) {
return a.compareTo(b);
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;
public class B_Schools {
public static void main(String[] args) throws IOException {
FileReader f = new FileReader("input.txt");
FileWriter fr = new FileWriter("output.txt");
Scanner sa = new Scanner(f);
int n = sa.nextInt();
int k = sa.nextInt();
int [] ar2 = new int[n];
for(int i = 0 ; i < n ; i ++)
ar2[i] = sa.nextInt();
k-=1;
while(ar2[k] == 0)
{
k++;
if(k==n)
k=0;
}
fr.write((k+1)+"\n");
fr.close();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class Main implements Runnable {
private void solve() throws IOException {
int n = nextInt(), k = nextInt() - 1;
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
while (a[k] == 0) {
k++;
k %= n;
}
out.println(k + 1);
}
public void run() {
try {
in = new BufferedReader(new FileReader(new File("input.txt")));
out = new PrintWriter(new File("output.txt"));
//in = new BufferedReader(new InputStreamReader(System.in));
//out = new PrintWriter(System.out);
tokenizer = null;
solve();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
new Main().run();
}
private BufferedReader in;
private PrintWriter out;
private StringTokenizer tokenizer;
private String nextToken() throws IOException {
while (tokenizer == null || !tokenizer.hasMoreElements()) {
tokenizer = new StringTokenizer(in.readLine());
}
return tokenizer.nextToken();
}
private int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
private long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
private double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 |
import java.io.*;
import java.util.*;
public class CodeForces {
private void solve() throws IOException {
int n = nextInt(), k = nextInt();
int []map = new int[n];
for(int i = 0; i < n; i++)
map[i] = nextInt();
int x = k - 1;
while(map[x] == 0) {
x += 1;
x %= n;
}
writer.println(x + 1);
}
public static void main(String[] args) {
new CodeForces().run();
}
BufferedReader reader;
StringTokenizer tokenizer;
PrintWriter writer;
public void run() {
try {
reader = new BufferedReader(new FileReader(new File("input.txt")));
tokenizer = null;
writer = new PrintWriter(new FileOutputStream(new File("output.txt")));
solve();
reader.close();
writer.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
String nextLine() throws IOException {
return reader.readLine();
}
String nextToken() throws IOException {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Quiz_League {
public static void main(String[] args) throws IOException,
NumberFormatException {
BufferedReader rd = new BufferedReader(new FileReader("input.txt"));
PrintWriter p = new PrintWriter(new File("output.txt"));
StringTokenizer t = new StringTokenizer(rd.readLine(), " ");
int n = Integer.parseInt(t.nextToken()), k = Integer.parseInt(t
.nextToken());
boolean[] b = new boolean[n + 1];
t = new StringTokenizer(rd.readLine(), " ");
for (int i = 1; i <= n; i++) {
b[i] = t.nextToken().charAt(0) == '0' ? false : true;
}
int out = k;
while (!b[out]) {
out = (out + 1) % (n + 1);
}
p.println(out);
p.close();
rd.close();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.util.*;
import java.io.*;
public class ScOB{
static BufferedReader br;
public static void main(String args[])throws Exception{
//br=new BufferedReader(new InputStreamReader(System.in));
File f = new File("input.txt");
FileInputStream fin = new FileInputStream(f);
br = new BufferedReader(new InputStreamReader(fin));
int nm[]=toIntArray();
int n=nm[0];
int k=nm[1];
nm=toIntArray();
int res=0;
if(nm[k-1]==1){
res=k;
}
else{
int t=k;
if(t>n-1)
t=0;
while(true){
if(nm[t]==1){
res=t+1;
break;
}
else{
t++;
if(t>n-1)
t=0;
}
}
}
String r=""+res;
try{
FileWriter fstream = new FileWriter("output.txt");
BufferedWriter out = new BufferedWriter(fstream);
out.write(r);
out.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
/****************************************************************/
public static int[] toIntArray()throws Exception{
String str[]=br.readLine().split(" ");
int k[]=new int[str.length];
for(int i=0;i<str.length;i++){
k[i]=Integer.parseInt(str[i]);
}
return k;
}
public static int toInt()throws Exception{
return Integer.parseInt(br.readLine());
}
public static long[] toLongArray()throws Exception{
String str[]=br.readLine().split(" ");
long k[]=new long[str.length];
for(int i=0;i<str.length;i++){
k[i]=Long.parseLong(str[i]);
}
return k;
}
public static long toLong()throws Exception{
return Long.parseLong(br.readLine());
}
public static double[] toDoubleArray()throws Exception{
String str[]=br.readLine().split(" ");
double k[]=new double[str.length];
for(int i=0;i<str.length;i++){
k[i]=Double.parseDouble(str[i]);
}
return k;
}
public static double toDouble()throws Exception{
return Double.parseDouble(br.readLine());
}
public static String toStr()throws Exception{
return br.readLine();
}
public static String[] toStrArray()throws Exception{
String str[]=br.readLine().split(" ");
return str;
}
public static void pr(Object st){
System.out.print(st);
}
public static void prln(Object st){
System.out.println(st);
} /****************************************************************/
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
/**
*
*/
/**
* @author antonio081014
*
*/
public class B {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
FileInputStream fis = new FileInputStream("input.txt");
FileWriter fstream = new FileWriter("output.txt");
BufferedWriter out = new BufferedWriter(fstream);
DataInputStream in = new DataInputStream(fis);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine = br.readLine();
int n = Integer.parseInt(strLine.split(" ")[0]);
int k = Integer.parseInt(strLine.split(" ")[1]);
String[] nums = br.readLine().split(" ");
for (int i = 0; i < n; i++) {
int index = (i + k - 1) % n;
if (Integer.parseInt(nums[index]) != 0) {
out.write(Integer.toString(index + 1));
break;
}
}
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.*;
import java.util.zip.ZipEntry;
import javax.crypto.Cipher;
public class B {
static boolean test = true;
private void solve() throws Throwable, IOException {
int n = iread(), k = iread();
k--;
boolean[] free = new boolean[n];
for (int i = 0; i < n; i++) {
free[i] = iread() == 1;
}
while (true) {
if(free[k%n]){
out.write((k%n + 1)+"");
return;
}
k ++;
}
}
public int iread() throws Exception {
return Integer.parseInt(wread());
}
public double dread() throws Exception {
return Double.parseDouble(wread());
}
public long lread() throws Exception {
return Long.parseLong(wread());
}
public String wread() throws IOException {
StringBuilder b = new StringBuilder();
int c;
c = in.read();
while (c >= 0 && c <= ' ')
c = in.read();
if (c < 0)
return "";
while (c > ' ') {
b.append((char) c);
c = in.read();
}
return b.toString();
}
public static void main(String[] args) throws Throwable {
new B().solve();
out.close();
}
public B() throws Throwable {
if (test) {
in = new BufferedReader(new FileReader(new File(testDataFile)));
} else {
new BufferedReader(inp);
}
out = new BufferedWriter(new FileWriter("output.txt"));
}
static InputStreamReader inp = new InputStreamReader(System.in);
static BufferedReader in = new BufferedReader(inp);
static BufferedWriter out;
static String testDataFile = "input.txt";
BufferedReader reader = null;
} | JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.*;
import java.util.*;
public class B120 {
public static void main(String args[]) throws FileNotFoundException{
Scanner input = new Scanner(new File("input.txt"));
int a[] = new int[5000];
int n = input.nextInt();
int k = input.nextInt();
for(int i = 0; i < n; i++){
a[i]=input.nextInt();
a[i+n]=a[i];
}
k=k-1;
while(a[k]!=1) k++;
String out = (k%n+1)+"";
//System.out.println(out);
new PrintStream("output.txt").append(out);
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.File;
import java.io.FileReader;
import java.io.PrintWriter;
import java.util.Scanner;
/*
* A team quiz game called "What? Where? When?" is very popular in Berland.
* The game is centered on two teams competing. They are the team of six
* Experts versus the team of the Audience. A person from the audience asks
* a question and the experts are allowed a minute on brainstorming and finding
* the right answer to the question. All it takes to answer a typical question
* is general knowledge and common logic. The question sent be the audience
* are in envelops lain out in a circle on a round table. Each envelop is
* marked by the name of the asker's town. Each question is positioned in a
* separate sector. In the centre of the table is a spinning arrow. Thus, the
* table rather resembles a roulette table with no ball but with a spinning
* arrow instead. The host sets off the spinning arrow to choose a question for
* the experts: when the arrow stops spinning, the question it is pointing at
* is chosen. If the arrow points at the question that has already been asked,
* the host chooses the next unanswered question in the clockwise direction.
* Your task is to determine which will be the number of the next asked
* question if the arrow points at sector number sectorPointed.
*
* Input
* The first line contains two positive integers numSectors and sectorPointed
* (1 ≤ numSectors ≤ 1000 and 1 ≤ sectorPointed ≤ numSectors) — the numbers of
* sectors on the table and the number of the sector where the arrow is
* pointing. The second line contains numSectors numbers: ai = 0 if the
* question from sector i has already been asked and ai = 1 if the question
* from sector i hasn't been asked yet (1 ≤ i ≤ numSectors). The
* sectors are given in the clockwise order, the first sector follows after
* the numSectors-th one.
*
* Output
* Print the single number — the number of the sector containing the question
* the experts will be asked. It is guaranteed that the answer exists, that is
* that not all the questions have already been asked.
*/
/**
* @author Arief Rahman
*/
public class QuizLeague {
public static void main(String[] args) throws Exception{
PrintWriter pw;
Scanner in;
try (FileReader fr = new FileReader(new File("input.txt"))) {
pw = new PrintWriter(new File("output.txt"));
in = new Scanner(new File("input.txt"));
// Get inputs from "input.txt"
int numSectors = in.nextInt(),
sectorPointed = in.nextInt(),
answered[] = new int[numSectors + 1];
for(int i = 1; i < numSectors + 1; i++) {
answered[i] = in.nextInt();
}
// Assume that the sector pointed is the sector that
// will be asked.
int sectorToAsk = sectorPointed;
int currentSectorChecked = answered[sectorToAsk];
// Find the next sector that will be asked.
// If current sector pointed is already asked, check
// the next sector, clockwise.
while (currentSectorChecked != 1) {
if (sectorToAsk == numSectors) {
sectorToAsk = 1;
} else {
sectorToAsk++;
}
currentSectorChecked = answered[sectorToAsk];
}
// Print the number of the sector that will be asked in
// "output.txt"
pw.print(sectorToAsk);
}
pw.close();
in.close();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Codeforces {
StringTokenizer tok;
BufferedReader in;
PrintWriter out;
final boolean OJ = System.getProperty("ONLINE_JUDGE") != null;
String filename = "input";
void init() {
try {
if (OJ) {
if (filename == null) {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
} else {
in = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter("output.txt");
}
} else {
in = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter("output.txt");
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
String readString() {
try {
while (tok == null || !tok.hasMoreTokens()) {
tok = new StringTokenizer(in.readLine());
}
return tok.nextToken();
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
int readInt() {
return Integer.parseInt(readString());
}
long readLong() {
return Long.parseLong(readString());
}
public static void main(String[] args) {
new Codeforces().run();
}
void run() {
init();
long time = System.currentTimeMillis();
solve();
System.err.println(System.currentTimeMillis() - time);
out.close();
}
void solve() {
int n = readInt();
int k = readInt()- 1;
int[] a = new int[n];
for (int i=0;i<n;i++) a[i] = readInt();
while (a[k] == 0) k = (k + 1) % n;
out.println(k + 1);
}
} | JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 |
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Trung Pham
*/
public class A {
public static void main(String[] args) {
try {
Scanner in = new Scanner();
PrintWriter out = new PrintWriter(new FileOutputStream(new File("output.txt")));
int n = in.nextInt();
int k = in.nextInt() - 1;
boolean[] chose = new boolean[n];
for (int i = 0; i < n; i++) {
chose[i] = in.nextInt() == 0;
}
for (int i = 0; i < n; i++) {
if (!chose[k]) {
out.println((k + 1));
break;
} else {
k = (k + 1) % n;
}
}
out.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
static class Point implements Comparable<Point> {
int index, pos;
public Point(int index, int pos) {
this.index = index;
this.pos = pos;
}
@Override
public int compareTo(Point o) {
if (pos != o.pos) {
return pos - o.pos;
} else {
return index - o.index;
}
}
}
public static boolean nextPer(int[] data) {
int i = data.length - 1;
while (i > 0 && data[i] < data[i - 1]) {
i--;
}
if (i == 0) {
return false;
}
int j = data.length - 1;
while (data[j] < data[i - 1]) {
j--;
}
int temp = data[i - 1];
data[i - 1] = data[j];
data[j] = temp;
Arrays.sort(data, i, data.length);
return true;
}
static class FT {
int[] data;
FT(int n) {
data = new int[n];
}
void update(int index, int val) {
// System.out.println("UPDATE INDEX " + index);
while (index < data.length) {
data[index] += val;
index += index & (-index);
// System.out.println("NEXT " +index);
}
}
int get(int index) {
// System.out.println("GET INDEX " + index);
int result = 0;
while (index > 0) {
result += data[index];
index -= index & (-index);
// System.out.println("BACK " + index);
}
return result;
}
}
static int gcd(int a, int b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
static int pow(int a, int b) {
if (b == 0) {
return 1;
}
if (b == 1) {
return a;
}
int val = pow(a, b / 2);
if (b % 2 == 0) {
return val * val;
} else {
return val * val * a;
}
}
// static Point intersect(Point a, Point b, Point c) {
// double D = cross(a, b);
// if (D != 0) {
// return new Point(cross(c, b) / D, cross(a, c) / D);
// }
// return null;
// }
//
// static Point convert(Point a, double angle) {
// double x = a.x * cos(angle) - a.y * sin(angle);
// double y = a.x * sin(angle) + a.y * cos(angle);
// return new Point(x, y);
// }
// static Point minus(Point a, Point b) {
// return new Point(a.x - b.x, a.y - b.y);
// }
//
// static Point add(Point a, Point b) {
// return new Point(a.x + b.x, a.y + b.y);
// }
//
// static double cross(Point a, Point b) {
// return a.x * b.y - a.y * b.x;
//
//
// }
//
// static class Point {
//
// int x, y;
//
// Point(int x, int y) {
// this.x = x;
// this.y = y;
// }
//
// @Override
// public String toString() {
// return "Point: " + x + " " + y;
// }
// }
static class Scanner {
BufferedReader br;
StringTokenizer st;
public Scanner() throws FileNotFoundException {
//System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
br = new BufferedReader(new InputStreamReader(System.in));
br = new BufferedReader(new FileReader(new File("input.txt")));
}
public String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
throw new RuntimeException();
}
}
return st.nextToken();
}
public long nextLong() {
return Long.parseLong(next());
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String nextLine() {
st = null;
try {
return br.readLine();
} catch (Exception e) {
throw new RuntimeException();
}
}
public boolean endLine() {
try {
String next = br.readLine();
while (next != null && next.trim().isEmpty()) {
next = br.readLine();
}
if (next == null) {
return true;
}
st = new StringTokenizer(next);
return st.hasMoreTokens();
} catch (Exception e) {
throw new RuntimeException();
}
}
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.*;
import java.util.Scanner;
public class p120b {
public static void main(String[] args) throws FileNotFoundException {
PrintWriter out = new PrintWriter("output.txt");
Scanner in = new Scanner(new File("input.txt"));
int n = in.nextInt();
int k = in.nextInt();
int[] all = new int[n];
for (int i = 0; i < all.length; i++) {
all[i] = in.nextInt();
}
for (int i = k-1; i < all.length; i = (i+1)%n) {
if(all[i] == 1) {
out.println(i+1);
out.flush();
return;
}
}
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.*;
import java.util.*;
public class Main3 {
public static Scanner sc;
public static PrintStream fout;
public static void run() {
int n = sc.nextInt(), k = sc.nextInt();
k--;
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = sc.nextInt();
while (a[k] == 0)
k = (k + 1) % n;
fout.println(k+1);
}
public static void main(String[] args) {
try {
Main3.sc = new Scanner(new FileInputStream("input.txt"));
Main3.fout = new PrintStream(new FileOutputStream("output.txt"));
}
catch (FileNotFoundException e) {
Main3.sc = new Scanner(System.in);
Main3.fout = System.out;
}
Main3.run();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
public class Main {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
//BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
//PrintWriter out=new PrintWriter(System.out);
BufferedReader in=new BufferedReader(new FileReader("input.txt"));
PrintWriter out=new PrintWriter(new FileWriter("output.txt"));
String[] fLine=in.readLine().split(" ");
int n=Integer.parseInt(fLine[0]);
int k=Integer.parseInt(fLine[1])-1;
String[] q=in.readLine().split(" ");
while (q[k].compareTo("1")!=0)
{
k++;
if (k>=n) k=0;
}
out.println(k+1);
out.close();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Prob120B
{
public static void main( String[] Args ) throws IOException
{
BufferedReader br = new BufferedReader( new FileReader( "input.txt" ) );
PrintWriter pw = new PrintWriter( new File( "output.txt" ) );
StringTokenizer st = new StringTokenizer( br.readLine() );
int numSectors = Integer.parseInt( st.nextToken() );
int numChosen = Integer.parseInt( st.nextToken() ) - 1;
st = new StringTokenizer( br.readLine() );
int[] array = new int[numSectors];
for ( int x = 0; x < numSectors; x++ )
array[x] = Integer.parseInt( st.nextToken() );
while ( true )
if ( array[numChosen++ % numSectors] == 1 )
{
pw.println( ( numChosen - 1 ) % numSectors + 1 );
break;
}
pw.close();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.util.*;
import java.io.*;
public class j
{
public static void main (String a[])throws IOException
{
BufferedReader f = new BufferedReader(new FileReader("input.txt"));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
int k=0,n=0,t=0,p=0,i=0;
String s;
s=f.readLine();
StringTokenizer c=new StringTokenizer(s);
n=Integer.parseInt(c.nextToken());
k=Integer.parseInt(c.nextToken());
int d[]=new int[2*n];
s=f.readLine();
StringTokenizer e=new StringTokenizer(s);
for(i=0;i<n;i++)
{
d[i]=Integer.parseInt(e.nextToken());
d[n+i]=d[i];
}
for(i=k-1;i<2*n;i++)
{
if(d[i]==1)
{
out.print(i%n+1);
break;
}
}
out.close();
}
} | JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class B_120 {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(new File("input.txt"));
PrintWriter pw = new PrintWriter(new File("output.txt"));
int n = sc.nextInt();
int[] a = new int[2 * n + 1];
int k = sc.nextInt();
for (int i = 1; i <= n; i++) {
a[i] = sc.nextInt();
a[i + n] = a[i];
}
if (a[k] == 1) {
pw.print(k);
} else {
for (int i = k; i <= 2 * n; i++) {
if (a[i] == 1) {
if (i > n) {
pw.print(i - n);
} else {
pw.print(i);
}
break;
}
}
}
pw.close();
}
} | JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class B {
/**
* @param args
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
Scanner sc = new Scanner(new File("input.txt"));
PrintWriter pw = new PrintWriter(new File("output.txt"));
int n = sc.nextInt();
int[] a = new int[2*n + 1];
int k = sc.nextInt();
for (int i = 1; i <= n; i++) {
a[i] = sc.nextInt();
a[i + n] = a[i];
}
if(a[k] == 1){
pw.print(k);
} else {
for (int i = k; i <= 2*n; i++) {
if(a[i] == 1) {
if(i > n) {
pw.print(i - n);
} else {
pw.print(i);
}
break;
}
}
}
pw.close();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.*;
import java.util.*;
public class MegaSolution {
StreamTokenizer in;
BufferedReader inb;
StringTokenizer ins;
PrintWriter out;
public static void main(String[] args) throws Exception {
new MegaSolution().run();
}
public void run() throws Exception {
inb = new BufferedReader(new FileReader("input.txt"));
in = new StreamTokenizer(inb);
//inb = new BufferedReader(new InputStreamReader(System.in));
ins = new StringTokenizer("");
//out = new PrintWriter(new OutputStreamWriter(System.out));
out = new PrintWriter(new FileWriter("output.txt"));
solve();
out.flush();
out.close();
}
public int nextInt() throws Exception {
in.nextToken();
return (int) in.nval;
}
public String nextLine() throws Exception {
return inb.readLine();
}
public String nextStr() throws Exception {
while (!ins.hasMoreTokens())
ins = new StringTokenizer(nextLine());
return ins.nextToken();
}
public int gcd(int a,int b) throws Exception {
return b = b==0 ? a : gcd(b,a%b);
}
public void solve() throws Exception {
int n = nextInt();
int k = nextInt();
int [] mas = new int [n];
for (int i=0;i<n;i++)
mas[i] = nextInt();
int i = k-1;
boolean f=true;
while (f) {
if ((i==n-1)&&(mas[i]!=1))
i=0;
else if ((i==n-1)&&(mas[i]==1)||mas[i]==1)
//if (mas[i]==1)
f = false;
else i++;
}
out.print(i+1);
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.*;
import java.util.*;
public class QuizLeague {
public static void main( String[] args ) throws Exception {
BufferedReader br = new BufferedReader( new InputStreamReader( new FileInputStream( new File("input.txt") ) ) );
String[] parts = br.readLine().split( " " );
int n = Integer.parseInt( parts[0] );
int k = Integer.parseInt( parts[1] );
parts = br.readLine().split( " " );
boolean[] free = new boolean[n];
for ( int i = 0; i < n; ++i ) {
free[i] = parts[i].charAt(0) == '1';
}
int idx = k - 1;
while ( !free[idx] ) {
idx = (idx+1)%n;
}
BufferedWriter out = new BufferedWriter( new OutputStreamWriter( new FileOutputStream( new File("output.txt") ) ) );
out.write( "" + (idx + 1) );
out.close();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(new FileReader("input.txt"));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
int n = sc.nextInt();
int k = sc.nextInt();
int[] a = new int[2*n+1];
for (int i = 0; i < n; i++)
{
a[i+1] = sc.nextInt();
a[n+i+1] = a[i+1];
}
for (int i = k; i < k+n; i++)
{
if (a[i] == 1) {
out.print(i > n ? i-n : i);
break;
}
}
out.close();
sc.close();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.*;
import java.util.*;
public class Main {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException
{
Scanner in=new Scanner(new FileReader("input.txt"));
PrintWriter out=new PrintWriter(new FileWriter("output.txt"));
int n=in.nextInt();
int k=in.nextInt();
int result = 0;
boolean checker = false;
int[] q = new int[n];
for (int i=0; i<n; i++)
q[i]=in.nextInt();
for (int i=k-1; i<n; i++)
{
if (q[i]==1)
{
result = i+1;
checker = true;
break;
}
}
if (!checker)
for (int i=0; i<k; i++)
{
if (q[i]==1)
{
result = i+1;
break;
}
}
out.print(result);
out.close();
// TODO Auto-generated method stub
}
} | JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.*;
import java.util.*;
public class Main {
FastScanner in = new FastScanner(System.in);
PrintWriter out = new PrintWriter(System.out);
static FileReader reader;
static FileWriter writer;
public static void main(String[] args) throws IOException {
reader = new FileReader("input.txt");
writer = new FileWriter("output.txt");
BufferedReader r = new BufferedReader(reader);
BufferedWriter w = new BufferedWriter(writer);
String[]f = r.readLine().split(" ");
int all = Integer.parseInt(f[0]);
int count = Integer.parseInt(f[1]);
String[]task = r.readLine().split(" ");
int[]tab = new int[all];
for (int i = 0; i < all; i++) {
tab[i] = Integer.parseInt(task[i]);
}
boolean flag = false;
for (int i = count - 1; i < tab.length; i++) {
if (tab[i] != 0) {
w.write(Integer.toString(i + 1));
flag = true;
break;
}
}
if (!flag) {
for (int i = 0; i < count; i++) {
if (tab[i] != 0) {
w.write(Integer.toString(i + 1));
flag = true;
break;
}
}
}
r.close();
w.close();
}
}
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class FastScanner {
BufferedReader br;
StringTokenizer st;
FastScanner(InputStream in) {
br = new BufferedReader(new InputStreamReader(in));
}
String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
System.err.println(e);
return "";
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
float nextFloat() {
return Float.parseFloat(next());
}
void close() {
try {
br.close();
} catch (IOException e) {
}
}
} | JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.*;
import java.util.*;
public class Main
{
//BufferedReader in;
Scanner in;
PrintStream out;
public Main() throws FileNotFoundException
{
out = new PrintStream(new File("output.txt"));
//in = new BufferedReader(new FileReader("in.txt"));
//in = new BufferedReader(new InputStreamReader(System.in));
in = new Scanner(new FileReader("input.txt"));
//in = new Scanner(new InputStreamReader(System.in));
}
void run() throws IOException
{
int n = in.nextInt();
int p = in.nextInt()-1;
boolean[] solv = new boolean[n];
for(int i = 0; i < n; i++)
{
int t = in.nextInt();
solv[i] = (t==1)?false:true;
}
while(solv[p]){p++; p%=n;}
out.println((p+1));
}
public static void main(String[] args) throws IOException
{
(new Main()).run();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 |
import java.io.*;
import java.util.*;
public class Main {
private void solve() throws IOException {
BufferedReader input = new BufferedReader(new FileReader("input.txt"));
PrintWriter output = new PrintWriter(new PrintStream(new FileOutputStream("output.txt")));
StringTokenizer sto = new StringTokenizer(input.readLine());
int n = Integer.parseInt(sto.nextToken()), k = Integer.parseInt(sto.nextToken());
int[] arr = new int [n];
sto = new StringTokenizer(input.readLine());
for (int x = 0; x < n; x++) {
arr[x] = Integer.parseInt(sto.nextToken());
}
while (arr[k - 1] != 1) {
k++;
if (k > n) {
k = 1;
}
}
output.println(k);
output.close();
input.close();
}
public static void main(String[] args) {
try {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
new Main().solve();
out.close();
} catch (Throwable e) {
e.printStackTrace();
System.exit(239);
}
}
static BufferedReader br;
static StringTokenizer st;
static PrintWriter out;
static String nextToken() throws IOException {
while (st == null || !st.hasMoreTokens()) {
String line = br.readLine();
if (line == null) {
return null;
}
st = new StringTokenizer(line);
}
return st.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
static long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
static double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
static int[] nextIntArray(int n) throws IOException {
int[] temp = new int[n];
for (int x = 0; x < n; x++) {
temp[x] = nextInt();
}
return temp;
}
static long[] nextLongArray(int n) throws IOException {
long[] temp = new long[n];
for (int x = 0; x < n; x++) {
temp[x] = nextLong();
}
return temp;
}
static String[] nextArray(int n) throws IOException {
String[] temp = new String[n];
for (int x = 0; x < n; x++) {
temp[x] = nextToken();
}
return temp;
}
static <T> void debug(T x) {
System.out.println("debug x: " + x.toString());
}
static void debugInt(int[] x) {
for (int a = 0; a < x.length; a++) {
System.out.println("debug array no: " + a + " value: " + x[a]);
}
}
static void debugArray(String[] x) {
for (int a = 0; a < x.length; a++) {
System.out.println("debug array no: " + a + " value: " + x[a]);
}
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.*;
import java.util.StringTokenizer;
/**
* 120B
* θ(n) time
* θ(n) space
*
* @author artyom
*/
public class _120B implements Runnable {
private BufferedReader in;
private StringTokenizer tok;
private Object solve() throws IOException {
int n = nextInt(), k = nextInt();
int[] a = readIntArray(n);
for (int i = k - 1; i < n; i++) {
if (a[i] == 1) {
return i + 1;
}
}
for (int i = 0; i < k - 1; i++) {
if (a[i] == 1) {
return i + 1;
}
}
return -1;
}
//--------------------------------------------------------------
public static void main(String[] args) {
new _120B().run();
}
@Override
public void run() {
try {
in = new BufferedReader(new FileReader("input.txt"));
PrintWriter out = new PrintWriter(new FileWriter("output.txt"));
tok = null;
out.print(solve());
in.close();
out.close();
} catch (IOException e) {
System.exit(0);
}
}
private String nextToken() throws IOException {
while (tok == null || !tok.hasMoreTokens()) {
tok = new StringTokenizer(in.readLine());
}
return tok.nextToken();
}
private int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
private int[] readIntArray(int n) throws IOException {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
} | JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.*;
import java.util.*;
public class Main {
BufferedReader in;
StringTokenizer tokenizer;
PrintWriter out;
public static void main(String[] args) throws IOException {
new Main().Solution();
}
public void Solution() throws IOException {
in = new BufferedReader(new FileReader(new File("input.txt")));
out = new PrintWriter(new File("output.txt"));
tokenizer = null;
solve();
in.close();
out.close();
}
int nextInt() throws IOException, NumberFormatException {
return Integer.parseInt(nextToken());
}
String nextToken() throws IOException {
if (tokenizer == null || !tokenizer.hasMoreTokens())
tokenizer = new StringTokenizer(in.readLine());
return tokenizer.nextToken();
}
private void solve() throws IOException
{
int n = nextInt();
int k = nextInt();
boolean flag;
int S = 0;
int []A = new int[n+1];
A[0]=5;
for (int i=1;i<n+1;i++)
{
A[i] = nextInt();
}
flag=true;
for (int i=k;i<n+1;i++)
{
if (A[i]==1) {flag=false;S=i;break;}
}
int i = 1;
while (flag)
{
if (A[i]==1) {flag=false;S=i;break;}
i++;
}
out.println(S);
}
} | JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.InputStream;
import java.io.OutputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Task {
private static final boolean readFromFile = true;
public static void main(String args[]){
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FileOutputStream fileOutputStream;
FileInputStream fileInputStream;
if (readFromFile){
try{
fileInputStream = new FileInputStream(new File("input.txt"));
fileOutputStream = new FileOutputStream(new File("output.txt"));
}catch (FileNotFoundException e){
throw new RuntimeException(e);
}
}
PrintWriter out = new PrintWriter((readFromFile)?fileOutputStream:outputStream);
InputReader in = new InputReader((readFromFile)?fileInputStream:inputStream);
Solver s = new Solver(in,out);
s.solve();
out.close();
}
}
class Solver{
InputReader in;
PrintWriter out;
public void solve(){
int n =in.nextInt();
int k =in.nextInt();
int a[] = new int[n];
for (int i=0;i<n;i++)
a[i]=in.nextInt();
int y=k-1;
while (a[y]==0){
y++;
if (y==n)
y=0;
}
out.println((y+1));
}
Solver(InputReader in, PrintWriter out){
this.in=in;
this.out=out;
}
}
class InputReader{
private BufferedReader buf;
private StringTokenizer tok;
InputReader(InputStream in){
tok = null;
buf = new BufferedReader(new InputStreamReader(in));
}
InputReader(FileInputStream in){
tok = null;
buf = new BufferedReader(new InputStreamReader(in));
}
public String next(){
while (tok==null || !tok.hasMoreTokens()){
try{
tok = new StringTokenizer(buf.readLine());
}catch (IOException e){
throw new RuntimeException(e);
}
}
return tok.nextToken();
}
public int nextInt(){
return Integer.parseInt(next());
}
public long nextLong(){
return Long.parseLong(next());
}
public double nextDouble(){
return Double.parseDouble(next());
}
public float nextFloat(){
return Float.parseFloat(next());
}
public String nextLine(){
try{
return buf.readLine();
}catch (IOException e){
return null;
}
}
} | JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | /**
* Created by IntelliJ IDEA.
* User: Dzianis_Siarheyeu
* Date: 10/18/11
* Time: 11:40 AM
* To change this template use File | Settings | File Templates.
*/
import java.io.*;
import java.util.StringTokenizer;
public class TaskB {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
BufferedReader buf = new BufferedReader(new FileReader(new File("input.txt")));
PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream("output.txt")));
StringTokenizer st;
int ans = 0;
//Solve
String s = buf.readLine();
st = new StringTokenizer(s);
int n = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
int[] a = new int[2 * n + 2];
s = buf.readLine();
st = new StringTokenizer(s);
for (int i = 0; i < n; ++i) {
a[i] = Integer.parseInt(st.nextToken());
}
for (int i = 0; i < k; ++i) {
a[n + i] = a[i];
}
while (a[k - 1] == 0) {
k++;
}
ans = (k % n == 0) ? k : k % n;
System.out.println(ans);
out.format("%d", ans);
out.flush();
out.close();
buf.close();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.util.ArrayList;
import java.util.List;
import java.util.InputMismatchException;
import java.math.BigInteger;
import java.util.Iterator;
import java.io.*;
import java.util.Comparator;
import java.util.Arrays;
import java.util.Collection;
/**
* Generated by Contest helper plug-in
* Actual solution is at the bottom
*/
public class Main {
public static void main(String[] args) {
InputReader in;
PrintWriter out;
try {
in = new StreamInputReader(new FileInputStream("input.txt"));
out = new PrintWriter(new PrintStream(new FileOutputStream("output.txt")));
} catch (Exception e) {
throw new RuntimeException(e);
}
run(in, out);
}
public static void run(InputReader in, PrintWriter out) {
Solver solver = new TaskB();
solver.solve(1, in, out);
Exit.exit(in, out);
}
}
abstract class InputReader {
private boolean finished = false;
public abstract int read();
public int readInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuffer res = new StringBuffer();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
private boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public void setFinished(boolean finished) {
this.finished = finished;
}
public abstract void close();
}
class StreamInputReader extends InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar, numChars;
public StreamInputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public void close() {
try {
stream.close();
} catch (IOException ignored) {
}
}
}
class Exit {
private Exit() {
}
public static void exit(InputReader in, PrintWriter out) {
in.setFinished(true);
in.close();
out.close();
}
}
interface Solver {
public void solve(int testNumber, InputReader in, PrintWriter out);
}
class IOUtils {
public static int[] readIntArray(InputReader in, int size) {
int[] array = new int[size];
for (int i = 0; i < size; i++)
array[i] = in.readInt();
return array;
}
}
class TaskB implements Solver {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int count = in.readInt();
int index = in.readInt() - 1;
int[] taken = IOUtils.readIntArray(in, count);
for (int i = index; ; i++) {
if (taken[i % count] == 1) {
out.println(i % count + 1);
return;
}
}
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.util.*;
import java.io.BufferedWriter;
import java.io.PrintWriter;
import java.io.FileWriter;
import java.io.File;
import java.io.IOException;
// warm-up
public class QuizLeague {
static void solve() throws IOException{
Scanner sc = new Scanner(new File("input.txt"));
PrintWriter p = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
int n=sc.nextInt(),k=sc.nextInt(),i=1,noc=n;
int[] a = new int[n+1];
int index = (k%n==0) ? n : k%n;
while (noc-->0) a[i++]=sc.nextInt();
while (a[index]==0) index = (++k%n==0) ? n : k%n;
p.println(index);
p.close();
sc.close();
}
public static void main(String args[]) throws IOException {
solve();
}
} | JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) throws IOException {
Scanner scanner = new Scanner(new FileReader("input.txt"));
PrintWriter writer = new PrintWriter(new File("output.txt"));
int n = scanner.nextInt();
int k = scanner.nextInt();
scanner.nextLine();
int[] array = new int[n];
for (int i = 0; i < n; i++) {
array[i] = scanner.nextInt();
}
int i = k - 1;
for (int j = 0; j < n; j++) {
if (i == n) {
i = 0;
}
if (array[i++] == 1) {
writer.print(i);
break;
}
}
writer.close();
}
} | JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 |
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class B {
public static void main(String[] args) throws IOException {
Scanner sc=new Scanner(new FileReader("input.txt"));
FileWriter fw=new FileWriter("output.txt");
int n=sc.nextInt();
int k=sc.nextInt();
int[] ar=new int[n];
for(int i=0;i<ar.length;i++)
ar[i]=sc.nextInt();
int s=k-1;
while(true) {
if(ar[s]==1) {
fw.write((s+1)+"\n");
break;
}
s=(s+1)%n;
}
fw.flush();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 |
import java.io.*;
import java.util.*;
public class Template {
//static int cnt=0;
static Scanner sc=new Scanner(System.in);
static ArrayList<Integer> v;
static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public static void main (String[] args) throws java.lang.Exception{
Scanner sc=new Scanner(new File("input.txt"));
FileWriter wr=new FileWriter("output.txt");
ArrayList<Integer> arr=new ArrayList();
//ArrayList<String> arr=new ArrayList();
//ArrayList<Long> arr=new ArrayList();
//ArrayList<Double> arr=new ArrayList();
int n=sc.nextInt();
int k=sc.nextInt();
for(int i=0;i<n;i++){
arr.add(sc.nextInt());
}
int ans=0;
for(int i=k-1;i<n;i++) {
if(arr.get(i)==1) {
ans=i+1;
break;
}
if(i==n-1 && arr.get(i)!=1) {
i=-1;
}
}
wr.write(String.valueOf(ans));
wr.close();
//System.out.println(index+1);
}
//}
static long gcd(long a,long b) {
if(b==0) {
return a;
}
return gcd(b,a%b);
}
public static int s2i(String s) {
return Integer.parseInt(s);
}
public static int LeastIntFn(int a,int b) {
if((b%a)==0) {
return (int)b/a;
}
return (int)(b/a)+1;
}
public static ArrayList<Long> arrInpLong(int n){
ArrayList<Long> arr=new ArrayList();
for(int i=0;i<n;i++) {
arr.add(sc.nextLong());
}
return arr;
}
public static ArrayList<String> arrInpStr(int n){
ArrayList<String> arr=new ArrayList();
for(int i=0;i<n;i++) {
arr.add(sc.nextLine());
}
return arr;
}
public static ArrayList<Integer> arrInpInt(int n){
ArrayList<Integer> arr=new ArrayList();
for(int i=0;i<n;i++) {
int k=sc.nextInt();
arr.add(k);
}
return arr;
}
public static void printArrInt(ArrayList<Integer> arr) {
for(int i=0;i<arr.size();i++) {
System.out.print(arr.get(i)+" ");
}
}
public static int min(int a,int b,int c) {
int min1=Math.min(a, b);
return Math.min(min1,c);
}
} | JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.*;
import java.util.*;
import java.math.*;
//created at 7:35 PM 10/20/11 by Abrackadabra
public class B {
int IOMode = 2; //0 - consoleIO, 1 - <taskName>.in/out, 2 - input.txt/output.txt, 3 - test case generator
String taskName = "";
void solve() throws IOException {
int n = nextInt(), k = nextInt() - 1;
boolean[] a = new boolean[n];
for (int i = 0; i < n; i++)
a[i] = nextInt() == 1;
while (!a[k]) {
k = (k + 1) % n;
}
out.println(k + 1);
}
public static void main(String[] args) throws IOException {
if (args.length > 0 && args[0].equals("Abra")) debugMode = true;
new B().run();
}
long startTime = System.nanoTime(), tempTime = startTime, finishTime = startTime;
long startMem = Runtime.getRuntime().totalMemory(), finishMem = startMem;
void run() throws IOException {
init();
if (debugMode) {
con.println("Start");
con.println("Console output:");
}
solve();
finishTime = System.nanoTime();
finishMem = Runtime.getRuntime().totalMemory();
out.flush();
if (debugMode) {
int maxSymbols = 1000, c = 0;
BufferedReader tbr = new BufferedReader(new FileReader("input.txt"));
char[] a = new char[maxSymbols];
tbr.read(a);
if (a[0] != 0) {
con.println();
con.println("File input:");
con.print(a);
}
boolean left = true;
for (int i = 0; i < maxSymbols; i++) left = left && a[i] != 0;
if (left) con.println("...");
else con.println();
tbr = new BufferedReader(new FileReader("output.txt"));
a = new char[maxSymbols];
tbr.read(a);
if (a[0] != 0) {
con.println();
con.println("File output:");
con.print(a);
}
left = true;
for (int i = 0; i < maxSymbols; i++) left = left && a[i] != 0;
if (left) con.println("...");
else con.println();
con.println("Time passed: " + (finishTime - startTime) / 1000000000.0 + " sec");
con.println("Memory used: " + (finishMem - startMem) + " bytes");
con.println("Total memory: " + Runtime.getRuntime().totalMemory() + " bytes");
}
}
boolean tick(double x) {
if (System.nanoTime() - tempTime > x) {
tempTime = System.nanoTime();
con.println("Tick at " + (tempTime - startTime) / 1000000000 + " sec");
con.print(" ");
return true;
}
return false;
}
void printTime() {
con.println((System.nanoTime() - tempTime) + " nanos passed");
tempTime = System.nanoTime();
}
static boolean debugMode = false;
PrintStream con = System.out;
void init() throws IOException {
if (debugMode) {
br = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter(new FileWriter("output.txt"));
} else
switch (IOMode) {
case 0:
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
break;
case 1:
br = new BufferedReader(new FileReader(taskName + ".in"));
out = new PrintWriter(new FileWriter(taskName + ".out"));
break;
case 2:
br = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter(new FileWriter("output.txt"));
break;
case 3:
out = new PrintWriter(new FileWriter("input.txt"));
break;
}
}
BufferedReader br;
PrintWriter out;
StringTokenizer in;
boolean hasMoreTokens() throws IOException {
while (in == null || !in.hasMoreTokens()) {
String line = br.readLine();
if (line == null) return false;
in = new StringTokenizer(line);
}
return true;
}
String nextString() throws IOException {
return hasMoreTokens() ? in.nextToken() : null;
}
int nextInt() throws IOException {
return Integer.parseInt(nextString());
}
long nextLong() throws IOException {
return Long.parseLong(nextString());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextString());
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.util.*;
import java.io.*;
public class b {
public static void main(String[] args) throws IOException
{
boolean[] sieve = new boolean[1000001];
Arrays.fill(sieve, true);
sieve[0]=sieve[1]=false;
for(int i = 2; i<sieve.length; i++) if(sieve[i]) for(long j = (long)i*i; j<sieve.length; j+=i) sieve[(int)j] = false;
Scanner input = new Scanner(new File("input.txt"));
PrintWriter out = new PrintWriter(new File("output.txt"));
//PrintWriter out = new PrintWriter(System.out);
//input.init(System.in);
int n= input.nextInt(), k = input.nextInt()-1;
int[] data = new int[n];
for(int i=0; i<n; i++) data[i] = input.nextInt();
int res = k;
while(data[res] == 0)
{
res++;
res %= n;
}
out.println(res+1);
out.close();
}
static class X implements Comparable<X>
{
int a;
double b;
public X(int a, double b)
{
this.a = a; this.b = b;
}
@Override
public int compareTo(X that) {
// TODO Auto-generated method stub
if(this.b == that.b) return this.a-that.a;
return (int)Math.signum(that.b-this.b);
}
}
public static long gcd(long a, long b)
{
if(b == 0) return a;
return gcd(b, a%b);
}
public static class input {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(
new InputStreamReader(input) );
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(
reader.readLine() );
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
static long nextLong() throws IOException {
return Long.parseLong( next() );
}
}
static class IT
{
int[] left,right, val, a, b;
IT(int n)
{
left = new int[3*n];
right = new int[3*n];
val = new int[3*n];
a = new int[3*n];
b = new int[3*n];
init(0,0, n);
}
int init(int at, int l, int r)
{
a[at] = l;
b[at] = r;
if(l==r)
left[at] = right [at] = -1;
else
{
int mid = (l+r)/2;
left[at] = init(2*at+1,l,mid);
right[at] = init(2*at+2,mid+1,r);
}
return at++;
}
//return the sum over [x,y]
int get(int x, int y)
{
return go(x,y, 0);
}
int go(int x,int y, int at)
{
if(at==-1) return 0;
if(x <= a[at] && y>= b[at]) return val[at];
if(y<a[at] || x>b[at]) return 0;
return go(x, y, left[at]) + go(x, y, right[at]);
}
//add v to elements x through y
void add(int x, int y, int v)
{
go3(x, y, v, 0);
}
void go3(int x, int y, int v, int at)
{
if(at==-1) return;
if(y < a[at] || x > b[at]) return;
val[at] += (Math.min(b[at], y) - Math.max(a[at], x) + 1)*v;
go3(x, y, v, left[at]);
go3(x, y, v, right[at]);
}
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) throws FileNotFoundException {
Scanner in = new Scanner(new File("input.txt"));
PrintWriter out = new PrintWriter(new File("output.txt"));
int n = in.nextInt();
int k = in.nextInt();
int[] arr = new int[n];
for (int i = 0; i < arr.length; i++)
arr[i] = in.nextInt();
int i = k - 1;
while (true) {
if (arr[i] == 1) {
out.print(i + 1);
break;
}
i++;
if (i == n)
i = 0;
}
out.close();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class B {
private void work() throws IOException {
Scanner sc = new Scanner(new FileReader("input.txt"));
PrintWriter pw = new PrintWriter(new FileWriter("output.txt"));
int n = sc.nextInt();
int k = sc.nextInt() - 1;
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
while (a[k % n] == 0)
k++;
pw.println(k % n + 1);
pw.close();
sc.close();
}
public static void main(String[] args) throws IOException {
new B().work();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class B120 {
public static void main(String[] args) throws IOException {
Scanner in = new Scanner(new File("input.txt"));
PrintWriter out = new PrintWriter(new File("output.txt"));
int N = in.nextInt();
int K = in.nextInt()-1;
int[] A = new int[N];
for (int n=0; n<N; n++) {
A[n] = in.nextInt();
}
while (A[K] == 0) {
K = (K+1)%N;
}
out.println(K+1);
out.close();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.*;
import java.util.*;
public class QuizLeague {
public static void main(String[] args) throws FileNotFoundException {
Scanner cin = new Scanner(new File("input.txt"));
PrintWriter out = new PrintWriter(new File("output.txt"));
int n = cin.nextInt();
int k = cin.nextInt() - 1;
int[] v = new int[n];
for (int i = 0; i < n; i++) {
v[i] = cin.nextInt();
}
while (v[k] == 0) {
k = (k + 1) % n;
}
out.println((k + 1));
out.close();
}
} | JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.File;
import java.io.FileInputStream;
import java.io.PrintWriter;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
try {
new Main().start();
} catch (Exception e) {
e.printStackTrace();
}
}
private void start() throws Exception {
Scanner in = new Scanner(new FileInputStream(new File("input.txt")));
PrintWriter out = new PrintWriter(new File("output.txt"));
int n, k;
int a[] = new int[1001];
n = in.nextInt();
k = in.nextInt();
for (int i = 1; i <= n; i++) {
a[i] = in.nextInt();
}
while (a[k] == 0) {
k++;
if (k > n) {
k = 1;
}
}
out.println(k);
out.close();
in.close();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.*;
import java.util.*;
import java.math.*;
public class A implements Runnable {
public void run() {
long startTime = System.nanoTime();
int n = nextInt();
int t = nextInt();
boolean[] b = new boolean[n + 1];
for (int i = 0; i < n; i++) {
b[i + 1] = nextInt() == 0;
}
while (b[t]) {
if (++t == n + 1) {
t = 1;
}
}
println(t);
if (fileIOMode) {
System.out.println((System.nanoTime() - startTime) / 1e9);
}
out.close();
}
//-----------------------------------------------------------------------------------
private static boolean fileIOMode;
private static String problemName = "a";
private static BufferedReader in;
private static PrintWriter out;
private static StringTokenizer tokenizer;
public static void main(String[] args) throws Exception {
fileIOMode = true;
if (fileIOMode) {
in = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter("output.txt");
} else {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
}
tokenizer = new StringTokenizer("");
new Thread(new A()).start();
}
private static String nextLine() {
try {
return in.readLine();
} catch (IOException e) {
return null;
}
}
private static String nextToken() {
while (!tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(nextLine());
}
return tokenizer.nextToken();
}
private static int nextInt() {
return Integer.parseInt(nextToken());
}
private static long nextLong() {
return Long.parseLong(nextToken());
}
private static double nextDouble() {
return Double.parseDouble(nextToken());
}
private static BigInteger nextBigInteger() {
return new BigInteger(nextToken());
}
private static void print(Object o) {
if (fileIOMode) {
System.out.print(o);
}
out.print(o);
}
private static void println(Object o) {
if (fileIOMode) {
System.out.println(o);
}
out.println(o);
}
private static void printf(String s, Object... o) {
if (fileIOMode) {
System.out.printf(s, o);
}
out.printf(s, o);
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.File;
import java.io.PrintStream;
import java.util.Scanner;
public class B {
public static void main(String[] args) {
try {
//*
File in = new File("input.txt");
File out = new File("output.txt");
PrintStream writer = new PrintStream(out);
Scanner sc = new Scanner(in);
/*
PrintStream writer = new PrintStream(System.out);
Scanner sc = new Scanner(System.in);
*/
int n = sc.nextInt(),
k = sc.nextInt();
boolean[] selected = new boolean[n];
for(int i = 0; i < n; i++)
selected[i] = sc.nextInt() == 0;
for(int i = k-1; ; i=(i+1)%n) {
if(!selected[i]) {
writer.println(i+1);
break;
}
}
} catch (Exception e) {
} finally {
}
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.*;
import java.util.*;
public class CodeForces implements Runnable {
void solve() throws IOException {
int n = nextInt();
int p = nextInt();
int []a= new int[n];
for(int i=0;i<n;i++)
a[i]=nextInt();
if(a[p-1]==1)
writer.println(p);
else
{
boolean find = false;
int pos = 0;
for(int i=p;i<n;i++)
if(a[i]==1)
{
pos = i;
find = true;
break;
}
if(!find)
{
for(int i=0;i<p;i++)
if(a[i]==1)
{
pos = i;
break;
}
}
writer.println(pos+1);
}
}
BufferedReader reader;
StringTokenizer tokenizer;
PrintWriter writer;
public void run() {
try {
//reader = new BufferedReader(new InputStreamReader(System.in));
//writer = new PrintWriter(System.out);
reader = new BufferedReader(new FileReader("input.txt"));
writer = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
tokenizer = null;
solve();
reader.close();
writer.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
String nextToken() throws IOException {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
public static void main(String[] args) {
new CodeForces().run();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.*;
import java.util.*;
import java.text.*;
import java.util.regex.*;
/**
* Problem-(#) - Main.java
*
* @author Isuru Madushanka Weerarathna
* @team CSECodersV2
* @written 2011/10/22
* @competetion IEEEXtreme 5.0
*/
public class Main {
public static void main(String[] args) {
try {
new Main().solve();
} catch (Exception e) {
e.printStackTrace();
}
}
public void solve() throws IOException {
BufferedReader reader = new BufferedReader(new FileReader("input.txt"));
PrintWriter out = new PrintWriter(new FileWriter("output.txt"));
int[] sz = getAsInt(reader.readLine().split("[ ]+"));
int[] sectors = getAsInt(reader.readLine().split("[ ]+"));
int p = sz[1]-1;
while (sectors[p]!=1) {
p++;
if (p==sz[0]) p =0;
}
out.println(p+1);
out.flush();
out.close();
reader.close();
}
private int[] getAsInt(String[] parts) {
int[] res = new int[parts.length];
for (int i = 0; i<parts.length; i++) res[i] = Integer.parseInt(parts[i]);
return res;
}
private double[] getAsDouble(String[] parts) {
double[] res = new double[parts.length];
for (int i = 0; i<parts.length; i++) res[i] = Double.parseDouble(parts[i]);
return res;
}
} | JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 |
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.Scanner;
public class P120B
{
public static void main(String[] args) throws FileNotFoundException
{
Scanner inScanner = new Scanner(new File("input.txt"));
PrintStream out = new PrintStream(new File("output.txt"));
int n = inScanner.nextInt();
int k = inScanner.nextInt() - 1;
int[] answered = new int[n];
for (int i = 0; i < n; i++)
{
answered[i] = inScanner.nextInt();
}
while (answered[k] == 0)
{
k = (k + 1) % n;
}
out.println(k + 1);
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class solution {
void solve() throws IOException {
int n = nextInt(), k = nextInt() - 1;
int[] z = new int[1010];
for (int i = 0; i < n; ++i) {
z[i] = nextInt();
}
while (true) {
if (z[k] == 1) {
out.println(k + 1);
break;
} else {
k = (k + 1) % n;
}
}
}
BufferedReader br;
StringTokenizer st;
PrintWriter out;
String nextToken() throws IOException {
while (st == null || !st.hasMoreTokens()) {
String s = br.readLine();
if (s == null) {
return "-1";
}
st = new StringTokenizer(s);
}
return st.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
void run() throws IOException {
br = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter("output.txt");
solve();
out.close();
br.close();
}
public static void main(String[] args) throws IOException {
new solution().run();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class A implements Runnable {
private void solve() throws IOException {
int n = nextInt();
int k = nextInt() - 1;
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
if(a[k] == 1)
writer.print(k + 1);
else {
for(int i = k + 1; i < a.length; ++i)
if(a[i] == 1){
writer.print(i + 1);
return;
}
for(int i = 0; i < a.length; ++i){
if(a[i] == 1){
writer.print(i + 1);
return;
}
}
}
}
public static void main(String[] args) {
new A().run();
}
BufferedReader reader;
StringTokenizer tokenizer;
PrintWriter writer;
public void run() {
try {
reader = new BufferedReader(new FileReader("input.txt"));
tokenizer = null;
writer = new PrintWriter("output.txt");
solve();
reader.close();
writer.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
String nextToken() throws IOException {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
} | JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
try {
Scanner scanner = new Scanner(new File("input.txt"));
PrintWriter writer = new PrintWriter(new File("output.txt"));
int n = scanner.nextInt();
int nk = scanner.nextInt();
int [] arr = new int[n];
for (int i=0;i<n;i++) {
arr[i]=scanner.nextInt();
}
int i=nk-1;
while (arr[i]==0) {
if (i==n-1) {
i=0;
}else {
i++;
}
}
i++;
writer.print(i);
writer.close();
} catch (FileNotFoundException e) {
}
}
} | JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class b120 {
public static void main(String[] args) throws IOException
{
Scanner in = new Scanner(new File("input.txt"));
PrintWriter out = new PrintWriter(new File("output.txt"));
int q = in.nextInt();
int n = in.nextInt()-1;
boolean[] t = new boolean[q];
for(int i = 0; i < q; i++)
t[i] = in.nextInt()==1;
while(true)
{
if(!t[n])
{
n++;
n%=q;
}
else
{
out.println(n+1);
break;
}
}
out.close();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.*;
import java.util.*;
public class kuchBhi{
public static void main(String[] args) throws Throwable{
// BufferedReader br = new BufferedReader(new FileReader("input.txt"));
// String in = br.nextLine();
Scanner sc = new Scanner(new File("input.txt"));
BufferedWriter br1 = new BufferedWriter(new FileWriter("output.txt"));
int n = sc.nextInt();
int k = sc.nextInt();
int ar[] = new int[n+1];
for(int i=1;i<=n;i++)
ar[i] = sc.nextInt();
while(true)
{
if(ar[k]==1)
{
br1.write(k+"");
break;
}
k = (k+1)%n;
if(k==0)
k = n;
}
sc.close();
br1.close();
}
} | JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | //package com.company;
import java.util.*;
import java.io.*;
import java.util.Scanner;
public class A {
public static void main(String[] args) throws Exception{
// write your code here
Scanner sc = new Scanner(new File("input.txt"));
PrintWriter out = new PrintWriter(new File("output.txt"));
int n = sc.nextInt();
int k = sc.nextInt();
int[] sp = new int[n];
for (int i=0;i<n;i++){
sp[i]=sc.nextInt();
}
int t = 0;
int index = k-1;
while(t<n){
if(sp[index]>0){
out.println(index+1);
break;
} else if (index+1>=n){
index=0;
} else {
index++;
}
t++;
}
out.close();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.*;
import java.math.BigInteger;
import java.util.*;
import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
public class CodeForces {
public void solve() throws IOException {
int n=nextInt();
int k=nextInt()-1;
int arr[]=new int[n];
for(int i=0;i<n;i++){
arr[i]=nextInt();
}
while(true){
if(arr[k]==1) break;
k++;
if(k==n) k=0;
}
out.print(k+1);
}
public static void main(String[] args) {
new CodeForces().run();
}
int NOD(int a, int b) {
while (a != 0 && b != 0) {
if (a >= b)
a = a % b;
else
b = b % a;
}
return a + b;
}
BufferedReader reader;
StringTokenizer tokenizer;
PrintWriter out;
public void run() {
try {
//reader = new BufferedReader(new InputStreamReader(System.in));
reader = new BufferedReader(new FileReader("input.txt"));
tokenizer = null;
//out = new PrintWriter(System.out);
out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
// long t=new Date().getTime();
solve();
// writer.println(t-new Date().getTime());
reader.close();
out.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
String nextToken() throws IOException {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
} | JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | //package que_a;
import java.io.*;
import java.util.*;
import java.math.*;
public class utkarsh {
InputStream is;
PrintWriter out;
long mod = (long) (1e9 + 7), inf = (long) (3e18);
void solve() {
int n = ni(), k = ni()-1;
int a[] = na(n);
while(a[k] == 0) {
k = (k + 1) % n;
}
out.println(k+1);
}
long mp(long b, long e) {
long r = 1;
while(e > 0) {
if((e&1) == 1) r = (r * b) % mod;
b = (b * b) % mod;
e >>= 1;
}
return r;
}
//---------- I/O Template ----------
public static void main(String[] args) { new utkarsh().run(); }
void run() {
File fi = new File("input.txt");
File fo = new File("output.txt");
try{
is = new FileInputStream(fi);
out = new PrintWriter(fo);
} catch (FileNotFoundException e){
System.out.printf("Error %s\n",e);
}
solve();
out.flush();
}
byte input[] = new byte[1024];
int len = 0, ptr = 0;
int readByte() {
if(ptr >= len) { ptr = 0;
try { len = is.read(input); }
catch(IOException e) { throw new InputMismatchException(); }
if(len <= 0) { return -1; }
} return input[ptr++];
}
boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); }
int skip() {
int b = readByte();
while(b != -1 && isSpaceChar(b)) { b = readByte(); }
return b;
}
char nc() { return (char)skip(); }
String ns() {
int b = skip();
StringBuilder sb = new StringBuilder();
while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); }
return sb.toString();
}
String nLine() {
int b = skip();
StringBuilder sb = new StringBuilder();
while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); }
return sb.toString();
}
int ni() {
int n = 0, b = readByte();
boolean minus = false;
while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
if(b == '-') { minus = true; b = readByte(); }
if(b == -1) { return -1; } //no input
while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
return minus ? -n : n;
}
long nl() {
long n = 0L; int b = readByte();
boolean minus = false;
while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
if(b == '-') { minus = true; b = readByte(); }
while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
return minus ? -n : n;
}
double nd() { return Double.parseDouble(ns()); }
float nf() { return Float.parseFloat(ns()); }
int[] na(int n) {
int a[] = new int[n];
for(int i = 0; i < n; i++) { a[i] = ni(); }
return a;
}
char[] ns(int n) {
char c[] = new char[n];
int i, b = skip();
for(i = 0; i < n; i++) {
if(isSpaceChar(b)) { break; }
c[i] = (char)b; b = readByte();
} return i == n ? c : Arrays.copyOf(c,i);
}
} | JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.*;
import java.util.*;
public class B {
public static void main(String[] args) throws Exception {
Scanner s = new Scanner(new File("input.txt"));
PrintWriter pw = new PrintWriter(new File("output.txt"));
int n = s.nextInt(), k = s.nextInt() - 1;
int[] a = new int[n];
for (int i = 0; i < n; ++i) {
a[i] = s.nextInt();
}
for (int i = k;; i = (i + 1) % n) {
if (a[i] == 1) {
pw.println(i + 1);
pw.close();
return;
}
}
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Stack;
import java.util.Vector;
public class Main {
private static BufferedReader input;
private static PrintWriter output;
private static StreamTokenizer stoken;
static String fin = "input";
static String fout = "output";
private static void solve() throws IOException {
int n = nextInt();
int k = nextInt();
int[] mas = new int[n];
for (int i = 0; i<n; i++){
mas[i] = nextInt();
}
if (mas[k-1]==1){ output.print(k);}else{
int cnt = k-1;
while(mas[cnt]!=1){
cnt++;
cnt %= n;
}
output.print(cnt+1);}
}
public static void main(String[] args) throws IOException {
// input = new BufferedReader(new InputStreamReader(System.in));
// output = new PrintWriter(System.out);
input = new BufferedReader(new FileReader(fin + ".txt"));
output = new PrintWriter(new FileWriter(fout + ".txt"));
stoken = new StreamTokenizer(input);
solve();
input.close();
output.flush();
output.close();
}
// ��������� 32-������ ����� �����
private static int nextInt() throws IOException {
return (int) nextDouble();
}
// ��������� 64-������ ����� �����
private static long nextLong() throws IOException {
return (long) nextDouble();
}
// ��������� 64-������ ������� �����
private static double nextDouble() throws IOException {
stoken.nextToken();
return stoken.nval;
}
} | JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.util.*;
import java.io.*;
public class cf120b {
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(new File("input.txt"));
PrintWriter out = new PrintWriter(new File("output.txt"));
int n = in.nextInt();
int k = in.nextInt()-1;
int[] v = new int[n];
for(int i=0; i<n; i++)
v[i] = in.nextInt();
while(v[k]==0)
k = (k+1)%n;
out.println((k+1));
out.close();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
/**
* http://codeforces.ru/contest/120/problem/B
*
* @author ashuiskov
* @date 18.10.2011
*/
public class ProblemB
{
public static void main(String[] args) throws NumberFormatException, IOException
{
long curTime = System.currentTimeMillis();
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt")));
String line;
Integer numSectors = null, currentSector = null;
Integer[] sectors = null;
while ((line = reader.readLine()) != null) {
if (numSectors == null) {
String[] elems = line.split(" ");
numSectors = Integer.parseInt(elems[0]);
currentSector = Integer.parseInt(elems[1])-1;
}
else {
String[] elems = line.split(" ");
sectors = new Integer[elems.length];
for (int i = 0; i < elems.length; i++)
sectors[i] = Integer.parseInt(elems[i]);
break;
}
}
reader.close();
Integer result = null;
while (result == null) {
if (sectors[currentSector]==1) result = currentSector+1;
currentSector++;
if (currentSector.equals(numSectors)) currentSector=0;
}
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("output.txt")));
writer.write(result.toString());
writer.close();
long endTime = System.currentTimeMillis();
System.out.println((endTime-curTime) + " ms");
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
// Scanner r = new Scanner(System.in);
Scanner r = new Scanner(new File("input.txt"));
BufferedWriter out = new BufferedWriter(new FileWriter("output.txt"));
int n = r.nextInt();
int k = r.nextInt()-1;
int[] a = new int[n];
for(int i = 0; i < n; i++)
a[i] = r.nextInt();
while(a[k] == 0)k = (k+1)%n;
//System.out.println(k + 1);
out.write("" + (k + 1));
out.newLine();
out.close();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 |
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class B120 {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new FileReader("input.txt"));
PrintWriter out = new PrintWriter("output.txt");
StringTokenizer st = new StringTokenizer(in.readLine());
int n = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken()) - 1;
int[] a = new int[n];
st = new StringTokenizer(in.readLine());
for (int i = 0 ; i < n ; i++)
a[i] = Integer.parseInt(st.nextToken());
while (a[k] == 0) {
k = (k + 1) % n;
}
out.println(k + 1);
out.close();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.awt.Point;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.Map.Entry;
import static java.lang.Math.*;
public class B {
final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE")!=null;
BufferedReader in;
PrintWriter out;
StringTokenizer tok = new StringTokenizer("");
void init() throws FileNotFoundException{
in = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter("output.txt");
}
String readString() throws IOException{
while(!tok.hasMoreTokens()){
tok = new StringTokenizer(in.readLine());
}
return tok.nextToken();
}
int readInt() throws IOException{
return Integer.parseInt(readString());
}
long readLong() throws IOException{
return Long.parseLong(readString());
}
double readDouble() throws IOException{
return Double.parseDouble(readString());
}
public static void main(String[] args){
new B().run();
}
public void run(){
try{
long t1 = System.currentTimeMillis();
init();
solve();
out.close();
long t2 = System.currentTimeMillis();
System.err.println("Time = "+(t2-t1));
}catch (Exception e){
e.printStackTrace(System.err);
System.exit(-1);
}
}
void solve() throws IOException{
int n = readInt();
int k = readInt() - 1;
boolean[] a = new boolean[n];
for (int i = 0; i < n; i++){
a[i] = readInt() == 1;
}
for (int i = k; i < n; i++){
if (a[i]){
out.print((i + 1));
return;
}
}
for (int i = 0; i < k; i++){
if (a[i]){
out.print((i + 1));
return;
}
}
}
static class MyAlgo{
long gcd(long a, long b){
if (a == 0) return b;
return gcd(b % a, a);
}
long lcm(long a, long b){
return a / gcd(a, b)*b;
}
long[] gcdPlus(long a, long b){
long[] d = new long[3];
if (a == 0){
d[0] = b;
d[1] = 0;
d[2] = 1;
}else{
d = gcdPlus(b % a, a);
long r = d[1];
d[1] = d[2] - b/a*d[1];
d[2] = r;
}
return d;
}
long binpow(long a, int n){
if (n == 0) return 1;
if ((n & 1) == 0){
long b = binpow(a, n/2);
return b*b;
}else return binpow(a, n - 1)*a;
}
long binpowmod(long a, int n, int m){
if (m == 1) return 0;
if (n == 0) return 1;
if ((n & 1) == 0){
long b = binpowmod(a, n/2, m);
return (b*b) % m;
}else return binpowmod(a, n - 1, m)*a % m;
}
long f(long n, int x, int k){ //Кол-во десятичных чисел (включая 0), содержащих в себе цифры от 0 до k-1
if (n == 0) return 1;
long b = binpow(10, x - 1);
long c = n / b;
return (c < k? c: k)*binpow(k, x - 1) + (c < k? 1: 0)*f(n % b, x - 1, k);
}
long fib(int n){
if (n == 0) return 0;
if ((n & 1) == 0){
long f1 = fib(n/2 - 1);
long f2 = fib(n/2 + 1);
return f2*f2 - f1*f1;
}else{
long f1 = fib(n/2);
long f2 = fib(n/2 + 1);
return f1*f1 + f2*f2;
}
}
BigInteger BigFib(int n){
if (n == 0) return BigInteger.ZERO;
if ((n & 1) == 0){
BigInteger f1 = BigFib(n/2 - 1);
f1 = f1.multiply(f1);
BigInteger f2 = BigFib(n/2 + 1);
f2 = f2.multiply(f2);
return f2.subtract(f1);
}else{
BigInteger f1 = BigFib(n/2);
f1 = f1.multiply(f1);
BigInteger f2 = BigFib(n/2 + 1);
f2 = f2.multiply(f2);
return f2.add(f1);
}
}
double d(Point p1, Point p2){
return sqrt(d2(p1, p2));
}
double d2(Point p1, Point p2){
return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y);
}
boolean IsProbablyPrime(long n){
if (n == 1) return false;
if ((n & 1) == 0) return false;
for (int j = 3; j < sqrt(n) + 1; j += 2){
if (n % j == 0) return false;
}
return true;
}
int[] Sieve(int n){
boolean[] b = new boolean[n+1];
Arrays.fill(b, true);
b[0] = false;
b[1] = false;
long nLong = n;
int j=0;
for (int i = 1; i <= n; i++) {
if (b[i]){
j++;
if (((long)i)*i <= nLong) {
for (int k = i*i; k <= n; k += i) {
b[k] = false;
}
}
}
}
int[] p = new int[j];
Arrays.fill(p, 0);
j=0;
for (int i = 2; i <= n; i++) {
if (b[i]){
p[j]=i;
j++;
}
}
return p;
}
int[][] Palindromes(String s){
char[] c = s.toCharArray();
int n = c.length;
int[][] d = new int[2][n];
int l = 0, r = -1;
for (int i = 0; i < n; i++){
int j = (i > r? 0: min(d[0][l+r-i+1], r-i+1)) + 1;
for (; i - j >= 0 && i + j - 1< n && c[i-j] == c[i+j-1]; j++);
d[0][i] = --j;
if (i + d[0][i] - 1 > r){
r = i + d[0][i] - 1;
l = i - d[0][i];
}
}
l = 0;
r = -1;
for (int i = 0; i < n; i++){
int j = (i > r? 0: min(d[1][l+r-i], r-i)) + 1;
for (; i - j >= 0 && i + j < n && c[i-j] == c[i+j]; j++);
d[1][i] = --j;
if (i + d[1][i] > r){
r = i + d[1][i];
l = i - d[1][i];
}
}
return d;
}
public static class SuffixAvtomaton{
class State{
int length;
State link;
HashMap<Character, State> next;
boolean terminal;
public State(){
length = 0;
link = null;
next = new HashMap<Character, State>();
terminal = false; }
}
ArrayList<State> st;
State last;
public SuffixAvtomaton(String s){
Init();
for (int i = 0; i < s.length(); i++){
add(s.charAt(i));
}
Marking();
}
void Init(){
last = new State();
st = new ArrayList<State>();
st.add(last);
}
void add(char c){
State newLast = new State();
st.add(newLast);
newLast.length = last.length + 1;
State p;
for (p = last; p != null &&!p.next.containsKey(c); p = p.link){
p.next.put(c, newLast);
}
if (p == null){
newLast.link = st.get(0);
}else{
State q = p.next.get(c);
if (q.length == p.length + 1){
newLast.link = q;
}else{
State clone = new State();
clone.link = q.link;
clone.length = p.length + 1;
clone.next.putAll(q.next);
for (; p!= null; p = p.link){
if (p.next.get(c) == q) p.next.put(c, clone);
}
q.link = newLast.link = clone;
}
}
last = newLast;
}
void Marking(){
for (State term = last; term != null; term = term.link){
term.terminal = true;
}
}
int SubStrings(){
HashMap<State, Integer> d = new HashMap<State, Integer>();
d.put(st.get(0), 0);
ArrayList<State> list = new ArrayList<State>();
list.add(st.get(0));
while (list.size() != 0){
State p = list.get(0);
list.remove(0);
for (State s: st){
if (s.next.containsValue(p)){
if (d.containsKey(p)){
int x = d.get(p) + 1;
d.put(s, x);
list.add(s);
}
}
}
}
return d.get(last);
}
}
public class Permutation {
int[] a;
int n;
public Permutation(int n){
this.n=n;
a=new int[n];
for (int i=0; i<n; i++){
a[i]=i;
}
}
public boolean nextPermutation(){ //Пишется с do{}while(nextPermutation(a));
int i=n-1;
for (i=n-2; i>=0; i--){
if (a[i]<a[i+1]){
break;
}
}
if (i==-1){
return false;
}
int jMin=i+1;
for (int j=n-1; j>i; j--){
if (a[i]<a[j]&&a[j]<a[jMin]){
jMin=j;
}
}
swap(i, jMin);
for (int j=1; j<=(n-i)/2; j++){
swap(i+j, n-j);
}
return true;
}
public int get(int i){
return a[i];
}
void swap(int i, int j){
int r=a[i];
a[i]=a[j];
a[j]=r;
}
}
public class Fraction implements Comparable<Fraction>, Cloneable{
public final Fraction FRACTION_ZERO = new Fraction();
public final Fraction FRACTION_ONE = new Fraction(1);
public long numerator = 0;
public long denominator = 1;
public Fraction(){
numerator = 0;
denominator = 1;
}
public Fraction(long numerator){
this.numerator = numerator;
denominator = 1;
}
public Fraction(long numerator, long denominator){
this.numerator = numerator;
this.denominator = denominator;
Cancellation();
}
public Fraction(double numerator, double denominator, int accuracy){
this.numerator = (long)(numerator*pow(10,accuracy));
this.denominator = (long)(denominator*pow(10,accuracy));
Cancellation();
}
public Fraction(String s){
if (s.charAt(0) == '-'){
denominator = -1;
s = s.substring(1);
}
if (s.indexOf("/") != -1){
denominator *= Integer.parseInt(s.substring(s.indexOf("/") + 1));
}
if (s.indexOf(" ") != -1){
numerator = Integer.parseInt(s.substring(0, s.indexOf(" "))) * abs(denominator) + Integer.parseInt(s.substring(s.indexOf(" ") + 1, s.indexOf("/")));
}else{
if (s.indexOf("/") != -1){
numerator = Integer.parseInt(s.substring(0, s.indexOf("/")));
}else{
numerator = Integer.parseInt(s)*abs(denominator);
}
}
this.Cancellation();
}
void Cancellation(){
long g = gcd(abs(numerator), abs(denominator));
numerator /= g;
denominator /= g;
if (denominator < 0){
numerator *= -1;
denominator *= -1;
}
}
public String toString(){
String s = "";
if (numerator == 0){
return "0";
}
if (numerator < 0){
s += "-";
}
if (abs(numerator) >= denominator){
s += Long.toString(abs(numerator) / denominator) + " ";
}
if (abs(numerator) % denominator != 0){
s += Long.toString(abs(numerator) % denominator);
}else{
s = s.substring(0, s.length()-1);
}
if (denominator != 1){
s += "/" + Long.toString(denominator);
}
return s;
}
public Fraction add(Fraction f){
Fraction fResult = new Fraction();
fResult.denominator = lcm(denominator, f.denominator);
fResult.numerator = numerator * fResult.denominator / denominator + f.numerator * fResult.denominator / f.denominator;
fResult.Cancellation();
return fResult;
}
public Fraction subtract(Fraction f){
Fraction fResult = new Fraction();
fResult.denominator = lcm(denominator, f.denominator);
fResult.numerator = numerator * fResult.denominator / denominator - f.numerator * fResult.denominator / f.denominator;
fResult.Cancellation();
return fResult;
}
public Fraction multiply(Fraction f){
Fraction fResult = new Fraction();
fResult.numerator = numerator * f.numerator;
fResult.denominator = denominator * f.denominator;
fResult.Cancellation();
return fResult;
}
public Fraction divide(Fraction f){
Fraction fResult = new Fraction();
fResult.numerator = numerator * f.denominator;
fResult.denominator = denominator * f.numerator;
fResult.Cancellation();
return fResult;
}
@Override
public int compareTo(Fraction f){
long g = gcd(denominator, f.denominator);
long res = numerator * (f.denominator / g) - f.numerator * (denominator / g);
if (res < 0){
return -1;
}
if (res > 0){
return 1;
}
return 0;
}
public Fraction clone(){
Fraction fResult = new Fraction(numerator, denominator);
return fResult;
}
public Fraction floor(){
Fraction fResult = this.clone();
fResult.numerator = (fResult.numerator / fResult.denominator) * fResult.denominator;
return fResult;
}
public Fraction ceil(){
Fraction fResult = this.clone();
fResult.numerator = (fResult.numerator/fResult.denominator + 1) * fResult.denominator;
return fResult;
}
public Fraction binpow(int n){
if (n==0) return FRACTION_ONE;
if ((n&1)==0){
Fraction f=this.binpow(n/2);
return f.multiply(f);
}else return binpow(n-1).multiply(this);
}
}
class FenwickTree_1{ //One-dimensional array
int n;
long[] t;
public FenwickTree_1(int n){
this.n = n;
t = new long[n];
}
public long sum(int xl, int xr){
return sum(xr) - sum(xl);
}
public long sum(int x){
long result = 0;
for (int i = x; i >= 0; i = (i & (i + 1)) - 1){
result += t[i];
}
return result;
}
public void update(int x, long delta){
for (int i = x; i < n; i = (i | (i + 1))){
t[i] += delta;
}
}
}
class FenwickTree_2{ //Two-dimensional array
int n, m;
long[][] t;
public FenwickTree_2(int n, int m){
this.n = n;
this.m = m;
t = new long[n][m];
}
public long sum(int xl, int yl, int xr, int yr){
return sum(xr, yr) - sum(xl - 1, yr) - sum(xr, yl - 1) + sum(xl - 1, yl - 1);
}
public long sum(int x, int y){
long result = 0;
for (int i = x; i >= 0; i = (i & (i + 1)) - 1){
for (int j = y; j >= 0; j = (j & (j + 1)) - 1){
result+=t[i][j];
}
}
return result;
}
public void update(int x, int y, long delta){
for (int i = x; i < n; i = (i | (i + 1))){
for (int j = y; j < m; j = (j | (j + 1))){
t[i][j] += delta;
}
}
}
}
class FenwickTree_3{ //Three-dimensional array
int n, m, l;
long[][][] t;
public FenwickTree_3(int n, int m, int l){
this.n = n;
this.m = m;
this.l = l;
t = new long[n][m][l];
}
public long sum(int xl, int yl, int zl, int xr, int yr, int zr){
return sum(xr, yr, zr) - sum(xl - 1, yr, zr)
+ sum(xl - 1, yr, zl - 1) - sum(xr, yr, zl - 1)
- sum(xr, yl - 1, zr) + sum(xl - 1, yl - 1, zr)
- sum(xl - 1, yl - 1, zl - 1) + sum(xr, yl - 1, zl - 1);
}
public long sum(int x, int y, int z){
long result = 0;
for (int i = x; i >= 0; i = (i & (i + 1)) - 1){
for (int j = y; j >= 0; j = (j & (j + 1)) - 1){
for (int k = z; k >= 0; k = (k & (k + 1)) - 1){
result += t[i][j][k];
}
}
}
return result;
}
public void update(int x, int y, int z, long delta){
for (int i = x; i < n; i = (i | (i + 1))){
for (int j = y; j < n; j = (j | (j + 1))){
for (int k = z; k < n; k = (k | (k + 1))){
t[i][j][k] += delta;
}
}
}
}
}
}
} | JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.*;
import java.util.*;
public class A1008 {
public static void main(String [] args) throws Exception {
InputStream inputReader = System.in;
OutputStream outputReader = System.out;
InputReader in = new InputReader(new FileInputStream(new File("input.txt")));//new InputReader(inputReader);
PrintWriter out = new PrintWriter(new FileOutputStream(new File("output.txt")));
Algorithm solver = new Algorithm();
solver.solve(in, out);
out.close();
}
}
class Algorithm {
void solve(InputReader ir, PrintWriter pw) {
int n =ir.nextInt(), k = ir.nextInt() - 1;
int [] a = new int[n];
for (int i = 0; i < n; i++) a[i] = ir.nextInt();
while(a[k] == 0) k = (k + 1) % n;
pw.print(k + 1);
}
boolean isPolyndrom(String str) {
StringBuilder newStr = new StringBuilder();
for (int i = str.length() - 1; i >= 0; i--) newStr.append(str.charAt(i));
return newStr.toString().equals(str);
}
}
class InputReader {
private BufferedReader reader;
private StringTokenizer tokenizer;
InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
String nextLine(){
String fullLine = null;
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
fullLine = reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
return fullLine;
}
return fullLine;
}
String [] toArray() {
return nextLine().split(" ");
}
int nextInt() {
return Integer.parseInt(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
long nextLong() {
return Long.parseLong(next());
}
} | JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.Scanner;
public class B {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(new File("input.txt"));
BufferedWriter out = new BufferedWriter(new FileWriter("output.txt"));
int sectors = sc.nextInt();
int points = sc.nextInt();
int arr[] = new int[sectors];
for (int i = 0; i < sectors; i++) {
arr[i] = sc.nextInt();
}
if (arr[points - 1] == 1) {
out.write("" + points);
out.close();
return;
}
int count = points - 1;
while (arr[count] != 1) {
count++;
if (count > sectors - 1) {
count = 0;
}
}
out.write("" + ++count);
out.close();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.*;
import java.util.*;
public class B {
public static void main(String[] args) throws IOException{
// FastScanner sc = new FastScanner();
// int yo = sc.nextInt();
// while(yo-->0) {
// }
FileInputStream in = new FileInputStream("input.txt");
FileOutputStream out = new FileOutputStream("output.txt");
PrintWriter pw = new PrintWriter(out);
Scanner sc = new Scanner(in);
String[] line1 = sc.nextLine().split(" ");
String[] line2 = sc.nextLine().split(" ");
int n = Integer.parseInt(line1[0]);
int k = Integer.parseInt(line1[1])-1;
int[] arr = new int[n];
for(int i = 0; i < line2.length; i++) {
arr[i] = Integer.parseInt(line2[i]);
}
// int n = sc.nextInt();
// int k = sc.nextInt()-1;
//
// int[] arr = sc.readArray(n);
for(int i = k; i < 2*n; i++) {
if(arr[i%n] == 1) {
pw.println((i%n)+1);
pw.close();
// System.out.println((i%n)+1);
return;
}
}
}
static int mod = 1000000007;
static long pow(int a, int b) {
if(b == 0) {
return 1;
}
if(b == 1) {
return a;
}
if(b%2 == 0) {
long ans = pow(a,b/2);
return ans*ans;
}
else {
long ans = pow(a,(b-1)/2);
return a * ans * ans;
}
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
static int gcd(int a, int b) {
return a%b == 0 ? b : gcd(b,a%b);
}
static boolean[] sieve(int n) {
boolean isPrime[] = new boolean[n+1];
for(int i = 2; i <= n; i++) {
if(isPrime[i]) continue;
for(int j = 2*i; j <= n; j+=i) {
isPrime[j] = true;
}
}
return isPrime;
}
// For Input.txt and Output.txt
// FileInputStream in = new FileInputStream("input.txt");
// FileOutputStream out = new FileOutputStream("output.txt");
// PrintWriter pw = new PrintWriter(out);
// Scanner sc = new Scanner(in);
// sc.nextLine()
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.*;
import java.util.StringTokenizer;
public class Quiz {
public static void main(String args[])throws IOException{
BufferedReader in = new BufferedReader(new FileReader("input.txt"));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
StringTokenizer tok = new StringTokenizer(in.readLine());
int n = Integer.parseInt(tok.nextToken());
int now = Integer.parseInt(tok.nextToken());
int[] ques = new int[n];
tok = new StringTokenizer(in.readLine());
for(int i = 0; i < n; i++){
ques[i] = Integer.parseInt(tok.nextToken());
}
if(ques[now - 1] == 1)
out.println(now);
else{
int res = solve(ques, now);
out.println(res);
}
out.close();
in.close();
System.exit(0);
}
private static int solve(int[] ques, int now){
int i = now - 1;
while(true){
if(ques[i] == 1) return i + 1;
else{
i++;
if(i == ques.length) i = 0;
}
}
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.*;
import java.util.*;
/**
*
* @author Moonkin
*/
public class Main {
StreamTokenizer in;
PrintWriter out;
BufferedReader br;
public static void main(String[] args) throws Exception {
new Main().run();
}
public void run() throws Exception {
boolean oj = System.getProperty("ONLINE_JUDGE") != null;
oj = false;
in = oj ? new StreamTokenizer(new BufferedReader(new InputStreamReader(
System.in))) : new StreamTokenizer(new BufferedReader(
new FileReader("input.txt")));
//out = new PrintWriter(new OutputStreamWriter(System.out));
out = new PrintWriter ("output.txt");
br = new BufferedReader(new InputStreamReader(System.in));
solve();
out.flush();
}
int nextInt() throws Exception {
in.nextToken();
return (int) in.nval;
}
double nextDouble() throws Exception {
in.nextToken();
return in.nval;
}
String nextString() throws Exception {
in.nextToken();
return in.sval;
}
public void solve() throws Exception {
int n=nextInt();
int k=nextInt();
int [] mas = new int[n];
for (int i=0;i<n;i++){
mas[i]=nextInt();
}
int i=k-1;
while (true){
if (mas[i]==1) break;
i++;
if (i==n) i=0;
}
out.println(i+1);
}
} | JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
try
{
Scanner in;
PrintWriter out;
in = new Scanner(new File("input.txt"));
out = new PrintWriter("output.txt");
int n = in.nextInt();
int k = in.nextInt();
int[] d = new int[n];
for (int i = 0; i < n; ++i)
{
d[i] = in.nextInt();
}
while (d[k-1]==0)
{
++k;
if (k==n+1) k=1;
}
out.write(Integer.toString(k));
out.write("\n");
out.close();
}
catch (IOException ex)
{
throw new RuntimeException(ex);
}
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | //no full solution
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.StringTokenizer;
//codeforce
public class codeforceProblemB1 {
private static BufferedReader in;
private static PrintWriter out;
private static StringTokenizer input;
public static void main(String[] args) throws IOException {
// -------------------------------------------------------------------------
// Initializing...
new codeforceProblemB1();
// -------------------------------------------------------------------------
// put your code here... :)
String line1=in.readLine();
String[]s1=line1.split(" ");
String line2=in.readLine();
String[]s2=line2.split(" ");
boolean found=false;
int i=Integer.parseInt(s1[1])-1;
while(!found){
if(Integer.parseInt(s2[i])==1){
break;
}
i=(i+1)%Integer.parseInt(s1[0]);
}
out.println(i+1);
// int numbers = nextInt();
// int count = nextInt();
// int[] a = new int[numbers];
// int index = 0;
// HashMap<Integer,Integer>h1=new HashMap<Integer, Integer>();
// for (int i = 0; i < numbers; i++) {
// int inp = nextInt();
// if (inp == 1) {
// a[index++] = inp;
// }
// }
// writeln("");
// -------------------------------------------------------------------------
// closing up
end();
// --------------------------------------------------------------------------
}
private static String nextString() throws IOException {
if (!input.hasMoreTokens())
input = new StringTokenizer(in.readLine());
return input.nextToken();
}
public codeforceProblemB1() throws IOException {
// Input Output for Console to be used for trying the test samples of
// the problem
// in = new BufferedReader(new InputStreamReader(System.in));
// out = new PrintWriter(System.out);
in = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter("output.txt");
// -------------------------------------------------------------------------
// Initalize Stringtokenizer input
//input = new StringTokenizer(in.readLine());
}
private static int nextInt() throws IOException {
if (!input.hasMoreTokens())
input = new StringTokenizer(in.readLine());
return Integer.parseInt(input.nextToken());
}
private static void end() throws IOException {
in.close();
out.close();
System.exit(0);
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class test {
public static void main(String[] args) throws IOException {
Scanner in = new Scanner(new File("input.txt"));
PrintWriter out = new PrintWriter(new File("output.txt"));
// Scanner in = new Scanner(System.in);
// PrintWriter out = new PrintWriter(System.out);
int n = in.nextInt();
int k = in.nextInt() - 1;
int[] sectors = new int[n];
for (int i = 0; i < n; i++)
sectors[i] = in.nextInt();
while (true) {
if (sectors[k] == 1) {
out.println(k + 1);
break;
} else {
k = (k + 1) % n;
}
}
out.close();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.util.*;
import java.io.*;
public class Test2 {
public void doMain() throws Exception{
Scanner input = new Scanner(new FileReader("input.txt"));
PrintWriter pw = new PrintWriter(new FileWriter("output.txt"));
int n = input.nextInt();
int k = input.nextInt();
int person[] = new int[n];
for(int i = 0 ; i < n ; i++){
person[i] = input.nextInt();
}
pw.println(question(n,k,person));
input.close();
pw.flush();
pw.close();
}
public static int question(int n,int k,int[] person){
while(true){
if(k > n){
k = 0;
}else if(person[k-1] != 0){
return k;
}
k++;
}
}
public static void main(String[] args) throws Exception{
(new Test2()).doMain();
}
} | JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.File;
import java.io.PrintWriter;
import java.util.Scanner;
public class B120 {
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(new File("input.txt"));
PrintWriter out = new PrintWriter("output.txt");
int n = in.nextInt();
int k = in.nextInt()-1;
int[] ar = new int[n];
for(int x = 0;x<n;x++) {
ar[x] = in.nextInt();
}
while(ar[k]==0) {
k++;
k%=n;
}
out.println(k+1);
out.close();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.*;
import java.util.*;
public class Main {
private BufferedReader input;
private PrintWriter output;
private StringTokenizer stoken;
String fin = "input";
String fout = "output";
private void solve() {
/*
String way = nextToken();
int a = nextInt();
String res = "L";
if (way.equals("front")) {
if (a == 1) {
res = "L";
} else {
res = "R";
}
} else {
if (a == 1) {
res = "R";
} else {
res = "L";
}
}
output.print(res);
*/
int n = nextInt();
int k = nextInt();
int res = 0;
int first1 = -1;
for (int i=1; i<=n; i++) {
int c = nextInt();
if (first1 == -1 && c == 1) first1 = i;
if (i >= k && c == 1) {
res = i;
break;
}
}
if (res == 0) res = first1;
output.print(res);
}
Main() throws IOException {
//�������� ������
//input = new BufferedReader(new InputStreamReader(System.in));
//output = new PrintWriter(System.out);
//�������� ������
input = new BufferedReader(new FileReader(fin + ".txt"));
output = new PrintWriter(new FileWriter(fout + ".txt"));
solve();
input.close();
output.flush();
output.close();
}
int nextInt() {
return Integer.parseInt(nextToken());
}
long nextLong() {
return Long.parseLong(nextToken());
}
double nextFloat() {
return Float.parseFloat(nextToken());
}
double nextDouble() {
return Double.parseDouble(nextToken());
}
String nextToken() {
while ((stoken == null) || (!stoken.hasMoreTokens())) {
try {
String line = input.readLine();
stoken = new StringTokenizer(line);
} catch (IOException e) {
e.printStackTrace();
}
}
return stoken.nextToken();
}
public static void main(String[] args) throws IOException {
new Main();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.File;
import java.io.FileReader;
import java.io.PrintWriter;
import java.util.Scanner;
public class Lift {
public static void main(String[] args) throws Exception{
FileReader fr = new FileReader(new File("input.txt"));
PrintWriter pw = new PrintWriter(new File("output.txt"));
Scanner scan = new Scanner(new File("input.txt"));
int n = scan.nextInt(), k = scan.nextInt(), c[] = new int[n+1], a = k;
for(int i = 1; i<n+1; i++) {
c[i] = scan.nextInt();
}
int b = c[k];
while (b != 1) {
b = c[k];
if (k == n & b != 1) {
k = 1;
} else if (b != 1) {
k++;
}
}
pw.print(k);
fr.close();
pw.close();
scan.close();
}
} | JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
public class B_120_Quiz_League {
public static void main(String[] args) throws FileNotFoundException{
Scanner in = new Scanner(new File("input.txt"));
PrintWriter out = new PrintWriter(new File("output.txt"));
int n = in.nextInt();
int k = in.nextInt()-1;
int[] v = new int[n];
for(int i=0; i<n; i++)
v[i] = in.nextInt();
while(v[k]==0)
k = (k+1)%n;
out.println((k+1));
out.close();
}
} | JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.*;
import java.util.*;
public class TaskB {
BufferedReader br;
PrintWriter out;
StringTokenizer stok;
String nextToken() throws IOException {
while (stok == null || !stok.hasMoreTokens()) {
String s = br.readLine();
if (s == null) {
return "-1";
}
stok = new StringTokenizer(s);
}
return stok.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
char nextChar() throws IOException {
return (char) (br.read());
}
String nextLine() throws IOException {
return br.readLine();
}
void solve() throws IOException {
int n = nextInt(), k = nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
for (int i = k - 1; ; i++) {
if (i >= n) {
i -= n;
}
if (a[i] == 1) {
out.print(i + 1);
break;
}
}
}
void run() throws IOException {
br = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter("output.txt");
// br = new BufferedReader(new InputStreamReader(System.in));
// out = new PrintWriter(System.out);
solve();
br.close();
out.close();
}
public static void main(String[] args) throws IOException {
// Locale.setDefault(Locale.US);
new TaskB().run();
}
} | JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;
public class QuizLeague {
public static void main(String[] args) throws FileNotFoundException {
FileInputStream is = new FileInputStream("input.txt");
Scanner scanner = new Scanner(is);
int n = scanner.nextInt();
int p = scanner.nextInt();
p--;
scanner.nextLine();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = scanner.nextInt();
}
while (p < n) {
if (arr[p] == 1) {
break;
}
p++;
p = p % n;
}
PrintWriter pw = new PrintWriter(new FileOutputStream("output.txt"));
pw.println(p + 1);
pw.flush();
//System.out.println(p + 1);
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 |
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class B {
public static void main(String[] args) throws IOException {
Scanner in = new Scanner(new FileReader("input.txt"));
PrintWriter out = new PrintWriter(new FileWriter("output.txt"));
int n = in.nextInt();
int k = in.nextInt() - 1;
int[] A = new int[n];
for (int i = 0; i < n; i++)
A[i] = in.nextInt();
for (int i = k;; i = (i + 1) % n)
if (A[i] == 1) {
out.println(i + 1);
break;
}
out.flush();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class B {
private void Problem() throws IOException {
int n = nextInt(), k = nextInt(), a[] = new int[n+1];
for (int i = 1; i < n + 1; i ++) a[i] = nextInt();
for (int i = k; i < n + 1; i ++) {
if (a[i] == 1) {
out.print(i);
break;
}
if (i == n) i = 0;
}
}
BufferedReader in;
StringTokenizer tokenizer;
PrintWriter out;
public void Solution() throws IOException {
in = new BufferedReader(new FileReader(new File("input.txt")));
out = new PrintWriter(new File("output.txt"));
tokenizer = null;
Problem();
in.close();
out.close();
}
public static void main(String[] args) throws IOException {
new B().Solution();
}
int nextInt() throws IOException, NumberFormatException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException, NumberFormatException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException, NumberFormatException {
return Double.parseDouble(nextToken());
}
String nextToken() throws IOException {
if (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(in.readLine());
}
return tokenizer.nextToken();
}
}
| JAVA |
120_B. Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one.
Output
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1 | 2 | 8 | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
public class B {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
FileInputStream fis = new FileInputStream("input.txt");
FileWriter fstream = new FileWriter("output.txt");
BufferedWriter out = new BufferedWriter(fstream);
DataInputStream in = new DataInputStream(fis);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine = br.readLine();
int n = Integer.parseInt(strLine.split(" ")[0]);
int k = Integer.parseInt(strLine.split(" ")[1]);
String[] nums = br.readLine().split(" ");
for (int i = 0; i < n; i++) {
int index = (i + k - 1) % n;
if (Integer.parseInt(nums[index]) != 0) {
out.write(Integer.toString(index + 1));
break;
}
}
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
} | JAVA |
Subsets and Splits