1676: [Usaco2005 Feb]Feed Accounting 饲料计算

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 252  Solved: 191
[Submit][Status][Discuss]

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.

约翰想知道上一船饲料是什么时候运到的.在饲料运到之前,他的牛正好把仓库里原来的饲料全吃光了.    他收到运来的F1(1≤Fi≤1000000)千克饲料.遗憾的是,他已经不记得这是哪一天的事情了.到第D(1≤D≤2000)天为止,仓库里还剩下F2(1≤F2≤Fi)千克饲料.
    约翰养了C(1≤C≤100)头牛,每头牛每天都吃掉恰好1千克饲料.由于不同的原因,牛们从某一天开始在仓库吃饲料,又在某一天离开仓库,所以不同的两天可能会有差距很大的饲料消耗量.每头牛在来的那天和离开的那天都在仓库吃饲料.    给出今天的日期D,写一个程序,判断饲料最近一次运到是在什么时候.今天牛们已经吃过饲料了,并且饲料运到的那天牛们还没有吃过饲料.

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.

    第1行:四个整数C,F1,F2,D,用空格隔开.
    第2到C+1行:每行是用空格隔开的两个数字,分别表示一头牛来仓库吃饲料的时间和离开的时间.

Output

The last day that the shipment might have arrived, an integer that will always be positive.

    一个正整数,即上一船饲料运到的时间.

Sample Input

3 14 4 10
1 9
5 8
8 12

Sample Output

6

对于每个区间[L, R],a[L]++, a[R+1]--,sum[]是a[]的前缀和

那么sum[i]就是第i天饲料的减少量

从第D天倒过来模拟一下就好了

#include<stdio.h>
#include<algorithm>
using namespace std;
int a[2005], sum[2005];
int main(void)
{int n, i, bet, ans, d, x, y;scanf("%d%d%d%d", &n, &bet, &ans, &d);for(i=1;i<=n;i++){scanf("%d%d", &x, &y);y = min(y, d);a[x]++, a[y+1]--;}for(i=1;i<=d;i++)sum[i] = sum[i-1]+a[i];for(i=d;i>=1;i--){ans += sum[i];if(ans>=bet){printf("%d\n", i);break;}}return 0;
}

bzoj 1676: [Usaco2005 Feb]Feed Accounting 饲料计算(差分)相关推荐

  1. 【差分】bzoj 1676 [Usaco2005 Feb]Feed Accounting 饲料计算

    题目的建模意思是什么呢? 每个奶牛从a点开始吃,从b+1点就停止吃.这就是间接告诉你这两点组成一个区间,需要差分序列. 之后对差分的序列求前缀和(计算每天的粮草的消耗量), 之后对于消耗的粮草,我们倒 ...

  2. bzoj 3392: [Usaco2005 Feb]Part Acquisition 交易(最短路)

    3392: [Usaco2005 Feb]Part Acquisition 交易 Time Limit: 5 Sec  Memory Limit: 128 MB Submit: 191  Solved ...

  3. BZOJ 1734: [Usaco2005 feb]Aggressive cows 愤怒的牛( 二分答案 )

    最小最大...又是经典的二分答案做法.. -------------------------------------------------------------------------- #inc ...

  4. bzoj 1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区(暴力)

    1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: ...

  5. bzoj 1731: [Usaco2005 dec]Layout 排队布局【差分约束】

    差分约束裸题,用了比较蠢的方法,先dfs_spfa判负环,再bfs_spfa跑最短路 注意到"奶牛排在队伍中的顺序和它们的编号是相同的",所以\( d_i-d_{i-1}>= ...

  6. 1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区(题解第二弹)

    1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: ...

  7. bzoj2059[Usaco2010 Nov]Buying Feed 购买饲料*

    bzoj2059[Usaco2010 Nov]Buying Feed 购买饲料 题意: 约翰开车来到镇上,他要带K吨饲料回家.如果他的车上有X吨饲料,每公里就要花费X^2元,开车D公里就需要D* X^ ...

  8. [DP/单调队列]BZOJ 2059 [Usaco2010 Nov]Buying Feed 购买饲料

    首先我想吐槽的是题目并没有表明数据范围... 这个题目 DP方程并不难表示. dp[i][j]表示前i个地点携带了j个货物的最小花费 dp[i][j] = dp[i-1][k] + (j-k) * c ...

  9. BZOJ 1738: [Usaco2005 mar]Ombrophobic Bovines 发抖的牛( floyd + 二分答案 + 最大流 )

    一道水题WA了这么多次真是.... 统考终于完 ( 挂 ) 了...可以好好写题了... 先floyd跑出各个点的最短路 , 然后二分答案 m , 再建图. 每个 farm 拆成一个 cow 点和一个 ...

最新文章

  1. 【Android基础】序列化 Serializable vs Parcelable
  2. ubuntu下python的错误
  3. 【python】逻辑运算符总结
  4. mysql数据库事务隔离级别
  5. 偶然搜索看到的杂谈——什麼東西是.NET程序員可以掌握並且可倚仗十年而不管微軟存在與否的技術呢?...
  6. 【html】【17】高级篇--loading加载
  7. Flink系列-实时数仓之Flink实时写入ClickHouse并实时大屏Tableau
  8. 关于WindowsPE的DIY和黑科技
  9. 彻底理解SVD奇异值分解(singular value decomposition)
  10. [入门向]标准测试用例模板
  11. 百兆电口Lan Bypass实例
  12. iostream头文件
  13. ​「5G消息」的最新消息
  14. IOS11.03越狱
  15. 根据银行卡号获取logo,并提取图片主题色(小程序版)
  16. 【虚拟仿真】Unity3D中如何实现让3D模型显示在UI前面
  17. Acrel-EMS企业微电网能效管理平台在某食品加工厂35kV变电站案例分享-安科瑞 周莉娜
  18. 宝宝起名神器小程序源码
  19. 回首过去,立足当下,展望未来
  20. 微信小程序 lookup 联表查询

热门文章

  1. python中文版软件下载-Python中文版下载_PyCharm官方最新版下载_3DM单机
  2. 普通人学python有什么用-学python日常工作有什么用?
  3. python最适合做什么-python学完之后比较适合哪些职业工作呢?
  4. 成都专业语音转化为文字怎么样_安徽听见科技
  5. 静态代理,cglib动态代理,jdk动态代理区别以及流程详解
  6. 在iview + vue项目中使用自定义icon图标
  7. 安全使用计算机习惯,如何安全使用计算机和互联网
  8. Element UI el-table 表格多选的使用
  9. Javascript预解析、代码执行
  10. linux编辑文件命令 vi_Linux的vi编辑器