Xidian oj 1120: Gold of Orz Pandas 贪心
来源:互联网 发布:rc522 stc源码 编辑:程序博客网 时间:2024/06/11 17:53
链接:戳这里
1120: Gold of Orz Pandas
时间限制: 1 Sec 内存限制: 128 MB
题目描述Orz Panda is addicted to one RPG game. To make his character stronger, he have to fulfil tasks to get EXP for higher level.At first he accepted all the tasks.But after he read rules carefully, he realized that what he has done was stupid.
Rule:
Every task costs 1 time interval.
Every task has a dead line.If you can't finish it on time ,you have to pay the same amount of gold as the EXP given by this task.
Orz Panda wants to know the minimum amount of gold he has to pay.
输入
The first line has one integer n, tell you how many tasks Orz Panda has accepted.
The second line has n integers ti separated by blank, represent for the ith task's dead line.
The third line has n integers ei separated by blank, represent for the
EXP given by the ith task.
(1 <= n, ti, ei <= 1000)
输出
One integer for the minimum amount of gold Orz Panda has to pay.
样例输入
4
3 1 2 3
10 20 30 40
样例输出
10
题意:给出n个任务,每个任务有两个属性,t表示这个任务必须在第t天之前完成(包括第t天),e表示这个任务有一个价值,如果一个任务完不成就会丢失这个价值,要求你输出最小的价值损失 你可以在第i天任意的选择任务去做
思路:
这个首先提到的是必须在第t天之前完成,所以我们贪心在第t天最多能得到的最大的价值(可以拿t天之后的,但是t天之前的拿不了) 所以我们每次都去贪心当前的i天能拿的最大价值
代码:
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<string>#include<vector>#include <ctime>#include<queue>#include<set>#include<map>#include<stack>#include<iomanip>#include<cmath>#define mst(ss,b) memset((ss),(b),sizeof(ss))#define maxn 0x3f3f3f3f#define MAX 1000100///#pragma comment(linker, "/STACK:102400000,102400000")typedef long long ll;typedef unsigned long long ull;#define INF (1ll<<60)-1using namespace std;int n;struct node{ int t,v; bool operator < (const node a) const{ return v>a.v; }}s[1000100];int vis[1000100];int main(){ while(scanf("%d",&n)!=EOF){ mst(vis,0); int T=0,sum=0; for(int i=1;i<=n;i++){ scanf("%d",&s[i].t); T=max(T,s[i].t); } for(int i=1;i<=n;i++){ scanf("%d",&s[i].v); sum+=s[i].v; } sort(s+1,s+n+1); int ans=0; for(int i=T;i>=1;i--){ for(int j=1;j<=n;j++){ if(i<=s[j].t && !vis[j]) { ans+=s[j].v; vis[j]=1; break; } } } cout<<sum-ans<<endl; } return 0;}
0 0
- Xidian oj 1120: Gold of Orz Pandas 贪心
- Baskets of Gold Coins
- Synthesis of Gold Nanorods
- UESTC--1271--Search gold(贪心)
- LIGHT OJ 1189 - Sum of Factorials【贪心+递归】
- light oj 1189 - Sum of Factorials (阶乘+贪心)
- Orz
- orz
- ORZ
- ...Orz
- Orz
- Orz
- orz
- 贪心小结 [贪心专题16题] --Orz爱神
- Gift of gold tiffany jewelry
- Deliver of the dfo gold
- hdu2401 Baskets of Gold Coins
- Baskets of Gold Coins 2401
- 【SSH】——Hibernate(2)get和load的区别
- C语言学习一:vc++6环境搭配、学习资料准备
- iOS高效开发工具汇总(持续更新中)
- 最快排序--桶排序
- C-第二次
- Xidian oj 1120: Gold of Orz Pandas 贪心
- 题目来源于欧拉计划的数学OJ。。。
- 从源码理解TreeMap.java
- CentOS系统:no space left on device错误
- PullToRefreshGridView下拉刷新
- 基础卷_异常篇 第1集一句话让异常在你面前裸体
- JSP的基本语法
- HDU 1233 还是畅通工程
- hdu3555——Bomb(数位dp)