今天本来解决的很好,本来可以不聊那么结束,但是我想更完美一点,多聊几句,谁知道就聊了很长时间,很傻逼。耽误了时间!

/*************************************************************************************************/

Go Home

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 400    Accepted Submission(s): 169

Problem Description
There comes the holiday, Partychen set foot on the way home. He takes some ECNU coins to hire bodyguards to prevent from being robbed before he went home. But the bodyguard takes one coin for every kilometer. If Partychen walks without bodyguard , he will be robbed one ECNU coin by every robber on every kilometer . Of course , he can choose where to hire bodyguard or where to be robbed as he like.
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.
 
Input
It consists of multi-case .
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 .
 
Output
An integer means the number of ECNU coins to be robbed at least.
 
Sample Input
2 8
4 5
5 6
3 1
5 10
5 10
5 10
0 0
 
Sample Output
5
140
 
Source
 
Recommend
lcy
 
贪心,暗每千米的强盗数降序排即可
#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的更多相关文章

  1. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  2. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  3. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  4. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  5. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  6. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  7. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

  8. HDU 3791二叉搜索树解题(解题报告)

    1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...

  9. hdu 4329

    problem:http://acm.hdu.edu.cn/showproblem.php?pid=4329 题意:模拟  a.     p(r)=   R'/i   rel(r)=(1||0)  R ...

随机推荐

  1. 安装elk,日志采集系统

    #elasticsearch安装 wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.0.0-linux ...

  2. PHP获得网页源码

    获取网页源代码: <?php $lines = file('http://www.hoverreader.com/'); foreach ($lines as $line_num => $ ...

  3. Spring核心技术(十二)——基于Java的容器配置(二)

    使用@Configuration注解 @Configuration注解是一个类级别的注解,表明该对象是用来指定Bean的定义的.@Configuration注解的类通过@Bean注解的方法来声明Bea ...

  4. python基础学习笔记——列表技巧

    列表: 循环删除列表中的每⼀个元素 li = [, , , ] for e in li: li.remove(e) print(li) 结果: [, ] 分析原因: for的运⾏过程. 会有⼀个指针来 ...

  5. shiro 系列

    http://jinnianshilongnian.iteye.com/blog/2019547 shiro学习以及附带DEMO地址: http://www.sojson.com/shiro ,git ...

  6. Spring注解@Component、@Repository、@Service、@Controller

    @Service用于标注业务层组件 @Controller用于标注控制层组件(如struts中的action) @Repository用于标注数据访问组件,即DAO组件 @Component泛指组件, ...

  7. Debian7配置LAMP(Apache/MySQL/PHP)环境及搭建建站

    完整Debian7配置LAMP(Apache/MySQL/PHP)环境及搭建建站 第一.安装和配置Apache Web服务器 运行升级命令来确保我们的系统组件各方面都是最新的. apt-get upd ...

  8. Replication and Triggers

    参考官网:https://dev.mysql.com/doc/refman/5.7/en/replication-features-triggers.html 需要了解复制和触发器关系的背景: 程序变 ...

  9. SPOJ QTREE4 Query on a tree IV ——动态点分治

    [题目分析] 同bzoj1095 然后WA掉了. 发现有负权边,只好把rmq的方式改掉. 然后T了. 需要进行底(ka)层(chang)优(shu)化. 然后还是T 下午又交就A了. [代码] #in ...

  10. uva 11021

    题意:有k只麻球,每只活一天就会死亡,临死之前可能会生出一些新的麻球.具体来说,生i个麻球的概率为pi.给定m,求m天后所有麻球死亡的概率.注意,不足m天时就已经全部死亡的情况也算在内. 分析:由于每 ...