CodeChef November Lunchtime 2013 Lucy and the Number Game(简单题)
2013-11-24 15:50
393 查看
n个人报数找到只有一个报过且最小的数。
代码如下:
View Code
代码如下:
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <algorithm> #define INF 0x7fffffff #define LEN 1000100 using namespace std; struct P{ char name[50]; int num; }man[LEN]; bool cmp(struct P a, struct P b){ return a.num<b.num; } int main() { // freopen("in.txt", "r", stdin); int T, n; scanf("%d", &T); while(T--){ scanf("%d", &n); for(int i=1; i<=n; i++){ scanf("%s%d", man[i].name, &man[i].num); } sort(man+1, man+n+1, cmp); int ans = -1, loc = man[1].num, cnt=1; for(int i=2; i<=n; i++){ if(man[i].num == loc){ cnt++; } else { if(cnt == 1){ ans = i-1; break; }else{ loc = man[i].num; cnt = 1; } } } if(cnt == 1 && loc == man .num) ans = n; if(ans!=-1)printf("%s\n", man[ans].name); else printf("Nobody wins.\n"); } return 0; }
View Code
相关文章推荐
- codechef_Home » Compete » January Challenge 2013 » The Minimum Number Of Moves
- Codechef Wonder Woman and the Dark man
- CF389A:Fox and Number Game(简单数论)
- CodeChef Inscription 2013 Wonderland jewellery(简单题)
- codechef The Ball And Cups题解
- Codeforces Round #430 A. Kirill And The Game
- codechef The Ball And Cups题解
- use code to generate Silverlight Controls at run time, and serialize the control into XAML file
- codeforces Soldier and Number Game(dp+素数筛选)
- Codeforces Round #430 (Div. 2) A. Kirill And The Game
- codechef The Lead Game 题解
- Codeforces Round #304 (Div. 2) D Soldier and Number Game
- ●CodeChef Sereja and Game
- (数学水题)Codeforces A. Kirill And The Game
- 【 Codeforces Round #430 (Div. 2) A 】 Kirill And The Game
- CodeChef November Challenge 2013 » Yet Another Cute Girl
- codechef Johnny and the Beanstalk 题解
- Codeforces Round #228 (Div. 2), problem: (A) Fox and Number Game
- codechef January Lunchtime 2017简要题解
- codechef Chef and The Right Triangles 题解