bzoj1676[Usaco2005 Feb]Feed Accounting 饲料计算
Description
Farmer John is trying to figure out when his last shipment of feed arrived. Starting with an empty grain bin, he ordered and received F1 (1 <= F1 <= 1,000,000) kilograms
of feed. Regrettably, he is not certain exactly when the feed arrived. Of the F1 kilograms, F2 (1 <= F2 <= F1) kilograms of feed remain on day D (1 <= D <= 2,000). He must determine the most recent day that his shipment could have arrived. Each of his C (1
<= C <= 100) cows eats exactly 1 kilogram of feed each day. For various reasons, cows arrive on a certain day and depart on another, so two days might have very different feed consumption. The input data tells which days each cow was present. Every cow ate
feed from Farmer John's bin on the day she arrived and also on the day she left. Given that today is day D, determine the minimum number of days that must have passed since his last shipment. The cows have already eaten today, and the shipment arrived before
the cows had eaten.
Input
* Line 1: Four space-separated integers: C, F1, F2, and D * Lines 2..C+1: Line i+1 contains two space-separated integers describing the presence of a cow. The first integer tells the first day the cow
was on the farm; the second tells the final day of the cow's presence. Each day is in the range 1..2,000.
Output
The last day that the shipment might have arrived, an integer that will always be positive.
Sample Input
1 9
5 8
8 12
INPUT DETAILS:
The shipment was 14 kilograms of feed, and Farmer John has 4 kilograms
left. He had three cows that ate feed for some amount of time in
the last 10 days.
Sample Output
上一次运来了14千克饲料,现在饲料还剩下4千克.最近10天里.有3头牛来吃过饲料.
约翰在第6天收到14千克饲料,当天吃掉2千克,第7天吃掉2千克,第8天吃掉3千克,第9天吃掉2千克,第10天吃掉1千克,正好还剩4千克
倒着搞差分序列……f2每次更新……到f2>=f1的时候就输出……没了
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int c,f1,f2,d,r,sum;
int a[2010];
int main()
{
c=read();
f1=read();
f2=read();
d=read();
while (c--)
{
int x=read(),y=read();
a[x-1]--;a[y]++;
r=max(r,y);
}
for (int i=r;i>0;i--)
{
sum+=a[i];
if(i<=d)f2+=sum;
if (f2>=f1)
{
printf("%d",i);
return 0;
}
}
}
bzoj1676[Usaco2005 Feb]Feed Accounting 饲料计算的更多相关文章
- 【BZOJ】1676: [Usaco2005 Feb]Feed Accounting 饲料计算(差分)
http://www.lydsy.com/JudgeOnline/problem.php?id=1676 太水的一题了.. 差分直接搞. #include <cstdio> #includ ...
- [Usaco2005 Feb]Feed Accounting 饲料计算
Description Farmer John is trying to figure out when his last shipment of feed arrived. Starting wit ...
- BZOJ3392: [Usaco2005 Feb]Part Acquisition 交易
3392: [Usaco2005 Feb]Part Acquisition 交易 Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 26 Solved: ...
- 1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区(题解第二弹)
1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: ...
- BZOJ 1734: [Usaco2005 feb]Aggressive cows 愤怒的牛( 二分答案 )
最小最大...又是经典的二分答案做法.. -------------------------------------------------------------------------- #inc ...
- 1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区(题解第一弹)
1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: ...
- 1734: [Usaco2005 feb]Aggressive cows 愤怒的牛
1734: [Usaco2005 feb]Aggressive cows 愤怒的牛 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 217 Solved: ...
- bzoj 1734: [Usaco2005 feb]Aggressive cows 愤怒的牛
1734: [Usaco2005 feb]Aggressive cows 愤怒的牛 Description Farmer John has built a new long barn, with N ...
- bzoj1734 [Usaco2005 feb]Aggressive cows 愤怒的牛 二分答案
[Usaco2005 feb]Aggressive cows 愤怒的牛 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 407 Solved: 325[S ...
随机推荐
- solr索引
solr索引 当我们真正进入到Lucene源代码之中的时候,我们会发现: • Lucene的索引过程,就是按照全文检索的基本过程,将倒排表写成此文件格式的过程. • Lucene的搜索过程,就是按照此 ...
- ORACLE_CLASS_ENDING
[JSU]LJDragon's Oracle course notes In the first semester, junior year Oracle考前复习 试题结构分析: 1.选择题2x10, ...
- mongodb授权登录
mongodb版本为3.2(目前最新),演示的是linux下的mongodb授权认证 第一次登录不启动授权(mongo默认不启动) ./mongod --dbpath=/home/db/data -- ...
- HTTP Status 404(The requested resource is not available)的几种解决方法
原因:servlet没有配置正确 ,查看web.xml确认正确,以及自己的请求路径正确 在IE中提示“404”错误有以下三种情况 1.未部署Web应用 2.URL输入错误 排错方法: 首先,查看URL ...
- 图表插件--jqplot交互演示样例
简单交互 在之前的学习中,我们已经能够绘制各种类型的图表,也能够给图表加入不同的组件,如标题.图例等等.但这些图表仅仅能用于展示数据,一旦希望对图表有所操作--比方查看数据明细--就显得束手无策了.事 ...
- 常见算法:C语言求最小公倍数和最大公约数三种算法
最小公倍数:数论中的一种概念,两个整数公有的倍数成为他们的公倍数,当中一个最小的公倍数是他们的最小公倍数,相同地,若干个整数公有的倍数中最小的正整数称为它们的最小公倍数,维基百科:定义点击打开链接 求 ...
- iOS中block实现的探究
[0. Brief introduction of block] Block是iOS4.0+ 和Mac OS X 10.6+ 引进的对C语言的扩展,用来实现匿名函数的特性. 用维基百科的话来说,Blo ...
- Asp.net +Jquery-uploadify多文件上传
页面代码如下: <link href="JS/jquery.uploadify/uploadify.css" rel="stylesheet" type= ...
- 免费SVN源代码在线托管
免费的SVN源代码在线托管网站很多,用的最多的是TaoCode吧.但是一般都要求开源,支持私有项目的普遍收费,要不就是流量很少,不够用.对比了一下,发现好库正好能满足需要. 网址: http://ww ...
- 一步步启动linux
可以一步一步启动linux. 在Ubantu刚一启动时,按c健即进入Grub>提示符状态,在此状态下输入(我用的是Ubuntu 13) grub>linux /vmlinuz grub&g ...