【HDU 5499】+ sort 结构体排序
来源:互联网 发布:java nanotime 单位 编辑:程序博客网 时间:2024/06/06 01:51
Problem Description
The Annual National Olympic of Information(NOI) will be held.The province of Shandong hold a Select(which we call SDOI for short) to choose some people to go to the NOI. n(n≤100) people comes to the Select and there is m(m≤50) people who can go to the NOI.
According to the tradition and regulation.There were two rounds of the SDOI, they are so called “Round 1” and “Round 2”, the full marks of each round is 300.
All the n people take part in Round1 and Round2, now the original mark of every person is known. The rule of SDOI of ranking gets to the “standard mark”. For each round there is a highest original mark,let’s assume that is x.(it is promised that not all person in one round is 0,in another way,x>0). So for this round,everyone’s final mark equals to his/her original mark∗(300/x).
After we got everyone’s final mark in both round.We calculate the Ultimate mark of everyone as 0.3∗round1′s final mark + 0.7∗round2′s final mark.It is so great that there were no two persons who have the same Ultimate mark.
After we got everyone’s Ultimate mark.We choose the persons as followed:
To encourage girls to take part in the Olympic of Information.In each province,there has to be a girl in its teams.
- If there is no girls take part in SDOI,The boys with the rank of first m enter the team.
- If there is girls, then the girl who had the highest score(compared with other girls) enter the team,and other(boys and other girls) m-1 people with the highest mark enter the team.
Just now all the examination had been finished.Please write a program, according to the input information of every people(Name, Sex ,The original mark of Round1 and Round2),Output the List of who can enter the team with their Ultimate mark decreasing.
Input
There is an integer T(T≤100) in the first line for the number of testcases and followed T testcases.
For each testcase, there are two integers n and m in the first line(n≥m), standing for the number of people take part in SDOI and the allowance of the team.Followed with n lines,each line is an information of a person. Name(A string with length less than 20,only contain numbers and English letters),Sex(male or female),the Original mark of Round1 and Round2 (both equal to or less than 300) separated with a space.
Output
For each testcase, output “The member list of Shandong team is as follows:” without Quotation marks.
Followed m lines,every line is the name of the team with their Ultimate mark decreasing.
Sample Input
2
10 8
dxy male 230 225
davidwang male 218 235
evensgn male 150 175
tpkuangmo female 34 21
guncuye male 5 15
faebdc male 245 250
lavender female 220 216
qmqmqm male 250 245
davidlee male 240 160
dxymeizi female 205 190
2 1
dxy male 300 300
dxymeizi female 0 0
Sample Output
The member list of Shandong team is as follows:
faebdc
qmqmqm
davidwang
dxy
lavender
dxymeizi
davidlee
evensgn
The member list of Shandong team is as follows:
dxymeizi
Hint
For the first testcase: the highest mark of Round1 if 250,so every one’s mark times(300/250)=1.2, it’s same to Round2.
The Final of The Ultimate score is as followed
faebdc 298.20
qmqmqm 295.80
davidwang 275.88
dxy 271.80
lavender 260.64
dxymeizi 233.40
davidlee 220.80
evensgn 201.00
tpkuangmo 29.88
guncuye 14.40
For the second testcase,There is a girl and the girl with the highest mark dxymeizi enter the team, dxy who with the highest mark,poorly,can not enter the team.
附上自己以前AC的代码和现在AC的代码~~不得不说现在没有之前的那种较真劲和刚开始的热血了~~~
现在的代码 :
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;struct node{ double val,a,b; char M[25]; int X;}st[110];char SX[8];bool cmp(node i,node j){ return i.val > j.val;}int main(){ int T,i,kl,pl,n,m; double ax,bx; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); kl = pl = 0; ax = bx = 0.0; for(i = 1 ; i <= n; i ++){ scanf("%s %s %lf %lf",st[i].M,SX,&st[i].a,&st[i].b); ax = max(ax,st[i].a); bx = max(bx,st[i].b); st[i].X = strlen(SX); if(st[i].X > 4 ) pl = 1; } ax = 300.0 / ax; bx = 300.0 / bx; for(i = 1 ; i <= n ; i++) st[i].val = 0.3 * ax * st[i].a + 0.7 * bx * st[i].b; sort(st + 1, st + 1 + n,cmp); for(i = 1 ; i <= m ; i++) if(st[i].X > 4) kl = 1; printf("The member list of Shandong team is as follows:\n"); if(kl || !pl){ for(i = 1 ; i <= m ; i++) printf("%s\n",st[i].M); } else{ for(i = m + 1 ; i <= n ; i++) if(st[i].X > 4){ pl = i; break; } for(i = 1 ; i < m ; i++) printf("%s\n",st[i].M); printf("%s\n",st[pl].M); } } return 0;}
之前的代码 :
#include<cstdio>#include<algorithm>#include<cstring>using namespace std;struct node{ double a,b,z; char sn[21],sx[7]; }st[1000000+11];bool cmp(node i,node j){ return i.a>j.a;}bool ctp(node i,node j){ return i.b>j.b;}bool czp(node i, node j){ return i.z>j.z;}int main(){ int t; int k,l,o; scanf("%d",&t); while(t--) { int n,m,i,f; double p,q; scanf("%d%d",&n,&m); for(i=0;i<n;i++) { scanf("%s%s%lf%lf",st[i].sn,st[i].sx,&st[i].a,&st[i].b); } sort(st,st+n,cmp); p=st[0].a; sort(st,st+n,ctp); q=st[0].b; for(i=0;i<n;i++) { st[i].a=st[i].a/p*300; st[i].b=st[i].b/q*300; st[i].z=st[i].a*0.3+st[i].b*0.7; } sort(st,st+n,czp); k=0;l=0; for(i=0;i<m;i++) { if(strlen(st[i].sx)>4) k=1; } if(k!=1) { for(i=m;i<n;i++) if(strlen(st[i].sx)>4) { l=1; o=i; break; } if(l!=1) { printf("The member list of Shandong team is as follows:\n"); for(i=0;i<m;i++) printf("%s\n",st[i].sn); } else { printf("The member list of Shandong team is as follows:\n"); for(i=0;i<m-1;i++) printf("%s\n",st[i].sn); printf("%s\n",st[o].sn); } } else { printf("The member list of Shandong team is as follows:\n"); for(i=0;i<m;i++) printf("%s\n",st[i].sn); } } return 0;}
- 【HDU 5499】+ sort 结构体排序
- 结构体排序,sort排序,c++sort
- HDU--杭电--3293--sort--结构体排序
- 【hdu 1862】EXCEL排序 (sort &结构体)
- HDU 5499 SDOI(sort+结构体)
- HDU 5499 SDOI(sort+结构体)
- c++ sort()结构体排序
- sort 对结构体排序
- qsort sort 结构体排序
- 结构体sort快速排序
- sort对结构体排序
- 【结构体】【sort】多重排序
- 结构体排序,使用sort
- EXCEL排序(sort结构体排序)
- usaco 1.3 Mixing Milk (结构体排序 qsort) and hdu 2020(sort)
- hdu 1263 水果 sort对结构体中字符串二级排序
- HDU-1234开门人和关门人(sort函数对结构体的排序)
- 【HDU 1069】Monkey and Banana(dp+sort结构体排序)
- 设计模式之装饰者模式
- Pku oj 1207 The 3n + 1 problem(模拟)
- HDU 5884 - Sort
- 【Leetcode】Convert a Number to Hexadecima
- 继承的基础知识1——有关继承的基本概念
- 【HDU 5499】+ sort 结构体排序
- JVM 垃圾回收机制主要原理
- PowerDesigner导出表到word
- 有关makefile
- poj1845Sumdiv+约数和定理
- C Primer Plus学习 六 基本运算符
- iOS开发笔记之五十一——跳转到app store应用下载评分
- Spring in action--Part1-Core Spring
- 乱码之MyEclipse控制台