poj3262
一、题意:有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的更多相关文章
- 【贪心算法】POJ-3262
一.题目 Description Farmer John went to cut some wood and left N (2 ≤ N ≤ 100,000) cows eating the gras ...
- POJ-3262
Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7923 Accepted: ...
- poj3262 Protecting the Flowers
思路: 简单贪心,每次选择性价比最高的. 实现: #include <iostream> #include <cstdio> #include <algorithm> ...
- POJ3262 Protecting the Flowers 【贪心】
Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4418 Accepted: ...
- 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 ...
- POJ-3262 贪心的一个小技巧
Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 3204 Accepted: ...
- POJ3262贪心
题意:FJ去砍树,然后和平时一样留了 N (2 ≤ N ≤ 100,000)头牛吃草.当他回来的时候,他发现奶牛们正在津津有味地吃着FJ种的美丽的花!为了减少后续伤害,FJ决定立即采取行动:运输每头牛 ...
- NOIP模拟赛20161016R2
Problem 1 护花(flower.cpp/c/pas) [题目描述] 约翰留下他的N(N<=100000)只奶牛上山采木.他离开的时候,她们像往常一样悠闲地在草场里吃草.可是,当他回来的时 ...
- 12月上旬poj其他题
poj3170 1,4两遍bfs: poj3171 改一改poj2376即可 poj3172 dfs+剪枝 其实增长速度很快,n<=40,题目吓你的: poj3661 比较经典的dp:设f[i, ...
随机推荐
- Python3 网络爬虫开发实战学习弱点书签
1. urllib.robotparse模块对robot.txt文件的解析,can_fetch()方法和parse()方法. Page121 2. lxml.etree模块自动补全Html代码,Htm ...
- Mybaties核心配置文件
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE configurationPUBLIC &q ...
- Sql语句摘要
1.分批更新数据库 declare @x intset @x=1 while(@x<=51) begin begin tran update UserFavorite set UserFavor ...
- C++函数后面加throw关键字简记
看代码时候看到fun() throw()的用法,找到一篇blog解释很简单,如下: C++函数后面加关键字throw(something)限制,是对这个函数的异常安全性作出限制. 举例及解释如下: v ...
- Http中的身份传递
IIS默认的身份验证方式 身份传递策略包括使用操作系统的委派功能或在应用程序级传递票证和/或凭证 为了阻止IIS的身份验证委派,可以在web.config加入如下设置, <system.web& ...
- Java 自定义异常类
类1:public class LogicException extends RuntimeException { //业务逻辑异常 /** * * @param mes ...
- QuotedStr函数
今天学到一个新函数,很有用 QuotedStr(s);// 在s两边加单引号, 这样就不会看着n多的单引号糊涂了...
- sql server 简单语句整合
1.去重distinct , group by select distinct userid,username from 表名 select userid,username from 表名 group ...
- switch case 判断是否为按钮、设置属性 Load Foreach 绑定事件
private void button9_Click(object sender, EventArgs e) { foreach (Control CT in this.Controls) {//判断 ...
- layui之弹出层--从父窗口传递数据到子窗口
原文链接:https://blog.csdn.net/Code_shadow/article/details/80524633 var Index = layer.open({ title: &quo ...