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, ...
随机推荐
- dev 官网
https://www.devexpress.com/Support/Center/Example/Details/E1343 <%@ Page Language="C#" ...
- Entity Framework 6.0 Tutorials(9):Stored Procedure Mapping
Code First - Insert, Update, Delete Stored Procedure Mapping: Entity Framework 6 Code-First provides ...
- IntelliJ IDEA——利用maven插件构建web工程
- C#中对DataTable进行全连接后group by,orderby
var result = from temp2 in ( from u in u ...
- delphi TString使用(取有规律的字符串中某一项内容)
{目的,取得下面字符串中的每一项内容,如s:='a,b,c,d',要去的用逗号隔开的每一项内容这时采用Tstring,会方便很多,TString是继承TStringList带有List所有属性.} v ...
- C#Thread学习
一.Thread的使用方式 1.不带参数 (1)使用lambda public static void fun1() { Console.WriteLine($"Main ThreadId: ...
- 关于nosql的讲解
Data Base 关于nosql的讲解 nosql非关系型数据库. 优点: 1.可扩展 2.大数据量,高性能 3.灵活的数据模型 4.高可用 缺点: 1.不正式 2.不标准 非关系型数据库有哪些: ...
- Ajax GET
$ajax的post请求提交方式: Controller: @RequestMapping("/emps") @ResponseBody public Msg getEmps(@R ...
- 321. Create Maximum Number (c++ ——> lexicographical_compare)
Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum numb ...
- 1221: Fibonacci数列 [数学]
1221: Fibonacci数列 [数学] 时间限制: 1 Sec 内存限制: 128 MB 提交: 116 解决: 36 统计 题目描述 Fibonacci数列的递推公式为:Fn=Fn-1+Fn- ...