题目链接: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的更多相关文章

  1. Codeforces 659B Qualifying Contest【模拟,读题】

    写这道题题解的目的就是纪念一下半个小时才读懂题...英文一多读一读就溜号... 读题时还时要静下心来... 题目链接: http://codeforces.com/contest/659/proble ...

  2. codeforces 659B B. Qualifying Contest(水题+sort)

    题目链接: B. Qualifying Contest time limit per test 1 second memory limit per test 256 megabytes input s ...

  3. Codeforces Round #346 (Div. 2) B Qualifying Contest

    B. Qualifying Contest 题目链接http://codeforces.com/contest/659/problem/B Description Very soon Berland ...

  4. Codeforces Round #346 (Div. 2) B. Qualifying Contest 水题

    B. Qualifying Contest 题目连接: http://www.codeforces.com/contest/659/problem/B Description Very soon Be ...

  5. B. Qualifying Contest

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  6. codeforces E. The Contest(最长上升子序列)

    题目链接:https://codeforces.com/contest/1257/problem/E 题意:给三个序列k1,k2,k3,每个序列有一堆数,k1是前缀,k3是后缀,k2是中间,现可以从任 ...

  7. 【37.74%】【codeforces 725D】Contest Balloons

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. CodeForces 474B E(Contest #1)

    题意: 给你一个数n,代表n段区间,接下来有n个数(a1,a2,...an)代表每段区间的长度,第一段区间为[1,a1],第二段区间为[a1+1,a1+a2],...第i段区间为[ai-1+1,ai- ...

  9. CodeForces 546B C(Contest #1)

    Description Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge ...

随机推荐

  1. UTL_RAW

    The UTL_RAW package provides SQL functions for manipulating RAW data types. 该包的功能其实可以用来加密: SELECT    ...

  2. uoj Goodbye Jiawu

    这次比赛真是太伤我心了. 比(惨)赛(不)结(忍)果(睹) 完挂感言 uoj round 5已经挂了一次了,没想到还要再挂第二次. 这次比赛的期望得分是\(100+100+100+70+10\)的.没 ...

  3. struts2之高危远程代码执行漏洞,可造成服务器被入侵,下载最新版本进行修复

          Struts2 被发现存在新的高危远程代码执行漏洞,可造成服务器被入侵,只要是Struts2版本 低于 2.3.14.3 全部存在此漏洞.目前官方已经发布了最新的版本进行修复.请将stru ...

  4. H3C HCSE 官方培训胶片(中文) 下载

    H3C HCSE 官方培训胶片(中文) 点击文件名下载 HM-040 OSPF路由协议(V5.1).ppt HM-041 BGP协议原理及配置(V5.0).ppt HM-041 BGP协议原理及配置( ...

  5. ASP.NET利用byte检测上传图片安全

    ) { //这里只测试上传第一张图片file[0] HttpPostedFile file0 = Request.Files[]; //转换成byte,读取图片MIME类型 Stream stream ...

  6. rowid结构浅析

    select rowid from dual AAAAB0AABAAAAOhAAA rowid结构如下: 对象号    文件号   块号   行号 XXXXXX    XXX     XXXXXX X ...

  7. 基于visual Studio2013解决面试题之1404希尔排序

     题目

  8. LoadRunner 监控 Apache

    配置Apache部分 1.修改Apache中Httpd.conf文件 <Location /server-status> SetHandler server-status Order de ...

  9. HDU - 5036 Explosion

    Problem Description Everyone knows Matt enjoys playing games very much. Now, he is playing such a ga ...

  10. HDU 1251 统计难题 (字符串-Trie树)

    统计难题 Problem Description Ignatius近期遇到一个难题,老师交给他非常多单词(仅仅有小写字母组成,不会有反复的单词出现),如今老师要他统计出以某个字符串为前缀的单词数量(单 ...