hdoj 1789 Doing Homework again
Doing Homework again
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 8638 Accepted Submission(s):
5090
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.
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.
total reduced score, one line per test case.
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct record
{
int day;
int score;
}num[1100];
bool cmp(record a,record b)
{
if(a.score!=b.score)
return a.score>b.score;
else
return a.day<b.day;
}
int main()
{
int n,m,j,i,t,l,sum;
int vis[1100];//用来储存必须要占用的日期
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
memset(vis,0,sizeof(vis));
for(i=0;i<n;i++)
scanf("%d",&num[i].day);
for(i=0;i<n;i++)
scanf("%d",&num[i].score);
sort(num,num+n,cmp);
sum=0;
for(i=0;i<n;i++)
{
for(j=num[i].day;j>=1;j--)
{
if(vis[j]==0)
{
vis[j]=1;
break;
}
}
if(j==0)
sum+=num[i].score;
}
printf("%d\n",sum);
}
return 0;
}
hdoj 1789 Doing Homework again的更多相关文章
- HDOJ.1789 Doing Homework again (贪心)
Doing Homework again 点我挑战题目 题意分析 给出n组数据,每组数据中有每份作业的deadline和score,如果不能按期完成,则要扣相应score,求每组数据最少扣除的scor ...
- Hdoj 1789 Doing Homework again 题解
Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of h ...
- 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 (贪心)
Doing Homework again http://acm.hdu.edu.cn/showproblem.php?pid=1789 Problem Description Ignatius has ...
- HDU 1789 - Doing Homework again - [贪心+优先队列]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 Time Limit: 1000/1000 MS (Java/Others) Memory Li ...
- HDU 1789 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 Problem Description Ignatius has just come back ...
- HDU 1789 Doing Homework again(贪心)
Doing Homework again 这只是一道简单的贪心,但想不到的话,真的好难,我就想不到,最后还是看的题解 [题目链接]Doing Homework again [题目类型]贪心 & ...
- HDU 1789 Doing Homework again(贪心)
在我上一篇说到的,就是这个,贪心的做法,对比一下就能发现,另一个的扣分会累加而且最后一定是把所有的作业都做了,而这个扣分是一次性的,所以应该是舍弃扣分小的,所以结构体排序后,往前选择一个损失最小的方案 ...
随机推荐
- absolute之整体布局实现
要实现如图的布局,我最先想到是将header与footer绝对定位,但是发现在移动端会出现bug,经查资料发现用absolute实现整体布局非常好,还挺简单的. .header, .footer, . ...
- ES6笔记-字符串方法
字符串检索方法,indexOf(searchValue,fromIndex)//参数1必需,检索查询的字符串或者值,参数2选题,规定检索的起始位置,不设置默认从0开始 indexOf()方法返回检索字 ...
- php学习,一个简单的Calendar(1)
材料取之深入PHP与JQuery开发,这本书实际上就是讲述一个活动日程表. 此文章适合从其它语言(如java,C++,python等)转到php,没有系统学习php,或者是php初学者,已经对程序有较 ...
- ObjectCopy
对象的传参用的是传引用,但开发中通常不允许对传入参数进行修改.因此对象拷贝很常用,Python提供一个很方便的对象拷贝方法 如代码: __author__ = 'mengxuan' import co ...
- 远程连接sql server 数据库的方法
今天找了半天,终于解决了如何从本地连接到远程sql server服务器的方法. 1.首先确保打开远程服务器的sql server配置管理器,确保TCP/IP协议开启 2.WebConfig的连接字符格 ...
- SQL Server 2008 R2 主从数据库同步设置
一.准备工作: 主数据库服务器: OS:Windows Server 2008 R2 DB: SQL Server 2008 R2 Hostname : CXMasterDB IP: 192.1 ...
- 一些嵌入式和FPGA相关模块的开源
工作一年,整理下手头做过的东西,分享出来,希望能帮到大家. 嵌入式方面,主要集中在Xilinx家的器件上,ZYNQ居多.Linux相关的就不贴了,网上的资料太多,xilinx-wiki上资料都是比较全 ...
- 关于BootStrap下图标的显示问题
我现在在做自己的毕业设计,用到了bootstrap的这一套css样式,说句心里话,这一套东西确实很好用,但是一个小问题足足浪费了我将近两个小时. 我的问题是:没有办法使用bootstrap下的图标(很 ...
- Linq Distinct List 去重复
//调用 return producePlantlst.Distinct(new item_collection_DistinctBy_item1()).ToList(); //方法 public c ...
- 【POJ 3167】Cow Patterns (KMP+树状数组)
Cow Patterns Description A particular subgroup of K (1 <= K <= 25,000) of Farmer John's cows l ...