POJ Protecting the Flowers
来源:互联网 发布:win10网络连接红叉 编辑:程序博客网 时间:2024/05/31 13:16
点击打开题目
题目大意
奶牛要吃花,FJ来赶牛,将第i头牛赶走要2*ti分钟,奶牛每分钟吃di个单位花,求花的最小损失
先赶吃花多的,Wrong Answer QAQ
我们可以算一算损失
设sum=d1+d2+d3+…+dn
那损失为:
如果将1号牛与2号牛交换
那损失为:
有变化的量为:t1·d2 –> t2·d1
假设cost1 > cost2
即 t1·d2 > t2·d1
所以
所以在排序时,
代码如下:
#include<cstdio> #include<cmath> #include<cstring> #include<queue> #include<algorithm> using namespace std;struct node{ int t,d;}a[100001];bool cmp(node x,node y){return x.t*1.0/x.d<y.t*1.0/y.d;}int getint() { int num=0,flag=1;char c; while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1; while(c>='0'&&c<='9')num=num*10+c-48,c=getchar(); return num*flag; }int n;long long ans,t;int main(){ int i;n=getint(); for(i=1;i<=n;i++)a[i].t=getint(),a[i].d=getint(); sort(a+1,a+n+1,cmp); for(i=1;i<=n;i++) { ans+=a[i].d*t; t+=2*a[i].t; } printf("%lld",ans);}
阅读全文
2 0
- 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-3264-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
- linux中socket编程出现 connect: No route to host
- 我的第一篇博客的尝试
- 缘分,来过便已成诗
- sublime-text3打造markdown编辑器
- Android MVP模式实战练习之一步一步打造一款简易便笺app(一)
- POJ Protecting the Flowers
- django中一个应用使用另一个应用的模型类并建立外键
- opencv配置:opencv3.2.0+VS2017
- NAT技术基本知识
- JavaWeb学习十八(util包下的Date和sql包下的Date的转换)
- 一个很智障却很实用的程序(十进制转二进制)
- 根据另外一张表更新已有表字段
- 欢迎使用CSDN-markdown编辑器
- 51Nod-1001 数组中和等于K的数对【排序+二分查找】