杭电 1789(贪心思维练习)
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
题意: 就是每个作业有不同得分值跟截至日期,到了时间没按时完成作业老师会扣分,然后如何写作业使得扣分最少。每天只能完成一项作业。
思路:我们是想在规定得时间拿到尽可能多得分数,好贪婪啊,那不就是贪心嘛! 那么我们可以这样对数组进行排序,分数大的,截至时间短得优先考虑,如果分数一样,则按照时间短的优先,否则按照分数从大到小排序。
#include<bits/stdc++.h>
using namespace std;
int vis[1000005];
int flag;
struct node{
int day;
int score;
}a[1005];
int cmpp(node a,node b){
if(a.score == b.score) return a.day < b.day;
return a.score > b.score;
}
int main(){
int t;
cin>>t;
int j;
while(t--){
memset(vis,0,sizeof(vis));
int n;
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i].day;
}
for(int i=0;i<n;i++){
cin>>a[i].score;
}
sort(a,a+n,cmpp);
flag = 0;
for(int i=0;i<n;i++){
j = a[i].day;
while(1){
if(vis[j] == 0){
vis[j] = 1;
break;
}
else{
j--;
}
if(j == 0){
flag += a[i].score;
break;
}
}
}
cout<<flag<<endl;
}
return 0;
}
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Codeforces Round #621 (Div. 1 + Div. 2)(无比自闭的一夜)
- 牛客小白月赛22 A~~J
- P1914 小书童——密码
- sql server 2008 把远程的数据库的数据转移到本地数据数据库里
- 蓝桥杯 试题 基础练习 阶乘计算
- Java Lamada
- 试题 基础练习 高精度加法
- C# devExpress GridControl 行中行 子行 多级行
- 蓝桥杯 试题 基础练习 Huffuman树
- 蓝桥杯 试题 基础练习 2n皇后问题(包含n皇后问题讲解)
- 蓝桥杯 试题 基础练习 报时助手
- 蓝桥杯 试题 基础练习 回形取数
- 了解RefreshScope这篇短文就够了
- Educational Codeforces Round 83 (Rated for Div. 2) A~~E
- Codeforces Round #627 (Div. 3) 题解