HDU1789Doing Homework again(贪心)
Problem Description
Input
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
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
Author
Source
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn=+;
struct node{
int dl,sco;
bool flag;//flag表示可以完成
}a[maxn];
bool cmp(node a1,node a2){
if(a1.dl!=a2.dl)return a1.dl<a2.dl;
else return a1.sco>a2.sco;
}
int main()
{
int N,n,i;
scanf("%d",&N);
while(N--)
{
scanf("%d",&n);
for(i=;i<n;i++)scanf("%d",&a[i].dl);
for(i=;i<n;i++)scanf("%d",&a[i].sco);
for(i=;i<n;i++)a[i].flag=true;
sort(a,a+n,cmp);
int day=,res=;
for(i=;i<n;i++)
{
if(a[i].dl>=day){
day++;
continue;
}
int p=a[i].sco,pos=i;
for(int j=;j<i;j++)
{
if(a[j].sco<p&&a[j].flag==)
{
p=a[j].sco;
pos=j;
}
}
res+=p;
a[pos].flag=;
}
printf("%d\n",res);
}
return ;
}
HDU1789Doing Homework again(贪心)的更多相关文章
- HDU1789Doing Homework again(贪婪)
HDU1789Doing Homework again(贪心) 题目链接 题目大意:给你n们作业的最后期限和过了这个期限没做须要扣的分数.问如何安排能够使得扣分最少. 解题思路:贪心,将扣分多的作业排 ...
- 贪心-hdu-1789-Doing Homework again
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1789 题目意思: 有n个作业,每个作业有一个截止日期,每个作业如果超过截止日期完成的时候有一个惩罚值 ...
- HDU 1789 Doing Homework again(贪心)
Doing Homework again 这只是一道简单的贪心,但想不到的话,真的好难,我就想不到,最后还是看的题解 [题目链接]Doing Homework again [题目类型]贪心 & ...
- hdu-1789-Doing Homework again
/* Doing Homework again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- hdu--1798--Doing Homework again(贪心)
Doing Homework again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- hdu 1789 Doing HomeWork Again (贪心算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 /*Doing Homework again Time Limit: 1000/1000 MS ...
- HDU 1789 - Doing Homework again - [贪心+优先队列]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 Time Limit: 1000/1000 MS (Java/Others) Memory Li ...
- HDOJ.1789 Doing Homework again (贪心)
Doing Homework again 点我挑战题目 题意分析 给出n组数据,每组数据中有每份作业的deadline和score,如果不能按期完成,则要扣相应score,求每组数据最少扣除的scor ...
- I - Doing Homework again(贪心)
I - Doing Homework again Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
随机推荐
- Head First设计模式——策略设计模式
策略设计模式 说在前面的话 入软件一年啦,平心而论,总算不限于只会钻研些基础的语言语法了,数据结构和算法也恶补的差不多了.所以~趁着现在一边实习一边啃<Head First设计模式>的功夫 ...
- [HMLY]10.iOS中block的基础用法
本文简介 本章不会对Block做过多的实现研究.只是讲解基本的用法.纯粹基础知识.结合实际项目怎么去做举例.Block使用场景,可以在两个界面的传值,也可以对代码封装作为参数的传递等.用过GCD就知道 ...
- openui5的资料比较少
openui5的资料比较少,稳定优秀的开源框架,国内了解的人了了,都在追AngularJS.ExtJS.React. React比较新,非死不可出品而且裹挟Native的噱头.Mobile Nativ ...
- 中兴电信光纤猫F450获取管理员密码方法
初衷:为了完成端口映射,一开始以为电信光猫不支持自定义路由,因为通过useradmin登录进去后没有找到对应的选项.一番了解之后,原来光猫有超级密码,电信装机时是不会告诉你的,电信客服一般也不会告诉你 ...
- 重要的几个热键[Tab], [ctrl]-c, [ctrl]-d
来源于:鸟哥的Linux私房菜 在继续后面的章节之前,这里很需要跟大家再来报告一件事,那就是我们的文字模式里头具有很多的功能按键, 这些按键可以辅助我们进行指令的编写与程序的中断呢!这几个按键请大家务 ...
- Linux的一些简单命令(三)
1.解压缩算法:使用gzip算法进行解压缩, 压缩语法:gzip filename 解压语法:gzip -dv filename 2.解压缩算法:使用bzip2算法进行解压缩, 压缩语法:bz ...
- Tomcat7性能优化
目的 通过优化tomcat提高网站的并发能力. 服务器资源 服务器所能提供CPU.内存.硬盘的性能对处理能力有决定性影响. 优化配置 配置tomcat管理员账户 在conf/ tomcat-users ...
- PHP5.5在windows 安装使用 memcached 服务端的方法以及 php_memcache.dll 下载
PHP5.5 在windows下安装 memcached 的方法 下载服务端资源 http://download.csdn.net/detail/zsjangel/7104727 下载完成后,解压(我 ...
- CodeForces 78D Archer's Shot
二分. 统计过程如下图: 先统计红线上的个数,然后统计绿线上的个数,然后统计咖啡色线上的个数......一个一个往下统计就可以了. #pragma comment(linker, "/STA ...
- CSU 1812 三角形和矩形
湖南省第十二届大学生计算机程序设计竞赛$J$题 计算几何. #pragma comment(linker, "/STACK:1024000000,1024000000") #inc ...