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. Docker存储方式选型建议

    转自:https://segmentfault.com/a/1190000007168476 第一部分 问题诊断 事情从一次实施项目说起,我们需要帮助客户将他们的应用容器化并在数人云平台上发布此应用. ...

  2. virtualbox+vagrant学习-2(command cli)-14-vagrant reload命令

    Reload 格式: vagrant reload [vm-name] 其等价于在运行vagrant up命令后接着运行vagrant halt 要使在Vagrantfile文件中所做的更改生效,通常 ...

  3. Robotframework测试相关库的简单整理

    一. 官网地址 http://robotframework.org/#libraries 二.几类测试所用到的常用库初步整理 1. UI自动化测试 Selenium2Library.BuiltIn(自 ...

  4. 打开一个网站中的不同页面时,相同的js文件会被重复加载吗?

    作者:JasonYang链接:https://www.zhihu.com/question/41184156/answer/135195798来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非 ...

  5. Python之Cubes框架使用

    本文主要内容包含Cubes框架的介绍和简单使用. 一. 介绍和安装 Cubes是一个轻量级的Python框架和一套工具,用于开发报告和分析应用程序,在线分析处理(OLAP),多维分析和聚合数据的浏览. ...

  6. Python spli指定多个分隔符

    #!/usr/bin/python # -*- coding: UTF-8 -*- import re a='Beautiful, is; better*than\nugly' 以竖线"|& ...

  7. Spring Security with Boot

    1.spring安全 boot中的应用文档https://docs.spring.io/spring-security/site/docs/current/guides/html5//hellowor ...

  8. [转]TortoiseSVN客户端重新设置用户名和密码

    在第一次使用TortoiseSVN从服务器CheckOut的时候,会要求输入用户名和密码,这时输入框下面有个选项是保存认证信息,如果选了这个选项,那么以后就不用每次都输入一遍用户名密码了. 不过,如果 ...

  9. kubernetes 日志定制查阅 - 排错 -- 好用的命令

    You can use kubectl logs to retrieve logs from a previous instantiation of a container with --previo ...

  10. centos下添加启动项

    chkconfig --add 服务名称 chkconfig --level 345 服务名称 on