zoukankan      html  css  js  c++  java
  • bzoj 1635: [Usaco2007 Jan]Tallest Cow 最高的牛【差分】

    s[i]为差分后的“i这头牛前有几头比它高”,计算答案的时候加成前缀和,假设第一头最高减一下即可
    用map记录一下被加过的区间,避免重复

    #include<iostream>
    #include<cstdio>
    #include<map>
    #include<algorithm>
    using namespace std;
    const int N=10005;
    int n,q,h,r,s[N],f[N],a,b;
    map<int,bool>mp[N];
    int read()
    {
    	int r=0,f=1;
    	char p=getchar();
    	while(p>'9'||p<'0')
    	{
    		if(p=='-')
    			f=-1;
    		p=getchar();
    	}
    	while(p>='0'&&p<='9')
    	{
    		r=r*10+p-48;
    		p=getchar();
    	}
    	return r*f;
    }
    int main()
    {
        n=read(),q=read(),h=read(),r=read();
        while(r--)
        {
            int x=read(),y=read();
            if(x>y)
    			swap(x,y);
            if(mp[x][y])
    			continue;
            mp[x][y]=1;
            ++s[x+1],--s[y];
        }
        for(int i=1;i<=n;++i)
        {
            f[i]=s[i]+f[i-1];
            printf("%d
    ",h-f[i]);
        }
        return 0;
    }
    
  • 相关阅读:
    mysql资料
    MySQL启动与关闭
    poj 2778 DNA Sequence
    poj 1625 Censored!
    zoj 3228 Searching the String
    hdu 4605 Magic Ball Game
    hdu 4610 Cards
    SGU 439 A Secret Book
    NOI2013
    NOI2014
  • 原文地址:https://www.cnblogs.com/lokiii/p/8994226.html
Copyright © 2011-2022 走看看