codeforces 659B Qualifying Contest
题目链接:http://codeforces.com/problemset/problem/659/B
题意:
n个人,m个区。给出n个人的姓名(保证不相同),属于的区域,所得分数。从每个区域中选出成绩最好的两个人去参加比赛,输出这两个人的名字。如果第三个人的成绩和第二个人的成绩相同,则输出“?”,保证结果不确定。
解题思路:
刚开始想用个什么STL容器把这三个属性存进去,然后根据区域的不同对每个区域的选手的分数进行排序,最后看选手确定,输出答案。
可是做比赛的时候没有想到应该用什么STL容器。
然后想到了用结构体。
结构体里面有选手的三个信息,然后对结构体进行排序。
交上去发现错了,后来发现是自己在写判断条件的时候出错了。对于判断条件与思路一定要条理清晰才不容易出错。
具体代码如下:
#include<bits/stdc++.h> using namespace std; struct p
{
string s;
int num;
int scro;
}P[]; bool cmp(p X,p Y) ///结构体排序
{
if(X.num==Y.num)
return X.scro>Y.scro;
return X.num<Y.num;
} int main()
{
int n,m,t1,t2;
string s1;
scanf("%d %d",&n,&m); for(int i=;i<n;i++) ///读入数据
{
cin>>P[i].s>>P[i].num>>P[i].scro;
} sort(P,P+n,cmp);///对数据按照一定的规则进行排序 for(int j=;j<=m;)
{
for(int i=;i<n;i++)
{
if(P[i].num==j) ///这里的判断条件一定要很清楚,不然容易出错。
{
if(P[i+].num==j)
{
if((P[i+].num==j&&P[i+].scro!=P[i+].scro)||(P[i+].num!=j))
cout<<P[i].s<<" "<<P[i+].s<<endl;
else
cout<<"?"<<endl;
}
else
{
cout<<"?"<<endl;
}
j++;
}
}
} return ;
}
codeforces 659B Qualifying Contest的更多相关文章
- Codeforces 659B Qualifying Contest【模拟,读题】
写这道题题解的目的就是纪念一下半个小时才读懂题...英文一多读一读就溜号... 读题时还时要静下心来... 题目链接: http://codeforces.com/contest/659/proble ...
- codeforces 659B B. Qualifying Contest(水题+sort)
题目链接: B. Qualifying Contest time limit per test 1 second memory limit per test 256 megabytes input s ...
- Codeforces Round #346 (Div. 2) B Qualifying Contest
B. Qualifying Contest 题目链接http://codeforces.com/contest/659/problem/B Description Very soon Berland ...
- Codeforces Round #346 (Div. 2) B. Qualifying Contest 水题
B. Qualifying Contest 题目连接: http://www.codeforces.com/contest/659/problem/B Description Very soon Be ...
- B. Qualifying Contest
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- codeforces E. The Contest(最长上升子序列)
题目链接:https://codeforces.com/contest/1257/problem/E 题意:给三个序列k1,k2,k3,每个序列有一堆数,k1是前缀,k3是后缀,k2是中间,现可以从任 ...
- 【37.74%】【codeforces 725D】Contest Balloons
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- CodeForces 474B E(Contest #1)
题意: 给你一个数n,代表n段区间,接下来有n个数(a1,a2,...an)代表每段区间的长度,第一段区间为[1,a1],第二段区间为[a1+1,a1+a2],...第i段区间为[ai-1+1,ai- ...
- CodeForces 546B C(Contest #1)
Description Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge ...
随机推荐
- 基于visual Studio2013解决C语言竞赛题之0906文件插入
题目
- poj 1990
题目链接 借鉴cxlove大神的思路 题意:听力v,位置x,2个牛交流声音为max(v1,v2)*(x1-x2),求总的 10000^2 tle 用的树状数组做的,排序,2个,小于vi的牛的总数和距离 ...
- POJ 2031 prim
Building a Space Station Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 4400 Accepted: 2 ...
- ASIHTTPRequest-插件的使用
链接地址:http://blog.sina.com.cn/s/blog_7b9d64af0101e5uf.html 一.什么是ASIHTTPRequest ASIHTTPRequest 插件是一个 ...
- JAVA面试中问及HIBERNATE与 MYBATIS的对比,在这里做一下总结(转)
hibernate以及mybatis都有过学习,在java面试中也被提及问道过,在项目实践中也应用过,现在对hibernate和mybatis做一下对比,便于大家更好的理解和学习,使自己在做项目中更加 ...
- encode_utf8 把字符编码成字节 decode_utf8解码UTF-8到字符
encode_utf8 $octets = encode_utf8($string); Equivalent to "$octets = encode("utf8", $ ...
- Ember.js - About
Ember.js - About More Productive Out of the Box. Write dramatically less code with Ember's Handleb ...
- 有N个正实数(注意是实数,大小升序排列) x1 , x2 ... xN,另有一个实数M。 需要选出若干个x,使这几个x的和与 M 最接近。 请描述实现算法,并指出算法复杂度
题目:有N个正实数(注意是实数,大小升序排列) x1 , x2 ... xN,另有一个实数M. 需要选出若干个x,使这几个x的和与 M 最接近. 请描述实现算法,并指出算法复杂度. 代码如下: #in ...
- linux学习之四---gdb调试
在Linux应用程序开发中,最经常使用的调试器是gdb. 一.启动和退出gdb gdb调试的对象是可运行文件,而不是程序的源码.假设要使一个可运行文件能够被gdb调试,那么使用编译器gcc编译时须要增 ...
- Mac os 进行Android开发笔记(2)
Mac OS X 下开发 Android 1> MAC OS Android环境搭建: 2>MAC OS 配置 Andoid ADB: 3>MAC OS 上进行Android真机 ...