杭电1789Doing Homework again
来源:互联网 发布:网络诈骗要判几年 编辑:程序博客网 时间:2024/04/28 06:46
E - Doing Homework again
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uDescription
zichen 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 zichen 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 zichen 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<string.h>#include<algorithm>using namespace std;struct node{int d,s;}num[1010];bool cmp(node a,node b){if(a.s==b.s)return a.d<b.d;elsereturn a.s>b.s;}int main(){int t,n,i,j,sum;int visit[1010];scanf("%d",&t);while(t--){memset(visit,0,sizeof(visit));scanf("%d",&n);for(i=0;i<n;i++)scanf("%d",&num[i].d);for(i=0;i<n;i++)scanf("%d",&num[i].s);sort(num,num+n,cmp);sum=0; for(i=0;i<n;i++) { if(!visit[num[i].d]) visit[num[i].d]=1; else { for(j=num[i].d;j>0;j--) { if(!visit[j]) { visit[j]=1; break; }}if(j==0)sum+=num[i].s;}}printf("%d\n",sum);}return 0;}
0 0
- 杭电OJ 1789:Doing Homework again
- Doing Homework again(杭电1789)
- Doing Homework again 杭电 1789
- 杭电- 1789 Doing Homework again
- 杭电1789Doing Homework again
- 【杭电1789】Doing Homework again
- 【杭电 1789 】Doing Homework again
- 【杭电】[1789]Doing Homework again
- 杭电doing homework again
- 杭电1789 Doing Homework again(贪心)
- hdu杭电1789 Doing Homework again【优先队列+贪心】
- 【杭电1789】Doing Homework again贪心(还不太懂)
- 【1789 Doing Homework again】
- 【杭电oj】1789 - Doing Homework again(贪心,并查集)
- HDOJ 1789 Doing Homework again
- hdu 1789 doing homework again
- HDU 1789 Doing Homework again!
- hdu 1789 Doing Homework again
- 旋转90°动画
- 点击事件
- gradle中用的一些路径环境变量
- 磁盘类型由动态转换成基本
- Java垃圾回收机制
- 杭电1789Doing Homework again
- Ubuntu16.04虚拟机使用备注笔记
- 使用搬瓦工vps的一次经历
- 括号匹配
- 调用系统级别权限(比如修改时间)
- POJ 3617:Best Cow Line
- spring boot 加载本地静态资源文件路径配置
- CodeForces 348A
- SICP_Python版第二章:符号数据(简易求导系统)