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 ...
随机推荐
- hdu 1102 Constructing Roads(最小生成树 Prim)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1102 Problem Description There are N villages, which ...
- BZOJ 1486: [HNOI2009]最小圈( 二分答案 + dfs判负圈 )
二分答案m, 然后全部边权减掉m, 假如存在负圈, 那么说明有平均值更小的圈存在. 负圈用dfs判断. ------------------------------------------------ ...
- Bootstrap3学习笔记
Bootstrap3简单介绍----专题1 声明:本文章是给初学bootstrap3的同学添加记忆的, 一定有非常多欠缺和不完好的地方, 希望能帮助到大家, 也希望能让很多其它的人了解boostrap ...
- 《Swift Programming Language 》——Swift中怎样使用继承(Inheritance)
一个类能够继承(inherit)还有一个类的方法(methods),属性(property)和其他特性.当一个类继承其他类时,继承类叫子类(subclass),被继承类叫超类(或父类,supercla ...
- Caffe —— Deep learning in Practice
因工作交接须要. 要将caffe用法及总体结构描写叙述清楚. 鉴于也有同学问过我相关内容, 决定在本文中写个简单的tutorial, 方便大家參考. 本文简单的讲几个事情: Caffe能做什么? 为什 ...
- HTML+CSS+JS - 5秒钟之后跳转页面
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.c ...
- CSS3实现时间轴效果
原文:CSS3实现时间轴效果 最近打开电脑就能看到极客学院什么新用户vip免费一个月,就进去看看咯,这里就不说它的课程怎么滴了,里面实战路径图页面看到了这个效果: 有点像时间轴的赶脚,而且每一块鼠标悬 ...
- Incompatible namespaceIDs或连接被对端重置异常的解决
Workaround 1: Start from scratch I can testify that the following steps solve this error, but the si ...
- FOJ 1607 Greedy division 数学题
题目地址: http://acm.fzu.edu.cn/problem.php?pid=1607 给定一个n,将n平均分成m份,问有几种方法,每种方法中找出最大的数.思路:就是求n的因子数.先将每个数 ...
- MongoDB学习笔记(二) 通过samus驱动实现基本数据操作
传统的关系数据库一般由数据库(database).表(table).记录(record)三个层次概念组成,MongoDB是由(database).集合(collection).文档对象(documen ...