zoukankan      html  css  js  c++  java
  • [技巧]ARubbish

    套树会爆内存,sort PAIR 离散后暴搜染色

    /*
    	Zeolim - An AC a day keeps the bug away
    */
    
    //#pragma GCC optimize(2)
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef long double ld;
    #define mp(x, y) make_pair(x, y) 
    #define pii pair <int, int>
    const int INF = 0x3f3f3f3f;
    const ld PI = acos(-1.0);
    const ld E = exp(1.0);
    
    const int MAXN = 1e6 + 10;
    
    pii ST[MAXN];
    
    int n, x, y, ans = 0;
    
    int coler[MAXN] = {0};
    
    pii now;
    
    void dfs(int x, int y)
    {
    	for(int i = -1; i <= 1; ++i)
    	{
    		for(int j = -1; j <= 1; ++j)
    		{
    			now = mp(x + i, y + j);
    
    			int it = lower_bound(ST, ST + n, now) - ST;
    
    			if(ST[it] == now && !coler[it])
    			{
    				coler[it] = ans;
    				int fst = ST[it].first, lst = ST[it].second;
    				dfs(fst, lst);
    			}
    		}
    	}
    }
    
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);     cout.tie(0);
        //freopen("D://test.in", "r", stdin);
        //freopen("D://test.out", "w", stdout);
    
    	cin >> n;
    
    	for(int i = 0; i < n; ++i)
    	{
    		cin >> ST[i].first >> ST[i].second;
    	}
    
    	sort(ST, ST + n);
    
    	for(int i = 0; i < n; ++i)
    	{
    		if(!coler[i])
    		{
    			++ans;
    			coler[i] = ans;
    			int fst = ST[i].first, lst = ST[i].second;
    			dfs(fst, lst);
    		}
    	}	
    
    	cout << ans << '
    ';
    
    
        return 0;
    }
  • 相关阅读:
    09-排序1 排序
    06-图3 六度空间
    06-图2 Saving James Bond
    06-图1 List Components
    04-树5 Complete Binary Search Tree
    03-树2 Tree Traversals Again
    PAT 05-树8 Huffman Codes
    Egret引擎的visible两次开关闭问题
    Egret的项目笔记(一)
    Egret屏幕适配【转】
  • 原文地址:https://www.cnblogs.com/zeolim/p/12270359.html
Copyright © 2011-2022 走看看