F - Kagome Kagome
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld
& %llu
Submit Status Practice ZOJ
3492
Description
Kagome kagome, kago no naka no tori wa Itsu itsu deyaru? Yoake no ban ni Tsuru to kame to subetta. Ushiro no shoumen daare?
Translation:
Kagome kagome, the bird in the cage, when will you come out? In the evening of the dawn, the crane and turtle slipped. Who stands right behind you now?
Kagome Kagome is a Japanese children‘s game. One child is chosen as the oni (literally demon or ogre, but similar to the concept of "it" in tag) and sits blindfolded (or with their eyes covered). The other children join
hands and walk in circles around the oni while singing the song for the game. When the song stops, the oni speaks aloud the name of the person behind him, and if he is correct, the person
behind will exchange places with the oni.
Higurashi Tewi is playing Kagome Kagome with her n (n is even) friends as the oni now. She peeps to know who is right in front of her. Knowing the order of the
children in circle and assuming that they keep distance evenly, it‘s easy to derive who is right behind her.
Input
There are multiple test cases. The first line of input is an integer T ≈ 100 indicating the number of test cases.
The first line of each test case starts with an even number 1 ≤ n ≤ 100, followed by the name of the child who is right in front of Higurashi Tewi. The second line contains exactly n different
names, listed in counterclockwise order. Name is an alphanumeric string whose length never exceeds 20. It‘s guaranteed that the child in front of Higurashi Tewi is always contained in the list exactly once.
Output
For each test case, output the name of the child who is right behind Higurashi Tewi.
Sample Input
3 2 Alice Alice Bob 4 inu inu neko usagi kizune 4 cat dog cat rabbit fox
Sample Output
Bob usagi fox
References
这题的题意真是难读懂,,right behind是后面的意思。。
可是这题,求的是坐在你对面的那个人是谁。。
一个多小时题意硬是没懂。。
主要思路,一个圈里,你对面那个人,数过去肯定是总人数的一半。
#include <cstdio> #include <algorithm> #include <map> #include <cstring> #include <cmath> #include <iostream> using namespace std; #define lson l , m , rt << 1 #define rson m + 1 , r , rt << 1 | 1 #define LL __int64 typedef long long ll; #define PI 3.1415926 int main() { int t,i; cin>>t; char s[2222][25]; char s1[25]; char s2[25]; while(t--) { int n,m; cin>>n; scanf("%s",s1); if(n%2==0) m=n/2; else m=n/2+1; for(i=1; i<=n; i++) scanf("%s",s[i]); for(i=1; i<=n; i++) { if(strcmp(s1,s[i])==0) { if(i+m<=n) { printf("%s\n",s[(i+m)]); break; } else { printf("%s\n",s[(i+m)%n]); break; } } } } return 0; }