题意:有n头牛,每头牛回去都需要一定时间,如果呆在原地就会毁坏花朵。问:怎么安排使得毁坏的花朵最少?

思路:

拉走成本最高的。

  1. 什么是成本?毁坏花朵的数量。
  2. 例如有两种排序   (这里用(a,b)表示题意,a表示往回走的时间,b表示呆在原处毁坏花朵的数量

     (a,b) (c,d) 成本为 x*b+(x+a)*d;   

     (c,d) (a,b) 成本为 x*d+(x+c)*b;

  两种成本显示,如果ad>bc则选择下面那种排序,如果bc>ad则选择上面那种排序,实现的代码

bool cmp(Cow a, Cow b)
{
return a.d / a.t > b.d / b.t;
}

通过这种成本由高到低的排序,只要遍历,时间*毁坏的花朵累加既可以得到答案

解决问题的代码:

#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
struct Cow
{
double t, d;
}cow[];
bool cmp(Cow a, Cow b)
{
return a.d / a.t > b.d / b.t;
}
int main()
{
int n;
scanf("%d", &n);
for (int i = ; i < n; i++)
scanf("%lf%lf", &cow[i].t, &cow[i].d);
sort(cow, cow + n, cmp);
long long sum = , ans = ;
for (int i = ; i < n; i++)
{
sum += ans * * cow[i].d;
ans += cow[i].t;
}
printf("%d\n", sum);
return ;
}

最新文章

  1. Codeforces CF#628 Education 8 F. Bear and Fair Set
  2. 论SOA架构的几种主要开发方式
  3. Harp – 内置常用预处理器的静态 Web 服务器
  4. hdu 1255
  5. Pyqt QSystemTrayIcon 实现托盘效果
  6. 基于Spark1.3.0的Spark sql三个核心部分
  7. tensorflow1
  8. iOS AFNetworking “Request failed: unacceptable content-type: text/html”问题
  9. linux服务之drbd
  10. mongodb csv 文件导入数据库,删除特定字段
  11. JHipster的安装
  12. ABAP ALV DEMO示例源码
  13. java-常用快捷键
  14. 线性代数(高斯消元):JSOI2008 球形空间产生器sphere
  15. Spring之SpringMVC的Controller(源码)分析
  16. linux之x86裁剪移植---ffmpeg的H264解码显示(420、422)
  17. python接口自动化(十九)--Json 数据处理---实战(详解)
  18. python基础16_闭包_装饰器
  19. servlet对象的生命周期
  20. js一元运算符

热门文章

  1. (转)nginx域名访问的白名单配置梳理
  2. 找不到 main 方法, 请将 main 方法定义为: public static void main(String[] args)
  3. 安卓H5软键盘遮挡输入框
  4. AJPFX辨析continue与break的区别
  5. Java面向对象(static、final、匿名对象、内部类、包、修饰符、代码块)
  6. Linux下软件安装的四种方式
  7. 用jQuery实现jsonp跨域
  8. 关于IT公司招聘的一个思考
  9. Android RecyclerView使用GridLayoutManager间距设置
  10. Beginning Python Chapter 2 Notes