poj-3262-Protecting the Flowers
来源:互联网 发布:wwe2k15优化补丁 编辑:程序博客网 时间:2024/06/12 00:22
题意:
有n头牛,每头牛每分钟对花的伤害为D,每头牛被运回牛棚需要T分钟,求对花最少的伤害。
解题思路:
只需按照每头牛对花的伤害排序即可,伤害最大的先运回去。
程序:
#include<stdio.h>#include<string.h>#include<iostream>#include<algorithm> #define N 110000using namespace std;int d[N];struct In{ long long a; long long b;}cow[N];bool cmp(In x , In y){ return x.a*y.b>=x.b*y.a;}int main(){ int n,m,s,t,i,j; long long ans; while(scanf("%d",&t)!=EOF) { memset(d,0,sizeof(d)); for(i=0;i<t;i++) { cin>>cow[i].a>>cow[i].b; // 按照伤害,由小到大排序。 } sort(cow,cow+t,cmp); /* for(i=0;i<t;i++) { cout<<cow[i].a<<" "<<cow[i].b<<endl;; }*/ d[0]=cow[0].b; for(i=1;i<t;i++) { d[i]=d[i-1]+cow[i].b; } ans=0; for(i=t-1;i>0;i--) { ans+=d[i-1]*cow[i].a*2; // 先把伤害大的运回去。 } cout<<ans<<endl; } return 0;}
0 0
- POJ 3262 Protecting the Flowers
- POJ 3262 Protecting the Flowers
- POJ-3262-Protecting the Flowers
- Poj 3262 Protecting the flowers
- POJ 3262 Protecting the Flowers
- POJ-3262-Protecting the Flowers
- POJ-3262-Protecting the Flowers
- poj-3262-Protecting the Flowers
- poj 3262 Protecting the Flowers
- poj 3262 Protecting the Flowers
- poj 3262 Protecting the Flowers
- poj 3262 Protecting the Flowers
- POJ 3262 Protecting the Flowers
- POJ 3262 - Protecting the Flowers
- POJ 3262 Protecting the Flowers
- POJ 3262 Protecting the Flowers
- poj 3262 Protecting the Flowers
- POJ 3262 Protecting the Flowers
- HDU 4908 BestCoder Sequence
- misc_register、 register_chrdev 的区别总结 .
- hdu 4883
- Java学习笔记(八)abstract,final,变量及接口
- HDOJ 题目2059 龟兔赛跑(动态规划)
- poj-3262-Protecting the Flowers
- POJ 1185 炮兵阵地
- OC类和对象
- html表格合并(行,列)
- 希尔排序-c++
- hibernate中criteria的用法
- Core Data入门
- 第156天
- 把Storyboard减轻的方法