P1093 [NOIP2007 普及组] 奖学金(模拟排序)

简介: P1093 [NOIP2007 普及组] 奖学金(模拟排序)

Description of the topic



A primary school recently received a grant to offer scholarships to top five students with outstanding academic performance. At the end of the term, each student has three subjects: Chinese, Maths, and English. First according to the total score from high to low sort, if the total score of two students is the same, and then according to the language score from high to low sort, if the total score of two students and language scores are the same, then the provisions of the small number of students in front, so that each student's ranking is the only certainty.


Task: The total score is calculated based on the results of the 3 courses entered, then sorted by the above rules, and finally output the top five students' school numbers and total scores in the ranking order. Note that in the top 5 students, each person's scholarship is different, so you must strictly follow the above rules. For example, in a correct answer, if the output data for the first two rows (two numbers per row: school number, total score) is:


77 279279

55 279279


The meaning of these two rows of data is: the two students with the highest total score are 77th and 55th in turn. The total scores of the two students were 279279 (the total score was equal to the sum of the three subjects of input, mathematics and English), but the students with the number 77 had higher scores in Chinese. If your top two output data is:


55 279279

77 279279


Error handling by output, no score can be scored.


Enter the format



A total of n1 lines.


The 11th behavior is a positive integer n (sle 300)n (≤300), indicating the number of students participating in the selection.


On lines 22 to n1n1, each row has 33 numbers separated by spaces, each between 00 and 100100. The 33 numbers in line jj indicate, in turn, the scores of students with the number j-1j-1 in Chinese, math, and English. Each student's number is numbered 1 to n1 n in the order in which they are entered (exactly the line number minus 11 of the input data).


The data given are correct and need not be tested.


Thanks to Huang Xiao U Drinks for correcting the input format


The output format



There are 5 rows, each of which is a positive integer separated by spaces, representing the number and total score of the first 55 students in turn.


A sample of the input and output



Enter #1 copy


1. 6
2. 90 67 80
3. 87 66 91
4. 78 89 91
5. 88 99 77
6. 67 89 64
7. 78 89 98


Output #1 copy

1. 6 265
2. 4 264
3. 3 258
4. 2 244
5. 1 237
6.


Enter #2 copy

1. 8
2. 80 89 89
3. 88 98 78
4. 90 67 80
5. 87 66 91
6. 78 89 91
7. 88 99 77
8. 67 89 64
9. 78 89 98


Output #2 copy

1. 8 265
2. 2 264
3. 6 264
4. 1 258
5. 5 258


题意分析就是模拟排序判断;

#include<bits/stdc++.h>
const int maxn=1e6+7;
using namespace std;
struct node
{
  int sum;
  int x,y,z;
  int num;
}s[maxn];
bool cmp(node a,node b)
{
  if(a.sum>b.sum)return 1;
  else if(a.sum<b.sum)return 0;
  else
  {
    if(a.x>b.x)return 1;
    else if(a.x<b.x) return 0;
    else
    {
      if(a.num<b.num)return 1;
      else return 0; 
    }
  }
}
int main()
{
  int t;
  cin>>t;
  for(int i=1;i<=t;i++)
  {
    s[i].num=i;
    cin>>s[i].x>>s[i].y>>s[i].z;
    s[i].sum=s[i].x+s[i].y+s[i].z;
  }
  sort(s+1,s+1+t,cmp);
  for(int i=1;i<=5;i++)
  {
    cout<<s[i].num<<' '<<s[i].sum<<endl; 
  }
}
相关文章
【2001NOIP普及组】T3. 求先序排列 试题解析
【2001NOIP普及组】T3. 求先序排列 试题解析
|
7月前
|
存储
【洛谷 P2141】[NOIP2014 普及组] 珠心算测验 题解(集合+多重循环)
**NOIP2014普及组的珠心算测验题要求参赛者找出给定集合中多少个数可表示为其他两个不同数的和。输入含n个正整数,输出满足条件的数的个数。样例输入4个数,输出2,因1+2=3且1+3=4。代码利用集合存储和,遍历所有数对组合,当找到匹配和时插入集合,最后输出集合大小。注意数据规模为n≤100,数不超过10,000。**
152 0
|
7月前
|
C++
【洛谷 P1047】[NOIP2005 普及组] 校门外的树 题解(位集合)
**NOIP2005普及组问题:**给定长度为$l$的马路,上面等距种植着树,需移除位于建造地铁区域的树。输入包含马路长度和区域数,以及各区域起止点,输出移树后剩余树的数量。样例输入:$l=500$, $m=3$,输出:$298$。$20\%$数据无区域重合,$1 \leq l \leq 10^4$,$1 \leq m \leq 100$。解决方案利用位集合(bitset)表示树的状态,遍历区域将树设为0,最后统计1的数量。AC代码使用C++实现。
36 0
|
7月前
【洛谷 P1046】[NOIP2005 普及组] 陶陶摘苹果 题解(比较)
`NOIP2005普及组`编程题《陶陶摘苹果》:陶陶有10个高度在100-200cm的苹果要摘,手触及最大高度+30cm板凳后能摘到的苹果数。输入10个苹果高度和她的最大触及高度,输出可摘苹果数。样例输入:10个苹果高度和110cm触及高度,输出5,表示能摘5个。代码通过逐个比较苹果高度实现统计。
84 0
|
7月前
|
C++
【洛谷 P2670】[NOIP2015 普及组] 扫雷游戏 题解(模拟)
**扫雷游戏NOIP2015普及组题目:**在$n\times m$的雷区,玩家需避开地雷格(*),翻开非地雷格(?)显示周围地雷数。给定雷区布局,输出每个格子的地雷数或保持*不变。输入含雷区大小及布局,输出相应格式。样例输入/输出展示具体规则。100%数据$n,m\leq100$。程序思路:检查邻接8格,AC代码用C++实现。
51 0
【2012NOIP普及组】T1. 质因数分解 试题解析
【2012NOIP普及组】T1. 质因数分解 试题解析
|
机器学习/深度学习
P2141 [NOIP2014 普及组] 珠心算测验
P2141 [NOIP2014 普及组] 珠心算测验
|
机器学习/深度学习
洛谷【3】P1014 [NOIP1999 普及组] Cantor 表
洛谷【3】P1014 [NOIP1999 普及组] Cantor 表
|
Java C语言
P1014 [NOIP1999 普及组] Cantor 表(java实现)---找规律
P1014 [NOIP1999 普及组] Cantor 表(java实现)---找规律