【HDU】1084 What Is Your Grade? (结构体 sort)
http://acm.hdu.edu.cn/showproblem.php?pid=1084
题目的关键:
1、Note, only 1 student will get the score 95 when 3 students have solved 4 problems.
If you can solve 4 problems, you can also get a high score 95 or 90 (you can get the former(前者) only when your rank is in the first half of all students who solve 4 problems).
获得了相同的grade(例如:4),只有前一半的学生才可以95,后一半的学生90。其他的分数也是,同理可得。
2、两个cmp函数,因为输出的结果是按照输入的顺序,逐一输出学生的分数,所以结构体中除了设置grade,time,score,还要再设置id,表示输入的顺序。
3、cnt[i] 表示 grade=i 的人数 。
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <string>
using namespace std;struct stu
{int id;int grade;int score;string time;
};stu s[10000];bool cmp1(stu a,stu b)
{if(a.grade != b.grade)return a.grade > b.grade;elsereturn a.time < b.time;
}bool cmp2(stu a,stu b)
{return a.id < b.id;
}int main ()
{int i,j,k,n;int cnt[8];while(scanf("%d",&n)!=EOF){if(n<=0)break;memset(cnt,0,sizeof(cnt));for(i=0;i<n;i++){cin >> s[i].grade >> s[i].time;s[i].id = i;cnt[s[i].grade]++;}sort(s,s+n,cmp1);k = 0;for(i=5;i>=0;i--){if(i==5){for(j=0;j<cnt[5];j++)s[k++].score = 100;}else if(i==0){for(j=0;j<cnt[0];j++)s[k++].score = 50;}else{for(j=0;j<cnt[i]/2;j++){if(i==4) s[k++].score = 95;else if(i==3) s[k++].score = 85;else if(i==2) s[k++].score = 75;else if(i==1) s[k++].score = 65;}for(j=cnt[i]/2;j<cnt[i];j++){if(i==4) s[k++].score = 90;else if(i==3) s[k++].score = 80;else if(i==2) s[k++].score = 70;else if(i==1) s[k++].score = 60; }}}sort(s,s+n,cmp2);for(i=0;i<n;i++)cout << s[i].score << endl;cout << endl;}return 0;
}
【HDU】1084 What Is Your Grade? (结构体 sort)相关推荐
- C - 开门人和关门人(结构体+sort)
C - 开门人和关门人(结构体+sort) Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- HDU 1873 看病要排队(结构体+优先队列)
题目: Problem Description 看病要排队这个是地球人都知道的常识. 不过经过细心的0068的观察,他发现了医院里排队还是有讲究的.0068所去的医院有三个医生(汗,这么少)同时看病. ...
- 【HDU】1862 EXCEL排序(结构体排序)
Problem Description Excel可以对一组纪录按任意指定列排序.现请你编写程序实现类似功能. Input 测试输入包含若干测试用例.每个测试用例的第1行包含两个整数 N (<= ...
- 结构体+sort方法
昨天做了一道简单但很麻烦的题,我只能想到结构体,并用了STL的sort方法解决了它.不过从中有许多细节问题. 题目: Problem Description Lcy wanted to choose ...
- HDU 1084 - What Is Your Grade?
给出第 i 个学生做完的题数和时间,给学生打分 排个序就行了吧 1 #include <iostream> 2 #include <cstdio> 3 #include < ...
- 【HDU】1305 Immediate Decodability(字典树:结构体数组,二维数组,链表/指针)
一.用的二维数组 #include <iostream> #include <cstring> #include <algorithm> using namespa ...
- 【HDU】1251统计难题 (字典树:二维数组,结构体数组,链表,map)
使用二维数组或者结构体数组都可以,但是在计数的时候有一点点小区别 一.结构体数组 #include <cstdio> #include <cstring> #include & ...
- hdu 幸福列车_优先队列+结构体
这道题是优先队列数组+结构体,题意很好懂,就是要注意最后记得把优先队列数组清空. #include <iostream> #include <string> #include ...
- Monkey and Banana HDU - 1069 [ 结构体排序+DP最长不上升子序列 ] 详细题解
题解目录 1.题目 2.题意 3.思路 4.代码 1.题目 A group of researchers are designing an experiment to test the IQ of a ...
最新文章
- 刘强东写在上市之际:京东要成为一家世界级企业 感慨吧
- boost::fibers模块实现异步调度的测试程序
- SAP Commerce的extensioninfo.xml
- robomaster裁判系统服务器,2018裁判系统调试组网完全攻略
- Redis面试复习大纲在手面试不慌,内含福利
- 单片机c语言检测压力值,基于单片机的压力检测系统设计论文.doc
- [转]工程师进阶之路(三)
- Mysql为什么多个大版本并行发布的个人理解
- filezilla server mysql_使用FileZilla Server轻松搭建个人FTP服务器
- PS中套索工具的使用
- 安装时遇到“已终止Autocad2006安装
- linux 获取文件名的后缀名,linux shell 取文件名后缀
- 虚幻引擎(UE4)场景漫游交互项目制作
- GEE系列:第 1 单元 Google 地球引擎简介
- 王者更新后苹果手机服务器维护,苹果手机不能更新王者荣耀怎么解决
- AU入门音频编辑基本认识
- iOS 判断当前键盘为九宫格
- vue中如何优雅实现爷孙组件的数据通信($attrs/$listeners)
- 「用户故事」竟然还可以这样写!?
- 分模块创建ssm项目
热门文章
- linux mpp集群环境,Linux环境下,DM8-MPP两节点集群搭建
- Jmeter 使用自定义变量
- MongoDB主动撤回SSPL的开源许可申请
- java实现用户登录注册功能(用集合框架来实现)
- 「深度」线下大数据正成为构建精准“用户画像”的最大助力
- 11.python并发入门(part9 多进程模块multiprocessing基本用法)
- 解决Office互操作错误检索COML类工厂中 CLSID为 {xxx}的组件时失败,原因是出现以下错误: 80070005...
- Eclipse 小插件
- Linux性能研究(总)
- Fckeditor PHP/ASP File Upload Vul