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 ...
随机推荐
- ZMQ设置socket选项
Name zmq_setsockopt –设置ZMQ socket的属性 Synopsis int zmq_setsockopt (void *socket, int option_name, con ...
- 转:Java生成图片验证码(有点仿QQ验证码的意思)
http://blog.csdn.net/ruixue0117/article/details/22829557 java: VerifyCodeUtils.java package com.fro. ...
- iTunes备份文件路径
Windows 7 电脑:C:\Users\使用者名称\AppData\Roaming\Apple Computer\MobileSync\Backup XP 电脑:C:\Documents and ...
- 利用TreeSet给纯数字字符串排序
import java.util.Iterator;import java.util.TreeSet; /* * 给字符串中的数字排序 * String str = "10,2,11,1,3 ...
- IOS设计模式学习(19)策略
1 前言 面向对象软件设计中,我们可以把相关算法分离为不同的类,成为策略.与这种做法有关的一种设计模式成为策略模式. 2 详述 2.1 简述 策略模式中得一个关键角色是策略类,它为所有支持的或相关的算 ...
- openstack单元測试用组件一览
声明: 本博客欢迎转发,但请保留原作者信息! 博客地址:http://blog.csdn.net/halcyonbaby 内容系本人学习.研究和总结,如有雷同,实属荣幸! 组件一览 hacking 一 ...
- Sqoop是一款开源的工具,主要用于在HADOOP(Hive)与传统的数据库(mysql、oracle...)间进行数据的传递
http://niuzhenxin.iteye.com/blog/1706203 Sqoop是一款开源的工具,主要用于在HADOOP(Hive)与传统的数据库(mysql.postgresql.. ...
- Linux修改SSH连接数 重启SSH服务
系统 linux,增加SSH终端连接数最大为1000个 解决方案: vi /etc/ssh/sshd_config 输入/MaxStartups 定位到如下并修改 1) #MaxStar ...
- NumberSpinner( 数字微调) 组件
本节课重点了解 EasyUI 中 Spinner(微调)组件的使用方法,这个组件依赖于Numberbox(数值输入框)和 Spinner(微调)组件. 一. 加载方式//class 加载方式<i ...
- 使用VS Code开发Angular 2应用程序所需配置文件的解析
目录 package.json typings.json tsconfig.json launch.json settings.json tasks.json package.json: 这是项目的基 ...