Doing Homework again

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

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
 想到了是贪心,但一直以为时间可能会给的很大不敢直接按时间一个一个遍历,没想到最后真的这样A的,恶心的题目为啥不说清数据范围!
时间段是不会变化的,所以我们要充分利用好每一个时间段,即在这个时间段里让其获得最大的利益,由于彼此天数之间毫无关系所以可以贪心每一天。
用一个数组记录这一天是否被使用,将结构体排序,排序方式:先按照分数大小排序,如果分数一样,天数大的排在前面;
贪心方法:找出当前某门科目,从这门课的截止日期开始往前推只要遇到没标记的天就占用!
 
为何倒着日期找:
因为选择了一门科目后,对于后面的科目,截止日期可能在这个科目的截止日期的前面或者后面,后面的话没有影响,主要就是前面,如果这个科目占用了
前面的某个位置有可能导致这个科目的截止日期的浪费和后面某个科目无法进行!是不符合贪心规则的。

#include<bits/stdc++.h>
using namespace std;
int vis[10005];
struct node
{
int a,b;
}P[1005];
bool cmp(node A,node B)
{
if(A.b==B.b) return A.a>B.a;
else return A.b>B.b;
}
int main()
{
int t,n,m,i,j;
cin>>t;
while(t--){memset(vis,0,sizeof(vis));
cin>>n;int ans=0,sumn=0;
for(i=1;i<=n;++i) cin>>P[i].a;
for(i=1;i<=n;++i) cin>>P[i].b,sumn+=P[i].b;
sort(P+1,P+1+n,cmp);
//for(i=1;i<=n;++i) cout<<P[i].a<<" "<<P[i].b<<endl;
for(i=1;i<=n;++i){
for(j=P[i].a;j>=1;j--){
if(!vis[j]) {vis[j]=1;ans+=P[i].b;break;}
}
}//cout<<ans<<endl;
cout<<sumn-ans<<endl;
}
return 0;
}

最新文章

  1. 遇到bug怎么办
  2. copy(python中的引用,浅拷贝,深拷贝)
  3. 转:Directshow开发的一些例子
  4. Microsoft Fakes
  5. Spring总结——AOP、JDBC和事务的总结
  6. python学习笔记 - 初识socket
  7. poj3237 树链剖分 暴力
  8. JS实现Tab选项卡
  9. (六)6.8 Neurons Networks implements of PCA ZCA and whitening
  10. uva 11029
  11. jvm垃圾回收的时间问题
  12. Html.ActionLink 几种重载方式说明及例子
  13. 互斥锁Mutex与信号量Semaphore的区别
  14. 我的PHP之旅--SQL语句
  15. Deep Learning 学习随记(五)深度网络--续
  16. 在同个工程中使用 Swift 和 Objective-C(Swift 2.0更新)-b
  17. C#核编之一个简单的C#程序
  18. Node.js入门-Node.js 介绍
  19. Spark:聚类算法之LDA主题模型算法
  20. SQL Server2008附加数据库出现错误

热门文章

  1. jQuery 是javascript的一个库(常用插件、处理器)
  2. 为什么采用4~20mA的电流来传输模拟量?(转)
  3. python-kafka之理论篇
  4. Python Web学习笔记之并发编程IO模型
  5. Java 问卷调查
  6. spring与spring-data-redis整合redis
  7. Codeforces Round #429 (Div. 2)
  8. 论文笔记之:UNSUPERVISED REPRESENTATION LEARNING WITH DEEP CONVOLUTIONAL GENERATIVE ADVERSARIAL NETWORKS
  9. UVa 10905 孩子们的游戏
  10. UVa 10048 噪音恐惧症(Floyd)