HDU 3039 Go Home
今天本来解决的很好,本来可以不聊那么结束,但是我想更完美一点,多聊几句,谁知道就聊了很长时间,很傻逼。耽误了时间!
/*************************************************************************************************/
Go Home
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 400 Accepted Submission(s): 169
For example , there
are two roads on his way home and he wants to use 8 ECNU coins to hire
bodyguard , the first road takes 4 kilometers with 5 robbers ( per
kilometer ) and the second takes 5 kilometers with 6 robbers. He could
choose the last 3 kilometers on the first road and the whole kilometers
on the second road to hire bodyguard to protect him, and leave the first
kilometer on the first road to be robbed by 5 robbers, which he will be
robbed 5 ECNU coins.
Now , Partychen want to know how many ECNU coins will be robbed at least.
Every
case starts with two integers N and M ( 0≦N≦10,000, 0≦M≦1,000,000,000 )
which means that there are N roads and M ECNU coins to hire bodyguard.
The
followed N lines contains two integers D and P (1<=D<=10,000 ,
0<=P<=10 ) , which means the length of every road and the number
of robbers in every kilometer on this road.
End with N=0 and M=0 .
4 5
5 6
3 1
5 10
5 10
5 10
0 0
140
#include<queue>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 12345
struct node
{
int a,b;
}c[N];
int cmp(node n1,node n2)
{
return n1.b > n2.b;
}
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m)&&(n+m))
{
int sum=;
for(int i=;i<n;i++)
{
scanf("%d%d",&c[i].a,&c[i].b);
sum+=c[i].a*c[i].b;
}
sort(c,c+n,cmp);
for(int i=;i<n;i++)
{
if(m>=c[i].a)
{
sum-=c[i].b*c[i].a;
m-=c[i].a;
}
else
{
sum-=c[i].b*m;
break;
}
}
cout<<sum<<endl;
}
return ;
}
HDU 3039 Go Home的更多相关文章
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 4481 Time travel(高斯求期望)(转)
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...
- HDU 3791二叉搜索树解题(解题报告)
1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...
- hdu 4329
problem:http://acm.hdu.edu.cn/showproblem.php?pid=4329 题意:模拟 a. p(r)= R'/i rel(r)=(1||0) R ...
随机推荐
- Hive 导入数据报错,驱动版本过低
Failed with exception Unable to alter table. javax.jdo.JDODataStoreException: You have an error in y ...
- PHP过滤器 filter_has_var() 函数
定义和用法 filter_has_var() 函数检查是否存在指定输入类型的变量. 如果成功则返回 TRUE,如果失败则返回 FALSE. 语法 filter_has_var(type, variab ...
- AWR报告中Parse CPU to Parse Elapsd%的理解
AWR报告中Parse CPU to Parse Elapsd%的理解 原文自:http://dbua.iteye.com/blog/827243 Parse CPU to Parse Ela ...
- POJ——2251Dungeon Master(三维BFS)
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 25379 Accepted: 9856 D ...
- BZOJ4199 [Noi2015]品酒大会 【后缀数组 + 单调栈 + ST表】
题目 一年一度的"幻影阁夏日品酒大会"隆重开幕了.大会包含品尝和趣味挑战两个环节,分别向优胜者颁发"首席品 酒家"和"首席猎手"两个奖项,吸 ...
- run as maven build时报错
eclipse中使用maven插件的时候,运行run as maven build的时候报错 -Dmaven.multiModuleProjectDirectory system propery is ...
- 算法复习——树链剖分模板(bzoj1036)
题目: 题目背景 ZJOI2008 DAY1 T4 题目描述 一棵树上有 n 个节点,编号分别为 1 到 n ,每个节点都有一个权值 w .我们将以下面的形式来要求你对这棵树完成一些操作:I.CHAN ...
- Aragorn's Story(hdu3966)
题意:给一棵树,并给定各个点权的值,然后有3种操作: I C1 C2 K: 把C1与C2的路径上的所有点权值加上K D C1 C2 K:把C1与C2的路径上的所有点权值减去K Q C:查询节点编号为C ...
- POJ 2002 Squares [hash]
Squares Time Limit: 3500MS Memory Limit: 65536K Total Submissions: 16631 Accepted: 6328 Descript ...
- Scrapy学习-8-ItemLoader
ItemLoader使用 作用 方便管理维护重用xpath或css规则 实例 itemloader+图片处理 # items.py import scrapy from scrapy.loader ...