codeforces 120B Quiz League
来源:互联网 发布:剑豪生死斗 知乎 编辑:程序博客网 时间:2024/05/17 01:10
题目链接:传送门。
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 50 1 0 1 0
Output
2
Input
2 11 1
Output
1
【题意】
n个人要来回答问题,0表示已经回答过这个问题,1表示没有回答过问题,现在有一个问题要交给一个人回答,如果这个人没有回答过问题就是这个人回答,否则就让他后面第一个没回答问题的人来回答,其中她们是环绕着坐的,所以第n个人后面是第一个人。问你这个问题最后是谁来回答。
【分析】
简单的模拟就行,当然有一个更快的办法就是直接找出所有没有回答问题的人,然后二分一下就行了。
【代码】
#include<bits/stdc++.h>using namespace std;int num[1234];int main(){ freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); int len,que,a,flag = 0; scanf("%d%d",&len,&que); for(int i = 1;i<=len;i++) { scanf("%d",&a); if(a) num[flag++] = i; } num[flag++] = len+num[0]; int ans = lower_bound(num,num+flag,que)-num; printf("%d\n",num[ans]>len?num[ans]-len:num[ans]); return 0;}
阅读全文
0 0
- codeforces 120B Quiz League
- codeforces 781B. Innokenty and a Football League(贪心)
- 【Codeforces Round #403】Codeforces 781B Innokenty and a Football League
- Codeforces Round #403 B. Innokenty and a Football League(二分图匹配)
- codeforces 234E Champions' League
- codeforces 337C Quiz
- CodeForces 337C. Quiz
- CodeForces 337C. Quiz
- CodeForces Round #145(234E) - Champions' League
- codeforces D. Innokenty and a Football League
- codeforces - 337c Quiz【贪心】
- 【codeforces 337C Quiz】 + 贪心
- CodeForces - 337 C. Quiz【贪心】
- Codeforces Round #196 (Div. 2) C. Quiz
- Codeforces Round #196 (Div. 2) C. Quiz
- 【CodeForces】337C - Quiz(贪心,思维)
- Codeforces 337C Quiz 贪心+快速幂
- Codeforces 337C Quiz【贪心+快速幂】
- JAVA并发处理注意事项
- XShell+Xmanager实现在XShell中显示远程服务器的图形界面
- tomcat内存调优案例
- 《深入理解Java虚拟机》学习笔记(8)--线程安全与锁优化
- Qt学习—qt共享内存的使用
- codeforces 120B Quiz League
- 为Chrome上的Inifinity插件打call
- ccplot中的地图投影
- 深度探索C++ 对象模型【第六章1】
- java Timetask 访问service 抛空指针异常解决方案
- Hyperledger Fabric 开发环境搭建
- 【bzoj1083】[SCOI2005]繁忙的都市 kruskal
- UIWebView&WKWebView获取网页高度
- Python语法