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

题目的建模意思是什么呢?

每个奶牛从a点开始吃,从b+1点就停止吃。这就是间接告诉你这两点组成一个区间,需要差分序列。

之后对差分的序列求前缀和(计算每天的粮草的消耗量),

之后对于消耗的粮草,我们倒着从第D天往第1天加和,如果刚好相符就输出。

#include <cstdio>
#include <algorithm>
#include <cstring>

int n,d,Start,End;
int Sum[2333];
int x,y;

int main(){
    scanf("%d%d%d%d",&n,&Start,&End,&d);
    int Aim = Start - End;
    for(int i=1;i<=n;i++){
        scanf("%d%d",&x,&y);
        Sum[x]++;
        Sum[y+1]--;
    }
    for(int i=1;i<=d;i++){
        Sum[i]+=Sum[i-1];
        //printf("Sum[%d]:%d\n",i,Sum[i]);
    }
    int ans = 0;
    for(int i=d;i>=1;i--){
        ans+=Sum[i];
        if(ans>=Aim){
            printf("%d\n",i);
            return 0;
        }
    }
}
时间: 2024-10-12 13:42:32

【差分】bzoj 1676 [Usaco2005 Feb]Feed Accounting 饲料计算的相关文章

【BZOJ】1676: [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 arriv

bzoj1676[Usaco2005 Feb]Feed Accounting 饲料计算*

bzoj1676[Usaco2005 Feb]Feed Accounting 饲料计算 题意: 知道草料到来时F1kg,第D天F2kg.同时知道每头牛到来时间和离开时间,一牛一天吃1kg草料,问草料到来是第几天. 题解: 直接用区间左端点对应数组元素++,右端点+1对应数组元素--的方法,最后扫一下即可. 代码: 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #define inc(i

[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 arriv

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

最小最大...又是经典的二分答案做法.. -------------------------------------------------------------------------- #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #define rep( i , n ) for( int i = 0 ; i < n ; ++i ) #defin

bzoj 1734: [Usaco2005 feb]Aggressive cows 愤怒的牛

1734: [Usaco2005 feb]Aggressive cows 愤怒的牛 Description Farmer John has built a new long barn, with N (2 <= N <= 100,000) stalls. The stalls are located along a straight line at positions x1,...,xN (0 <= xi <= 1,000,000,000). His C (2 <= C &l

[BZOJ 1733] [Usaco2005 feb] Secret Milking Machine 【二分 + 最大流】

题目链接:BZOJ - 1733 题目分析 直接二分这个最大边的边权,然后用最大流判断是否可以有 T 的流量. 代码 #include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; const int MaxN = 200 + 5,

bzoj:1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区

Description It's election time. The farm is partitioned into a 5x5 grid of cow locations, each of which holds either a Holstein ('H') or Jersey ('J') cow. The Jerseys want to create a voting district of 7 contiguous (vertically or horizontally) cow l

BZOJ 1733: [Usaco2005 feb]Secret Milking Machine 神秘的挤奶机

Description 约翰正在制造一台新型的挤奶机,但他不希望别人知道.他希望尽可能久地隐藏这个秘密.他把挤奶机藏在他的农场里,使它不被发现.在挤奶机制造的过程中,他需要去挤奶机所在的地方T(1≤T≤200)次.他的农场里有秘密的地道,但约翰只在返回的时候用它.农场被划分成N(2≤N≤200)块区域,用1到200标号.这些区域被P(1≤P≤40000)条道路连接,每条路有一个小于10^6的长度L.两块区域之间可能有多条道路连接.为了减少被发现的可能,约翰不会两次经过农场上的任何一条道路.当然了

BZOJ3392: [Usaco2005 Feb]Part Acquisition 交易

3392: [Usaco2005 Feb]Part Acquisition 交易 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 26  Solved: 18[Submit][Status] Description 奶牛们接到了寻找一种新型挤奶机的任务,为此它们准备依次经过N(1≤N≤50000)颗行星,在行星上进行交易.为了方便,奶牛们已经给可能出现的K(1≤K≤1000)种货物进行了由1到K的标号.由于这些行星都不是十分发达.没有流通的货币,所以