注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

告别迷茫

梦想与现实的差距,就是我们生活的意义。因为我们有差距,我们才会一直积累,在努力。

 
 
 

日志

 
 

HDU 1789 Doing Homework again  

2014-03-08 14:03:38|  分类: 贪心算法 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

Doing Homework again

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5341    Accepted Submission(s): 3158


Problem Description
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.
 

Output
For each test case, you should output the smallest total reduced score, one line per test case.
 

Sample Input
3 3 3 3 3 10 5 1 3 1 3 1 6 2 3 7 1 4 6 4 2 4 3 3 2 1 7 6 5 4
 

Sample Output
0 3 5
 

Author
lcy
 

Source
#include<iostream>
#include<algorithm>
#include <cstring>
using namespace std;
struct sore
{
int time;
int total;
}s[10001];
int cmp(const sore a,const sore b)//扣分越多的越靠前//扣分相同的时候,time越早的越靠前
{
if(a.total!=b.total)
return a.total>b.total;
return a.time<b.time;
}
int  visit[2010];//如果当天没用过,值为0;否则为1
int main()
{
int N,M,sum,day;
cin>>N;
while(N--)
{
sum=0;
cin>>M;
memset(visit,0,sizeof(visit));
for(int i=0;i<M;i++)
{
cin>>s[i].time;
}
for(int k=0;k<M;k++)
{
cin>>s[k].total;
}
sort(s,s+M,cmp);
for(int j=0;j<M;j++)
{
day=s[j].time;
while(day)
{
if(visit[day]==0)
{
visit[day]=1;
break;
}
day--;
}
if(day==0)//如果day=0,表明从time往前的每一天都被占用了,这门课完不成
{
sum+=s[j].total;
}
}
cout<<sum<<endl;


}
return 0;
}
  评论这张
 
阅读(2)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017