一、题意:有n头牛,每头牛每分钟会吃D个菜,把这头牛赶回去需要时间T(人再返回又需要T),一次只能赶回去一头牛,也就是说剩下的牛会继续吃菜。求牛最少吃多少菜

二、思路:贪心。按D/T将牛进行排序,然后计算即可。

三、代码:

 #include"iostream"
#include"stdio.h"
#include"algorithm"
#include"string.h"
using namespace std; const int MAXN=;
typedef long long ll;
const ll INF=; int used[MAXN];
struct Cow
{
int t,d;
double div;
};
Cow cows[MAXN];
int n; bool Cmp(const Cow a,const Cow b)
{
return a.div>b.div;
}
ll Solve()
{
ll res=;
ll sum=;
for(int i=;i<n;i++)
sum+=cows[i].d;
for(int i=;i<n;i++){
sum-=cows[i].d;
res+=sum**cows[i].t;
}
return res;
} int main()
{
while(scanf("%d",&n)==)
{
for(int i=;i<n;i++){
scanf("%d%d",&cows[i].t,&cows[i].d);
cows[i].div=double(cows[i].d)/double(cows[i].t);
}
sort(cows,cows+n,Cmp);
cout<<Solve()<<endl;
}
return ;
}

poj3262的更多相关文章

  1. 【贪心算法】POJ-3262

    一.题目 Description Farmer John went to cut some wood and left N (2 ≤ N ≤ 100,000) cows eating the gras ...

  2. POJ-3262

    Protecting the Flowers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7923   Accepted: ...

  3. poj3262 Protecting the Flowers

    思路: 简单贪心,每次选择性价比最高的. 实现: #include <iostream> #include <cstdio> #include <algorithm> ...

  4. POJ3262 Protecting the Flowers 【贪心】

    Protecting the Flowers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4418   Accepted: ...

  5. Day3-D-Protecting the Flowers POJ3262

    Farmer John went to cut some wood and left N (2 ≤ N ≤ 100,000) cows eating the grass, as usual. When ...

  6. POJ-3262 贪心的一个小技巧

    Protecting the Flowers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 3204   Accepted: ...

  7. POJ3262贪心

    题意:FJ去砍树,然后和平时一样留了 N (2 ≤ N ≤ 100,000)头牛吃草.当他回来的时候,他发现奶牛们正在津津有味地吃着FJ种的美丽的花!为了减少后续伤害,FJ决定立即采取行动:运输每头牛 ...

  8. NOIP模拟赛20161016R2

    Problem 1 护花(flower.cpp/c/pas) [题目描述] 约翰留下他的N(N<=100000)只奶牛上山采木.他离开的时候,她们像往常一样悠闲地在草场里吃草.可是,当他回来的时 ...

  9. 12月上旬poj其他题

    poj3170 1,4两遍bfs: poj3171 改一改poj2376即可 poj3172 dfs+剪枝 其实增长速度很快,n<=40,题目吓你的: poj3661 比较经典的dp:设f[i, ...

随机推荐

  1. Luogu 4784 [BalticOI 2016 Day2]城市

    斯坦纳树复习,我暑假的时候好像写过[JLOI2015]管道连接来着. 设$f_{i, s}$表示以$i$为根,$k$个重要点的连通状态为$s$,($0$代表没有连进最小生成树里面去,$1$代表连进了最 ...

  2. Luogu 4159 [SCOI2009]迷路

    BZOJ 1297 应当是简单题. 发现边权的数量很小,所以我们暴力把一个点拆成$9$个点,然后把$(x, i)$到$(x, i + 1)$连边,代表转移一次之后可以走回来:对于每一条存在的边$(i, ...

  3. Part4_lesson3---U-Boot工作流程分析

    1.程序入口 我们从什么地方去找入口呢,首先是打开顶层目录的makefile文件,在这个文件里面,每一个uboot支持的开发板都有一个配置选项,比如说,搜索smdk2440,结果如下 我们主要关注上图 ...

  4. python核心编程第2章课后题答案(第二版36页)

    2-5 Loops and Numbers a) i = 0    while i <11:     print i    i += 1 b) for i in range(0,11): pri ...

  5. Socket编程(c语言示例)

    转自:http://blog.csdn.net/dxpqxb/article/details/8166423 前言 Socket可以看成在两个程序进行通讯连接中的一个端点,是连接应用程序和网络驱动程序 ...

  6. 将“100px” 转换为100

    parseInt("100px") //结果是100

  7. window.document 对象

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. 数据库表转换成JavaBean

    本人花了几个小时用C#开发了一款,数据表生成javabean的软件.目前只支持Mysql,内置类型映射器.开源,没有测试. 支持数据库注释,忘了获取表注释,见谅.使用之前配置一下config.xml文 ...

  9. 【C#】特性标签中的属性解释

    第一个为特性作用于类,或者接口(interface) 第二个为是否允许重叠定义,就是连续写两个特性标签 第三个为是否继承,当继承时候,除输出子类外,父类也将输出

  10. 游戏中遇到的BUG

    (1)bug描述:战斗中有英雄死亡,一方掉线之后再次上线,仍然可以看到死亡英雄空血条(英雄受到攻击才会显示血条) 解决方案:原来 当前血量小于英雄血量最大值时,证明英雄受到伤害,血条显示为true I ...