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

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

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. centos 装 android studio (2)

    这里,我打算安装 JDK 1.8. $ sudo add-apt-repository ppa:webupd8team/java $ sudoapt-get update $ sudoapt-get ...

  2. Centos6虚拟主机的实现

    centos6上虚拟主机的实现   实现虚拟主机有三种方式:基于IP的实现.基于端口的实现.基于FQDN的实现 一.基于IP的实现 1.先创建三个站点: mkdir /app/site1 mkdir ...

  3. 【LeetCode】Roman to Integer(罗马数字转整数)

    这道题是LeetCode里的第13道题. 题目说明: 罗马数字包含以下七种字符: I, V, X, L,C,D 和 M. 字符 数值 I 1 V 5 X 10 L 50 C 100 D 500 M 1 ...

  4. A Survey of Model Compression and Acceleration for Deep Neural Network时s

    A Survey of Model Compression and Acceleration for Deep Neural Network时s 本文全面概述了深度神经网络的压缩方法,主要可分为参数修 ...

  5. Relay Race (DP)

    Furik and Rubik take part in a relay race. The race will be set up on a large square with the side o ...

  6. TeraTerm下载

    参考:http://blog.csdn.net/gxp/article/details/9169319 官方主页: http://ttssh2.sourceforge.jp/ 官方下载: http:/ ...

  7. 高一python笔记大全(过会考)

    最初のプログラム xfは.どちらかの試合(しあい)活動(かつどう)に参加して.a秒(aは整数)を使ったのですが.今あなたがひとつ任務を有:分と秒数を出力するください. a=int(input(&quo ...

  8. 【angularjs学习】简单的语法

    <div ng-app="" ng-init="names=[{name:'Jani',country:'Norway'},{name:'Hege',country ...

  9. 【Vijos1412】多人背包(背包DP)

    题意:求0/1背包的前K优解总和 k<=50 v<=5000 n<=200 思路:日常刷水 归并即可,不用排序 ; ..,..,..]of longint; w,c,a,b:..]o ...

  10. MongoDB_副本集集群模式

    主从模式: 在10.3.13.213 主节点, 10.3.2.33 从节点.mongodb 安装路径均为:/usr/local/server/mongodb 参考文章:http://www.lance ...