POJ-3264-Protecting the Flowers
来源:互联网 发布:淘宝买家虚假交易 编辑:程序博客网 时间:2024/05/20 12:47
题意:有一群牛正在花园里吃花,给你几组测试分别是把牛运回去的时间和一单位时间里对花的伤害,让你帮助找出按什么顺序把牛运回去才能使牛对花的伤害最小。
思路:很简单,就是对花的伤害除以运回去的时间就是对花的平均伤害,根据平均伤害从大到小排序就可以了。
代码:
#include<cstdio>#include<iostream>#include<algorithm>using namespace std;const int maxn=100005;struct lpf{ int t; int d;}a[maxn];int cmp(struct lpf p,struct lpf q){ double x,y; x=p.d*1.0/p.t; y=q.d*1.0/q.t; return x>y;}int main(){ int n; while(~scanf("%d",&n)) { long long sum=0,hua=0; for(int i=0;i<n;i++) { scanf("%d%d",&a[i].t,&a[i].d); sum+=a[i].d; } sort(a,a+n,cmp); for(int i=0;i<n;i++) { sum-=a[i].d; hua+=sum*a[i].t; } printf("%lld\n",hua*2); }}
0 0
- POJ-3264-Protecting the Flowers
- POJ 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
- (26)JavaScript中表格方便的操作方式
- java 内存泄露常见类型及对应相关JVM参数
- java 基础知识回顾(便于复习)
- 自己要找的东西
- opencv各种问题记录
- POJ-3264-Protecting the Flowers
- 变量为什么要初始化
- Best Time to Buy and Sell Stock
- Devise Authentication Recover Password by Email
- 七月书单
- 求一个二叉树中任意两个节点间的最大距离,两个节点的距离的定义是这两个节点间边的个数,比如某个孩子节点和父节点间的距离是1,和相邻兄弟节点间的距离是2,
- Ubuntu静态ip与动态ip联网
- mysql数据表类型的选择
- 利用OpenCV显示一幅图像