[Virtual Judge]SGU171:Sarov zones
来源:互联网 发布:在数据库储存的是 编辑:程序博客网 时间:2024/04/30 12:33
点击打开题目链接
171. Sarov zones
memory limit per test: 4096 KB
output: standard
This year K zones invited students from Sarov to participate their olympiads. i-th zone invited N[i] students, so N=N[1]+N[2]+...+N[K] totally students were invited. After the Sarov city olympiad, N students were selected, so now the olympiad authorities of Sarov have to decide, which students will participate which zone olympiad. Each student is characterized by his olympiad level and each zone is characterized by its zone level. If a student with olympiad level P participates zone with zone level Q, he will be invited to All-Russian olympiad if and only if P>Q.
Every student is also characterized by his "weight". The Sarov olympiad authorities want, that the All-Russian Olympiad will be participated by students with maximal summary weight. You are to help them. Write a program which will divide the students between zones. Keep in mind that exactly N[i] students can go to i-th zone.
Input
Output
Sample test(s)
Input
=====================================题目大意=====================================
参加俄罗斯的数学奥林匹克全国赛是需要先参加区域赛的,因此每年XXX州都会有许多学生为了参加全国赛而先去参加各地的区域赛。
今年共有K个区域举办比赛且编号为i的区域给予了XXX州N[i]名的参赛名额,因此XXX州今年将有N=N[1]+N[2]+...N[K]名学生参赛。
各区域赛和各学生都有自己的等级,当参赛学生等级大于他所参加的区域赛等级时,他将会受到全国赛的邀请。
此外还给出了N名参赛学生的体重,XXX州的当局者希望自己州能够参加全国赛的学生的总体重最大(真不知道他是怎么想的)。
请编程帮助他决定各参赛学生应该前往哪个区域参赛。
=====================================算法分析=====================================
贪心算法:
1、优先保证体重大的学生能够参加比自己等级低的区域赛以使其受到全国赛的邀请(满足题目所需)。
2、当体重相等时,不需要优先考虑等级低的学生(第3点的存在保证了等级高的学生不会占用与其体重相等的等级低的学生的
参赛机会)。
3、当前考虑的学生应该在等级比自己低的区域赛中选择等级最高的区域赛(为了给之后的学生提供更大的机会)。
4、若不存在比当前考虑的参赛学生等级低的区域赛,则应该让他参加当前可以参加的等级最高的区域赛(最大限度降低他所占
用的机会)。
========================================坑========================================
前言:“惨象,以使我目不忍视了,我还有什么话好说呢?”
根据题意:On the first line of input there is an only integer K (1<=K<=100).
写有代码:struct THEZONE { int ID,LV,N; } Zon[105];
提交结果:Runtime Error on test 8 X 14次。
修改代码:struct THEZONE { int ID,LV,N; } Zon[16005];
提交结果:Accepted。
此外还有:输出答案时每个数字后面都要跟空格,否则会Presentation Error。
查错依据:RE的错误原因是在对比了渊哥Runtime Error on test 8和Accepted的两份代码后得知的。
PE的错误原因是在做之前就看了freezhan学姐的博客得知的(也是一把辛酸的PE史)。
总结:本坑就是我CSUST集训队用血肉之躯填的,还不知道是不是填平了。。。
=======================================代码=======================================
#include<cstdio> #include<algorithm>using namespace std;int K,SumN,Ans[16005];struct THEZONE { int ID,LV,N; } Zon[16005];struct STUDENT { int ID,LV,W; } Stu[16005];bool cmpzon(THEZONE& Z1,THEZONE& Z2) {return (Z1.LV>Z2.LV);}bool cmpstu(STUDENT& S1,STUDENT& S2) {return (S1.W>S2.W);}bool ReadAndDealData() {if(scanf("%d",&K)==1){SumN=0;int i;for(i=0;i<K;++i){Zon[i].ID=i;scanf("%d",&Zon[i].N);SumN+=Zon[i].N;}for(i=0;i<K;++i){scanf("%d",&Zon[i].LV);}//按照等级降序排列区域sort(Zon,Zon+SumN,cmpzon); for(i=0;i<SumN;++i){Stu[i].ID=i;scanf("%d",&Stu[i].LV);}for(i=0;i<SumN;++i){scanf("%d",&Stu[i].W);}//按照重量降序排列学生(题解第1点和第2点)sort(Stu,Stu+SumN,cmpstu); return true;}return false;}int main(){while(ReadAndDealData()){int i;for(i=0;i<SumN;++i) {int maxlvloc=-1; int hopeloc=-1;//在等级比当前考虑的学生低的区域中选择等级最高的区域参赛(题解第2点) for(int j=0;j<K;++j) if(Zon[j].N) { //由于区域按照等级降序排列,所以maxlvloc即当前可以参加的等级最高的区域赛 if(maxlvloc==-1) { maxlvloc=j; } //由于区域按照等级降序排列,所以hopeloc即在等级比当前考虑的学生低的区域中等级最高的区域if(Stu[i].LV>Zon[j].LV) { hopeloc=j; break; }}//若不存在hopeloc则应该让当前考虑的学生参加maxlvloc(题解第4点) int loc=(hopeloc==-1?maxlvloc:hopeloc); --Zon[loc].N;Ans[Stu[i].ID]=Zon[loc].ID;}for(i=0;i<SumN;++i){printf("%d ",Ans[i]+1);}}return 0;}
- [Virtual Judge]SGU171:Sarov zones
- sgu171 Sarov zones 贪心
- sgu171:Sarov zones(贪心)
- SGU171:Sarov zones
- Sarov zones(SGU171,排序+模拟,)
- sgu 171. Sarov zones
- SGU 171 Sarov zones【贪心】
- SGU171
- SGU171
- [Virtual Judge]URAL1303:Minimal Coverage
- virtual judge配置和发布
- Virtual Judge Contest 1-E
- Virtual Judge Contest 1-F
- APOC-UVA virtual judge 开启
- virtual judge 本地部署方案
- Virtual Judge 注册用户教程
- 关于virtual judge的问题
- Private virtual networks for Solaris xVM and Zones with Crossbow
- Nginx
- 链表 小注意
- JAVA实现串口通信
- 串的模式匹配
- SMTP 与 ESMTP
- [Virtual Judge]SGU171:Sarov zones
- 消息队列RabbitMQ和ActiveMQ的生产者流量控制
- JSON(JavaScript Object Notation)
- Martin Fowler:持续集成(很有参考意义)
- binder机制底层驱动浅析
- ARM特殊生存之道及Cortex-A12架构解析
- 微信,微微之我见
- android中ImageView设置图片边框的方法
- eucalyptus 云平台搭建