国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

HDUoj 1789 Doing Homework again ( 貪心 好題

2019-11-11 06:38:07
字體:
供稿:網(wǎng)友

Doing Homework again

Time Limit: 1000/1000 MS (java/Others)    

Memory Limit: 32768/32768 K (Java/Others)

 

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. InputThe 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. OutputFor each test case, you should output the smallest total reduced score, one line per test case. Sample Input
333 3 310 5 131 3 16 2 371 4 6 4 2 4 33 2 1 7 6 5 4 Sample Output

0 3 5 

怎么才能提高一個(gè)智障的人的智商啊

/* 先按照分?jǐn)?shù)從大到小排序,分?jǐn)?shù)相等就按照天數(shù)從小到大排序*/ #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define N 1000000bool arr[N]; // 標(biāo)記數(shù)組,兩個(gè)值就夠了 struct node{ int a, b;}p[1000];bool cmp(node x, node y){ if(x.b != y.b) return x.b > y.b; //分?jǐn)?shù)不相等,從大到小排序 return x.a < y.a;}int main(){ int T, n; scanf("%d",&T); while(T--){ bool flag; memset(arr,false,sizeof(arr)); scanf("%d",&n); for(int i = 0;i < n; i++) scanf("%d",&p[i].a); for(int i = 0;i < n; i++) scanf("%d",&p[i].b); sort(p,p+n,cmp); int k = 0; for(int i = 0;i < n; i++){ flag = false; for(int j = p[i].a;j > 0; j--){ if(!arr[j]){ arr[j] = true; flag = true; break; } } if(!flag) k += p[i].b; } printf("%d/n",k); }return 0;}
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 新乡市| 洛扎县| 谷城县| 丹东市| 海丰县| 和林格尔县| 南宫市| 祁连县| 简阳市| 泰兴市| 湖北省| 崇义县| 南川市| 新野县| 沁源县| 辽阳县| 通道| 广河县| 台南县| 隆子县| 安乡县| 常熟市| 巫山县| 邯郸市| 东乡县| 屏东市| 长葛市| 永德县| 桂东县| 安化县| 尉氏县| 廉江市| 分宜县| 古蔺县| 宁国市| 班玛县| 化隆| 衡阳县| 夏津县| 塘沽区| 庆元县|