• CF56E Domino Principle(dp)


    // Problem: CF56E Domino Principle
    // Contest: Luogu
    // URL: https://www.luogu.com.cn/problem/CF56E
    // Memory Limit: 250 MB
    // Time Limit: 2000 ms
    // Author:Cutele
    // 
    // Powered by CP Editor (https://cpeditor.org)
    
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    typedef pair<ll, ll>PLL;
    typedef pair<int, int>PII;
    typedef pair<double, double>PDD;
    #define I_int ll
    inline ll read()
    {
        ll x = 0, f = 1;
        char ch = getchar();
        while(ch < '0' || ch > '9')
        {
            if(ch == '-')f = -1;
            ch = getchar();
        }
        while(ch >= '0' && ch <= '9')
        {
            x = x * 10 + ch - '0';
            ch = getchar();
        }
        return x * f;
    }
      
    inline void out(ll x){
        if (x < 0) x = ~x + 1, putchar('-');
        if (x > 9) out(x / 10);
        putchar(x % 10 + '0');
    }
      
    inline void write(ll x){
        if (x < 0) x = ~x + 1, putchar('-');
        if (x > 9) write(x / 10);
        putchar(x % 10 + '0');
    }
      
    #define read read()
    #define closeSync ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
    #define multiCase int T;cin>>T;for(int t=1;t<=T;t++)
    #define rep(i,a,b) for(int i=(a);i<=(b);i++)
    #define repp(i,a,b) for(int i=(a);i<(b);i++)
    #define per(i,a,b) for(int i=(a);i>=(b);i--)
    #define perr(i,a,b) for(int i=(a);i>(b);i--)
    ll ksm(ll a, ll b,ll p)
    {
        ll res = 1;
        while(b)
        {
            if(b & 1)res = res * a%p;
            a = a * a %p;
            b >>= 1;
        }
        return res;
    }
    
    const int inf = 0x3f3f3f3f;
    const int maxn=1e5+7;
    
    int n,las[maxn],ans[maxn];
    struct node{
    	int x,h,id;
    }a[maxn];
    
    bool cmp(node a,node b){
    	return a.x<b.x;
    }
    
    int main(){
    	n=read;
    	rep(i,1,n){
    		a[i].x=read,a[i].h=read;a[i].id=i;
    		ans[i]=1;
    	}
    	sort(a+1,a+1+n,cmp);
    	
    	for(int i = n-1 ; i ; i--){
    		int now = i + 1 ;
    		while(now >=1 && a[i].x + a[i].h - 1 >= a[now].x){
    			ans[a[i].id]+=ans[a[now].id];
    			now=las[now];
    		}
    		las[i]=now;
    	}
    	
    	rep(i,1,n) cout<<ans[i]<<" ";
    	return 0;
    }
    
    
    
  • 相关阅读:
    Django中的syncdb命令
    notepad++下的字体设置
    python中的getattr函数
    python实现虚拟茶话会
    利用python爬取海量疾病名称百度搜索词条目数的爬虫实现
    SQL里面如何取得前N条数据?
    python中怎么查看当前工作目录和更改工作目录
    python中thread模块中join函数
    python中的自测语句是什么?
    python读取数据库数据有乱码怎么解决?
  • 原文地址:https://www.cnblogs.com/OvOq/p/15093882.html
Copyright © 2020-2023  润新知