HDU1789时间贪心
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
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.
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.
total reduced score, one line per test case.
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
3
5
#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时间贪心的更多相关文章
- [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 ...
- bzoj 1029: [JSOI2007]建筑抢修【贪心+堆】
第一想法是按照结束时间贪心,但是这样有反例 所以先按照t贪心,能选则选,把选的楼的持续时间放进大根堆里,当当前的楼不能选的时候如果当前的持续时间比大根堆里最大的要小,就用这个替换最大,这样总数不变但是 ...
- 贪心算法-过河问题 pojo1700
过桥问题: 黑夜,只有一只手电筒 A过桥需要1s B过桥需要3s C过桥需要5s D过桥需要8s E过桥需要12s 求最小过桥时间 贪心算法: 从最大的开始过去,最小的两个做为辅助. 假如左岸人数为2 ...
- codeforces#1165 F2. Microtransactions (hard version) (二分+贪心)
题目链接: https://codeforces.com/contest/1165/problem/F2 题意: 需要买$n$种物品,每种物品$k_i$个,每个物品需要两个硬币 每天获得一个硬币 有$ ...
- hdu26道动态规划总结
前言:我们队的dp一直是我在做,说不上做的很顺,有些可以做,有些不能做.到现在为止,做dp题目也有七八十道了,除了背包问题的题目我可以说有百分之七八十的把握ac的话,其他类型的dp,还真没有多大把握. ...
- BestCoder——59
http://bestcoder.hdu.edu.cn/contests/contest_show.php?cid=640 第一题:给一堆书的序列 每次操作只能将书从中间移到最上面 求最少移动多少次 ...
- BZOJ-USACO被虐记
bzoj上的usaco题目还是很好的(我被虐的很惨. 有必要总结整理一下. 1592: [Usaco2008 Feb]Making the Grade 路面修整 一开始没有想到离散化.然后离散化之后就 ...
- Codeforces551 C. GukiZ hates Boxes
二分答案 + 贪心 传送门:$>here<$ $Solution$ 二分时间+贪心验证.思维难度主要在验证上,然而坑人的点却在n的取值上.那么先来谈如何验证.在已知时间的条件下,能否用一种 ...
- luogu P2107 小Z的AK计划
最近复习了一下堆,于是去luogu上找一些简单题写一写 贪心的想,小z不会到一半以后回头去Ak,因为这样从时间上想肯定是不优的,他可以早在之间经过时就AK所以我们可以将所有机房按照横坐标排序可以想到的 ...
随机推荐
- bzoj3524 [Poi2014]Couriers/2223 [Coci 2009]PATULJCI
题目链接1 题目链接2 主席树模板题 两题有细节不同 #include<algorithm> #include<iostream> #include<cstdlib> ...
- python之路----钻石继承
钻石继承 继承顺序 class A(object): def test(self): print('from A') class B(A): def test(self): print('from B ...
- HTML 和 JavaScript 编写简单的 404 界面
编写简单的 404 界面,也可以用来做 500 报错界面,还会飘东西,特别好,蛮漂亮的! <!DOCTYPE html> <html> <head> <met ...
- Android 深入理解Activity 页面Intent跳转
- troubleshooting-windows 在 CDH集群环境读取 Hive 表 KrbException: Cannot locate default realm
KrbException: Cannot locate default realm 解决办法 1)拷贝需要组件的配置文件到项目中的 /resources/目录.如hadoop,目录/etc/hadoo ...
- awk之match函数
功能:match函数是用于个性化定制搜索模式. 例子: 文件内容: this is wang ,not wan that is chen, not che this is chen ,and wang ...
- android 实践项目四
android 实践项目四 本周主要是开发android baidumap实现公交的查询 1.权限的取得和对屏幕的支持 <uses-permission android:name="a ...
- 20165310 Java实验四 《Android程序设计》
20165310 实验四 <Android程序设计> 第24章:初识Android 任务一:改写res目录中的内容,Hello World后要显示自己的学号,自己学号前后一名同学的学号 首 ...
- poj Meteor Shower - 搜索
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16313 Accepted: 4291 Description Bess ...
- Problem F: 等式
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 104 Solved: 22[Submit][Status][Web Board] Descriptio ...