hdu 1789 Doing Homework again(簡單貪心)
Doing Homework again
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5098 Accepted Submission(s): 3004
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.
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
題目大意:給你n件事情,然後給這n件事情的截止日期和如果不在截至日期之前完成會被扣掉的分數,問你被扣分數的最小值。
解題思路:感覺貪心靠得住,首先對事情的分數排個序,分數大的儘量先排,如果當天排了就往前面排。我自己在下面證明了覺得沒問題。實在排不進去就扣分。
題目地址:Doing Homework again
AC程式碼:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int visi[1005];
struct node
{
int time;
int score;
}nod[1005];
int cmp(node a,node b)
{
if(a.score>b.score) return 1;
if(a.score==b.score&&a.time>b.time) return 1;
return 0;
}
int main()
{
int tes,n;
cin>>tes;
int i,j;
int res;
while(tes--)
{
res=0;
cin>>n;
for(i=0;i<n;i++)
scanf("%d",&nod[i].time);
for(i=0;i<n;i++)
scanf("%d",&nod[i].score);
sort(nod,nod+n,cmp);
memset(visi,0,sizeof(visi));
for(i=0;i<n;i++)
{
int flag=0;
j=nod[i].time;
while(j)
{
if(!visi[j])
{
visi[j]=1;
flag=1;
break;
}
j--;
}
if(!flag)
res+=nod[i].score;
}
cout<<res<<endl;
}
return 0;
}
/*
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
*/
相關文章
- HDU 4550卡片遊戲(貪心)遊戲
- 貪心(入門簡單題)
- HDU 5813 Elegant Construction (貪心)Struct
- hdu4268 multiset應用 貪心
- hdu5380 貪心+雙端佇列佇列
- HDU1788Chinese remainder theorem again(中國剩餘定理 簡單)REMAI
- [kuangbin帶你飛]專題十二 基礎DP1 D - Doing Homework HDU - 1074
- hdu 3177Crixalis's Equipment(貪心)UI
- hdu4313 貪心並查集 || 樹形dp並查集
- HDU5630 Hiking(貪心+優先佇列)佇列
- 貪心
- HDU 4252A Famous City(弱資料可以使用貪心)
- HDU 5303 Delicious Apples (貪心 列舉 好題)APP
- 反悔貪心
- Supermarket(貪心)
- HDU 1848 Fibonacci again and again(SG函式)AI函式
- HDU 5135 Little Zu Chongzhi's Triangles(狀壓dp或者貪心)
- HDU - 1702 - ACboy needs your help again!AI
- HDU 1848 Fibonacci again and again (尼姆博弈+sg函式)AI函式
- POJ 2718簡單列舉貪心演算法(好久沒寫程式碼了。。)演算法
- 貪心模式記錄模式
- 貪心、構造合集
- 貪心演算法演算法
- 反悔貪心雜題
- UVA11292 HDU1902 POJ3646 The Dragon of Loowater【貪心】Go
- LightOJ 1038 Race to 1 Again (簡單期望)AI
- HDU 4770 Lights Against Dudely(列舉所有狀態 當然壯壓dp會很簡單)AI
- Least Cost Bracket Sequence(貪心)ASTRacket
- 牛客 tokitsukaze and Soldier 貪心
- 24/03/20 貪心(一)
- 7.5 - 貪心篇完結
- 貪心 做題筆記筆記
- 「貪心」做題記錄
- hdu 3665Seaside(簡單floyd)IDE
- 學一下貪心演算法-學一下貪心演算法演算法
- 貪心演算法(貪婪演算法,greedy algorithm)演算法Go
- 淺談貪心與動歸
- 貪心演算法Dijkstra演算法