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;
}

HDU1789时间贪心的更多相关文章

  1. [ACM_水题] UVA 11729 Commando War [不可同时交代任务 可同时执行 最短完成全部时间 贪心]

    There is a war and it doesn't look very promising for your country. Now it's time to act. You have a ...

  2. bzoj 1029: [JSOI2007]建筑抢修【贪心+堆】

    第一想法是按照结束时间贪心,但是这样有反例 所以先按照t贪心,能选则选,把选的楼的持续时间放进大根堆里,当当前的楼不能选的时候如果当前的持续时间比大根堆里最大的要小,就用这个替换最大,这样总数不变但是 ...

  3. 贪心算法-过河问题 pojo1700

    过桥问题: 黑夜,只有一只手电筒 A过桥需要1s B过桥需要3s C过桥需要5s D过桥需要8s E过桥需要12s 求最小过桥时间 贪心算法: 从最大的开始过去,最小的两个做为辅助. 假如左岸人数为2 ...

  4. codeforces#1165 F2. Microtransactions (hard version) (二分+贪心)

    题目链接: https://codeforces.com/contest/1165/problem/F2 题意: 需要买$n$种物品,每种物品$k_i$个,每个物品需要两个硬币 每天获得一个硬币 有$ ...

  5. hdu26道动态规划总结

    前言:我们队的dp一直是我在做,说不上做的很顺,有些可以做,有些不能做.到现在为止,做dp题目也有七八十道了,除了背包问题的题目我可以说有百分之七八十的把握ac的话,其他类型的dp,还真没有多大把握. ...

  6. BestCoder——59

    http://bestcoder.hdu.edu.cn/contests/contest_show.php?cid=640 第一题:给一堆书的序列 每次操作只能将书从中间移到最上面 求最少移动多少次 ...

  7. BZOJ-USACO被虐记

    bzoj上的usaco题目还是很好的(我被虐的很惨. 有必要总结整理一下. 1592: [Usaco2008 Feb]Making the Grade 路面修整 一开始没有想到离散化.然后离散化之后就 ...

  8. Codeforces551 C. GukiZ hates Boxes

    二分答案 + 贪心 传送门:$>here<$ $Solution$ 二分时间+贪心验证.思维难度主要在验证上,然而坑人的点却在n的取值上.那么先来谈如何验证.在已知时间的条件下,能否用一种 ...

  9. luogu P2107 小Z的AK计划

    最近复习了一下堆,于是去luogu上找一些简单题写一写 贪心的想,小z不会到一半以后回头去Ak,因为这样从时间上想肯定是不优的,他可以早在之间经过时就AK所以我们可以将所有机房按照横坐标排序可以想到的 ...

随机推荐

  1. bzoj3524 [Poi2014]Couriers/2223 [Coci 2009]PATULJCI

    题目链接1 题目链接2 主席树模板题 两题有细节不同 #include<algorithm> #include<iostream> #include<cstdlib> ...

  2. python之路----钻石继承

    钻石继承 继承顺序 class A(object): def test(self): print('from A') class B(A): def test(self): print('from B ...

  3. HTML 和 JavaScript 编写简单的 404 界面

    编写简单的 404 界面,也可以用来做 500 报错界面,还会飘东西,特别好,蛮漂亮的! <!DOCTYPE html> <html> <head> <met ...

  4. Android 深入理解Activity 页面Intent跳转

  5. troubleshooting-windows 在 CDH集群环境读取 Hive 表 KrbException: Cannot locate default realm

    KrbException: Cannot locate default realm 解决办法 1)拷贝需要组件的配置文件到项目中的 /resources/目录.如hadoop,目录/etc/hadoo ...

  6. awk之match函数

    功能:match函数是用于个性化定制搜索模式. 例子: 文件内容: this is wang ,not wan that is chen, not che this is chen ,and wang ...

  7. android 实践项目四

    android 实践项目四 本周主要是开发android baidumap实现公交的查询 1.权限的取得和对屏幕的支持 <uses-permission android:name="a ...

  8. 20165310 Java实验四 《Android程序设计》

    20165310 实验四 <Android程序设计> 第24章:初识Android 任务一:改写res目录中的内容,Hello World后要显示自己的学号,自己学号前后一名同学的学号 首 ...

  9. poj Meteor Shower - 搜索

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16313   Accepted: 4291 Description Bess ...

  10. Problem F: 等式

    Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 104  Solved: 22[Submit][Status][Web Board] Descriptio ...