POJ-3262-Protecting the Flowers
来源:互联网 发布:哪些app网络视频下载 编辑:程序博客网 时间:2024/05/20 12:48
这个题是说FJ要把在外面的牛带回去,每次需要花费的时间是2*Ti(往返),然后若该牛没有被牵走,那么每个单位时间那么将破坏Di朵花,然后要求求出将所有的牛带回,最少破坏的花有多少朵。
思路:
贪心题,按D[i]/T[i]从大到小排序即可。
代码:
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm> using namespace std;const int maxn=1e6+1000;struct Node{ long long t; long long d; double s; bool operator < (const Node &a)const {if(s==a.s) return d>a.d;return s>a.s; }}a[maxn];int n;long long ans;int main(){ while(scanf("%d",&n)!=EOF) {ans=0;for(int i=0;i<n;i++){ scanf("%I64d%I64d",&a[i].t,&a[i].d); a[i].s=a[i].d*1.0/a[i].t;}sort(a,a+n);int t=a[0].t*2;for(int i=1;i<n;i++){ ans+=t*a[i].d; t+=a[i].t*2;}printf("%I64d\n",ans); } 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
- php oauth 模块在linux下安装
- OJ_1152 点菜问题
- 一个关于矩阵的问题
- oracle的回滚和撤销机制
- VC++中播放声音的方法
- POJ-3262-Protecting the Flowers
- pgsql对用户添加数据库权限
- C语言三种基本结构
- 特征变换以及维度下降——Linear Discriminant Analysis(三)
- cocos2d-x技能冷却效果
- 【java performance】将try/catch块移出循环
- Android中window,view,Activity的关系
- yii中 集成PHPExcel 实现excel导入
- Java 序列化 格式