bzoj 1676: [Usaco2005 Feb]Feed Accounting 饲料计算(差分)
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.
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
Sample Output
对于每个区间[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 饲料计算(差分)相关推荐
- 【差分】bzoj 1676 [Usaco2005 Feb]Feed Accounting 饲料计算
题目的建模意思是什么呢? 每个奶牛从a点开始吃,从b+1点就停止吃.这就是间接告诉你这两点组成一个区间,需要差分序列. 之后对差分的序列求前缀和(计算每天的粮草的消耗量), 之后对于消耗的粮草,我们倒 ...
- bzoj 3392: [Usaco2005 Feb]Part Acquisition 交易(最短路)
3392: [Usaco2005 Feb]Part Acquisition 交易 Time Limit: 5 Sec Memory Limit: 128 MB Submit: 191 Solved ...
- BZOJ 1734: [Usaco2005 feb]Aggressive cows 愤怒的牛( 二分答案 )
最小最大...又是经典的二分答案做法.. -------------------------------------------------------------------------- #inc ...
- bzoj 1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区(暴力)
1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区 Time Limit: 5 Sec Memory Limit: 64 MB Submit: ...
- bzoj 1731: [Usaco2005 dec]Layout 排队布局【差分约束】
差分约束裸题,用了比较蠢的方法,先dfs_spfa判负环,再bfs_spfa跑最短路 注意到"奶牛排在队伍中的顺序和它们的编号是相同的",所以\( d_i-d_{i-1}>= ...
- 1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区(题解第二弹)
1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区 Time Limit: 5 Sec Memory Limit: 64 MB Submit: ...
- bzoj2059[Usaco2010 Nov]Buying Feed 购买饲料*
bzoj2059[Usaco2010 Nov]Buying Feed 购买饲料 题意: 约翰开车来到镇上,他要带K吨饲料回家.如果他的车上有X吨饲料,每公里就要花费X^2元,开车D公里就需要D* X^ ...
- [DP/单调队列]BZOJ 2059 [Usaco2010 Nov]Buying Feed 购买饲料
首先我想吐槽的是题目并没有表明数据范围... 这个题目 DP方程并不难表示. dp[i][j]表示前i个地点携带了j个货物的最小花费 dp[i][j] = dp[i-1][k] + (j-k) * c ...
- BZOJ 1738: [Usaco2005 mar]Ombrophobic Bovines 发抖的牛( floyd + 二分答案 + 最大流 )
一道水题WA了这么多次真是.... 统考终于完 ( 挂 ) 了...可以好好写题了... 先floyd跑出各个点的最短路 , 然后二分答案 m , 再建图. 每个 farm 拆成一个 cow 点和一个 ...
最新文章
- 【Android基础】序列化 Serializable vs Parcelable
- ubuntu下python的错误
- 【python】逻辑运算符总结
- mysql数据库事务隔离级别
- 偶然搜索看到的杂谈——什麼東西是.NET程序員可以掌握並且可倚仗十年而不管微軟存在與否的技術呢?...
- 【html】【17】高级篇--loading加载
- Flink系列-实时数仓之Flink实时写入ClickHouse并实时大屏Tableau
- 关于WindowsPE的DIY和黑科技
- 彻底理解SVD奇异值分解(singular value decomposition)
- [入门向]标准测试用例模板
- 百兆电口Lan Bypass实例
- iostream头文件
- ​「5G消息」的最新消息
- IOS11.03越狱
- 根据银行卡号获取logo,并提取图片主题色(小程序版)
- 【虚拟仿真】Unity3D中如何实现让3D模型显示在UI前面
- Acrel-EMS企业微电网能效管理平台在某食品加工厂35kV变电站案例分享-安科瑞 周莉娜
- 宝宝起名神器小程序源码
- 回首过去,立足当下,展望未来
- 微信小程序 lookup 联表查询
热门文章
- python中文版软件下载-Python中文版下载_PyCharm官方最新版下载_3DM单机
- 普通人学python有什么用-学python日常工作有什么用?
- python最适合做什么-python学完之后比较适合哪些职业工作呢?
- 成都专业语音转化为文字怎么样_安徽听见科技
- 静态代理,cglib动态代理,jdk动态代理区别以及流程详解
- 在iview + vue项目中使用自定义icon图标
- 安全使用计算机习惯,如何安全使用计算机和互联网
- Element UI el-table 表格多选的使用
- Javascript预解析、代码执行
- linux编辑文件命令 vi_Linux的vi编辑器