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, ...
随机推荐
- Python基础-2
目录: 1.列表.元组操作 2.字符串操作 3.字典操作 4.集合操作 5.文件操作 6.字符编码与转码 一.列表.元组操作 定义列表 names = ['Freeman',"Jack&qu ...
- atom markdown报错:AssertionError: html-pdf: Failed to load PhantomJS module.
今天安装markdown-pdf之后运行的时候报错: AssertionError: html-pdf: Failed to load PhantomJS module. You have to se ...
- What is difference between 3-layer architecture and MVC architecture?
By Vikas Singh on Sep 26, 2014 In 3-layer architecture 3-layer architecture separates the applicati ...
- 面试题:测试给定的list,使用for,foreach,iterator删除元素的不同表现
上代码: 1. 使用增强for循环(foreach) package com.xxx; import java.util.ArrayList; import java.util.List; /** * ...
- .net连接eDirectory,需要安全连接的解决方案
用C#连接eDirectory ,提示: “这个请求需要一个安全的连接.” 解决办法,eDirectory禁用TLS(这方法比较猥琐) ssh连接到eDirectory服务器上,执行: ldapcon ...
- delphi 数组的使用
delphi中数组就跟string使用类似,数组分为:动态数组和静态数组 还可根据数据的功能分为:数组(一维数组).二维数组.三维数组...静态数组: 固定长度,内容需要定义时添加.动态数组: 故名思 ...
- C# 操作 MongoDB
今项目使用Mongodb,C#操作MongoDB使用MongoDB.Driver.dll库(Nuget),写了个小Demo,如下: using System; using System.Collect ...
- 分享我的第一个asp.net core开发过程
.net core 这个东西感觉还是很不错的,学习了一下,并且做了一个微服务(IP地址查询服务) http://vju.cc/ip/ipquery 看上他的跨平台功能,所以就研究一下,中间有不少坑,有 ...
- Mybatis注解开发
mybatis 的常用注解: @Insert:实现新增 @Update:实现更新 @Delete:实现删除 @Select:实现查询 @Result:实现结果集封装 @Results:可以与 @Res ...
- django修改数据库连接
settings.py DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'domain', 'USER ...