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 ...
随机推荐
- Step by step guide to set up master and slave machines(转)
Note: There is no need to install Jenkins on the slave machine. On your master machine go to Manage ...
- c语言string.h和memory.h某些函数重复问题
在C语言中,为了使用memset()函数,你是选择#include <string.h>还是<memory.h>?两个都可以,如何选择? <string.h>,标准 ...
- ArrayList内元素按照字典排序
package day08; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; ...
- boost中asio网络库多线程并发处理实现,以及asio在多线程模型中线程的调度情况和线程安全。
1.实现多线程方法: 其实就是多个线程同时调用io_service::run for (int i = 0; i != m_nThreads; ++i) { boo ...
- SilkTest Q&A 12
111. 谁能告诉我,正在执行的SilkTest的log是存放在哪里? 答案1: 用下面的命令可以导出文本格式的log "c:/program files/segue/silktest/pa ...
- Java 异常解决之java.lang.IllegalArgumentException: Comparison method violates its general contract!
Java 异常解决 在你的代码前加一句 System.setProperty("java.util.Arrays.useLegacyMergeSort", "true&q ...
- openfire数据库中文乱码问题
1.首先数据库的编码设置为UTF-8 2.项目的编码也要设置为UTF-8 假设数据保存到数据库的时候还有乱码 就要改动openfire配置文件 在openfire主文件夹\conf\openfire ...
- Bitmap Style Designer非官方说明
Bitmap Style Designer Bitmap Style Designer给我的第一印象就是简陋,估计也是为了赶工.大致体会了一下,还是能够使用.因为目前没有对此有比较详细的中文资料,就把 ...
- MSSQL - 存储过程取出5条热点新闻
USE [DB_News] GO /****** Object: StoredProcedure [dbo].[SelectHotNews] Script Date: 2015/7/8 13:34:4 ...
- Kendo UI开发教程(21): Kendo MVVM 数据绑定(十) Source
Source绑定可以把ViewModel的值和由Kendo模板定义的目标元素绑定,如果ViewModel的值发生变化,被绑定的目标元素也随之发生变化.模板由属性data-template指定,它的值为 ...