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;
    }
    
  • 相关阅读:
    闭包的应用(转载)
    智能社讲解js基础
    HTML5 Geolocation
    Redis主从配置
    Redis序列化配置
    Ribbon负载均衡原理学习记录
    2059 mysql
    Cache缓存
    rabbitmq(三)-Direct交换器
    rabbitmq(二)原理
  • 原文地址:https://www.cnblogs.com/lokiii/p/8994226.html
Copyright © 2011-2022 走看看