Doing Homework again

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

题目描述:t组数据,输入n,然后n个数代表要交作业的时间,后边n个数表示作业的分值,做完不扣分,在该交时没交上,要扣对应的分,求最优方案下的扣分。

      先按照分数排序,肯定先安排好分大的,然后再安排分小的。

#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std; struct node { //t代表时间,a代表分值
int t, a;
}s[1010]; int T, n, cnt;
bool used[1010]; //标记某个时间段是否用了
bool cmp(node x, node y) {
if (x.a == y.a)
return x.t<y.t;
else
return x.a>y.a;
} int main() {
cin >> T;
while (T--) {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> s[i].t;
for (int i = 1; i <= n; i++)
cin >> s[i].a; sort(s + 1, s + n + 1, cmp);
memset(used, false, sizeof(used)); //不要忘了初始化
cnt = 0; for (int i = 1; i <= n; i++) { //枚举,先把分大的安排好
int ans = 1;
for (int j = s[i].t; j>0; j--) { //如果分大的当前时间已经被安排了,那就向前找
if (!used[j]) {
used[j] = true;
ans = 0;
break;
}
}
if (ans)cnt += s[i].a; //找不到,就只能加上
} cout << cnt << "\n";
}
return 0;
}

Doing Homework again:贪心+结构体sort的更多相关文章

  1. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  2. Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final) C. The Delivery Dilemma (贪心,结构体排序)

    题意:你要买\(n\)份午饭,你可以选择自己去买,或者叫外卖,每份午饭\(i\)自己去买需要消耗时间\(b_i\),叫外卖需要\(a_i\),外卖可以同时送,自己只能买完一份后回家再去买下一份,问最少 ...

  3. c++中结构体sort()排序

    //添加函数头 #include <algorithm> //定义结构体Yoy typedef struct { double totalprice;         //总价 doubl ...

  4. HDOJ 1051. Wooden Sticks 贪心 结构体排序

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  5. 洛谷 P1056 排座椅【贪心/结构体排序】

    题目描述 上课的时候总会有一些同学和前后左右的人交头接耳,这是令小学班主任十分头疼的一件事情.不过,班主任小雪发现了一些有趣的现象,当同学们的座次确定下来之后,只有有限的D对同学上课时会交头接耳.同学 ...

  6. 洛谷 P1478 陶陶摘苹果(升级版)【贪心/结构体排序/可用01背包待补】

    [链接]:https://www.luogu.org/problemnew/show/P1478 题目描述 又是一年秋季时,陶陶家的苹果树结了n个果子.陶陶又跑去摘苹果,这次她有一个a公分的椅子.当他 ...

  7. HDU——1009FatMouse' Trade(贪心+结构体+排序)

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. Codeforces Global Round 11 B. Chess Cheater (贪心,结构体排序)

    题意:你和朋友进行了\(n\)个回合的棋艺切磋,没有平局,每次要么输要么赢,每次赢可以得一分,假如前一局也赢了,那么可以得两分,结果已成定局,但是你确可以作弊,最多修改\(k\)个回合的结果,问你作弊 ...

  9. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

随机推荐

  1. 【洛谷】【线段树】P3353 在你窗外闪耀的星星

    [题目描述:] /* 飞逝的的时光不会模糊我对你的记忆.难以相信从我第一次见到你以来已经过去了3年.我仍然还生动地记得,3年前,在美丽的集美中学,从我看到你微笑着走出教室,你将头向后仰,柔和的晚霞照耀 ...

  2. iPhone 电脑备份路径

    C:\Users\iChen\AppData\Roaming\Apple Computer\MobileSync\Backup

  3. JQuery Validate插件与实现

    菜鸟拙见,望请纠正 一:效果展示:以下是两个注册表单验证,左边使用Jquery validate插件实现,右边是自己用JQuery实现,效果差不多,但个人推荐用插件,毕竟前人栽了树而且长大了后人当然好 ...

  4. 改用固定IP后zabbix无法发送邮件的问题解决

    虚拟机之前一直用随机IP,然后发送邮件也正常. 改成固定IP以后,发送邮件失败. 用mail命令发送邮件成功. 查看zabbix_server的log,显示 cannot connect to SMT ...

  5. 【转】CSDN离线网页html文件自动跳转

    问题: 最近使用OneNote2016剪辑csdn的文章时,发现一些公式/文本框不能被正确识别,所以离线保存网页的html文件. 但是每次打开html文件,都会自动跳转的CSDN主页,即使断网,也会自 ...

  6. python中的控制流

    ifpython条件语句是通过一条或多条语句的执行结果(True或false)来决定执行的代码块 if语句用于控制程序的执行,基本形式为:if 判断条件:执行语句....elif判断语句:执行语句.. ...

  7. linux 服务启动

    在linux上部署java服务的时候,发现服务启动正常,但是[ps -ef|grep java].[jps]看不到服务的运行. 查资料发现,[Java -jar Test.jar &      ...

  8. 从OEL5中启动简单的dns服务

    在OEL5中,有一个 dnsmasq,可以适合小型的实验性的dns设置. 如果可以看到类似如下的内容,说明dnsmasq已经设置好了. [root@dnssvr ~]# rpm -qa dnsmasq ...

  9. const限定符用法汇总

    const限定符限定变量的类型是一个常量,对象一旦创建后其值就无法改变,所以const对象必须初始化. 初始化 const int i = get_size(); //运行时初始化 const int ...

  10. 3992: [SDOI2015]序列统计

    3992: [SDOI2015]序列统计 链接 分析: 给定一个集和s,求多少个长度为n的序列,满足序列中每个数都属于s,并且所有数的乘积模m等于x. 设$f=\sum\limits_{i=0}^{n ...