bzoj 1676: [Usaco2005 Feb]Feed Accounting 饲料计算(差分)
来源:互联网 发布:安广网络宽带 编辑:程序博客网 时间:2024/04/28 09:21
1676: [Usaco2005 Feb]Feed Accounting 饲料计算
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 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 饲料计算(差分)
- bzoj1676[Usaco2005 Feb]Feed Accounting 饲料计算 差分
- 1676: [Usaco2005 Feb]Feed Accounting 饲料计算
- bzoj1676[Usaco2005 Feb]Feed Accounting 饲料计算
- bzoj1676: [Usaco2005 Feb]Feed Accounting 饲料计算
- [Usaco2005 Feb]Feed Accounting 饲料计算
- [Usaco2005 Feb]Feed Accounting 饲料计算
- BZOJ 1731: [Usaco2005 dec]Layout 排队布局 差分约束
- bzoj 1731: [Usaco2005 dec]Layout 排队布局 差分约束
- [BZOJ1731][Usaco2005 dec]Layout 排队布局(差分约束)
- bzoj 3043(差分)
- bzoj 1733: [Usaco2005 feb]Secret Milking Machine 神秘的挤奶机 (二分+最大流)
- bzoj 1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区(暴力)
- |BZOJ 1651|差分序列|[Usaco2006 Feb]Stall Reservations 专用牛棚
- bzoj 1734: [Usaco2005 feb]Aggressive cows 愤怒的牛
- bzoj 3392: [Usaco2005 Feb]Part Acquisition 交易 最短路
- POJ 2459 Feed Accounting(水~)
- bzoj 2160(manacher+差分)
- 渗透测试中常见的端口
- 对象族谱之类实例化过程
- 【scikit-learn】使用scikit机器学习的介绍
- MySQL数据库SYS CPU高的可能性分析
- JavaScript面向对象编程之封装
- bzoj 1676: [Usaco2005 Feb]Feed Accounting 饲料计算(差分)
- 分布式桥梁ZooKeeper开发体验
- ActiveMQ系列—消息协议(AMQP协议)
- 面试题:sql语句查询
- 读书笔记-《Java NIO》:第二章 缓冲区(2)
- 1007. Rails
- select语句中的多表查询
- 写一个线程安全的单例模式
- java中的==、equals()、hashCode()源码分析