ACM-HDU1789 Doing Homework again(又是贪心- -、)
来源:互联网 发布:网络教育学籍注册条件 编辑:程序博客网 时间:2024/06/05 08:34
D - Doing Homework again
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uDescription
Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every teacher gives him a deadline of handing in the homework. If Ignatius hands in the homework after the deadline, the teacher will reduce his score of the final test. And now we assume that doing everyone homework always takes one day. So Ignatius wants you to help him to arrange the order of doing homework to minimize the reduced score.
Input
The input contains several test cases. The first line of the input is a single integer T that is the number of test cases. T test cases follow.
Each test case start with a positive integer N(1<=N<=1000) which indicate the number of homework.. Then 2 lines follow. The first line contains N integers that indicate the deadlines of the subjects, and the next line contains N integers that indicate the reduced scores.
Each test case start with a positive integer N(1<=N<=1000) which indicate the number of homework.. Then 2 lines follow. The first line contains N integers that indicate the deadlines of the subjects, and the next line contains N integers that indicate the reduced scores.
Output
For each test case, you should output the smallest total reduced score, one line per test case.
Sample Input
333 3 310 5 131 3 16 2 371 4 6 4 2 4 33 2 1 7 6 5 4
Sample Output
035
#include<stdio.h>#include<algorithm>#include<string.h>using namespace std;struct e{ int day; int score;}a[1005];int cmp(e a,e b){ if(a.score==b.score) return a.day<b.day; else return a.score>b.score;}int main(){ int i,q,w,j,n,p,u,o; scanf("%d",&n); while(n--) { int q,b[1005]; memset(b,0,sizeof(b)); scanf("%d",&q);j=0; for(i=0;i<q;i++) scanf("%d",&a[i].day); for(i=0;i<q;i++) {scanf("%d",&a[i].score);j+=a[i].score;} sort(a,a+q,cmp); i=0;w=0;for(i=0;i<q;i++) { o=a[i].day; if(b[o]==0) b[o]=a[i].score; else for(u=o;u>0;u--) if(b[u]==0) {b[u]=a[i].score;break;} else ; } for(i=1;i<=1000;i++) w+=b[i]; printf("%d\n",j-w); }return 0;}第一次用天数排序,到第三个测试数据就有问题,用分数排序还是有问题,那么到底用啥!?好吧,最后是用分数排序,策略比排序重要,其实策略是变相的排序,按照题意,保留分数最大的天数,当分数依旧很大的天数和它重复,就往前排一天。比如第四天有7分和6分,就把7分放在第四天,6分放在第三天,第三天如果也有了就重复。做到最后都对了,却又WA无数次- -、只能说数据太狠了,我需要让b来记录第几天是多少分,但是如果天数太大,那么我需要找到的就多了,最后一个for循环于是到了1000.也算AC了。
0 1
- ACM-HDU1789 Doing Homework again(又是贪心- -、)
- HDU1789 Doing Homework again 贪心
- 【贪心】 hdu1789 Doing Homework again
- hdu1789 Doing Homework again (贪心)
- HDU1789 Doing Homework again 【贪心】
- hdu1789(Doing Homework again 贪心)
- [HDU1789]Doing Homework again[贪心]
- HDU1789:Doing Homework again 【贪心】
- HDU1789 Doing Homework again(贪心)
- HDU1789 doing homework again(贪心)
- HDU1789 Doing Homework again 贪心
- hdu1789 Doing Homework again (贪心)
- HDU1789 Doing Homework again(贪心)
- HDU1789-Doing Homework again-贪心
- Doing Homework again(hdu1789,贪心)
- hdu1789 sdut2076 Doing Homework again(贪心)
- HDU1789--Doing Homework again(贪心)
- hdu1789 Doing Homework again(贪心)
- jquery 传参
- poj_3349 哈希
- Linux shell编程简介
- HDU-IMNU集训六:叠筐-纯模拟(注意技巧)
- 调用系统方法打电话
- ACM-HDU1789 Doing Homework again(又是贪心- -、)
- Codeforces Round #287 (Div. 2) D. The Maths Lecture (数位dp)
- 自己写的年会抽奖软件免费版带后门作弊,共享出来给大家(更新至V1.3)——转自哈尔滨健康生活网
- sqlite3-基础教程
- CF 287 div2 A
- uva11888 - Abnormal 89's Manacher回文子串
- uva 725 Division(暴力枚举)
- hdu 1418 欧拉定理
- excel 条件判断