Codeforces Codeforces Global Round 5 C2

时间:2019-10-20
本文章向大家介绍Codeforces Codeforces Global Round 5 C2,主要包括Codeforces Codeforces Global Round 5 C2使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

https://codeforces.com/contest/1237/problem/C2

平面上的点可以把 x 轴坐标相等的点临近消除,剩余每个x轴只剩一个节点,临近相消除就好了,转换为三维则先消除x , y 轴坐标相等的节点就好了. 

#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i!=n;++i)
#define per(i, n) for(int i=n-1;i>=0;--i)
#define Rep(i, sta, n) for(int i=sta;i!=n;++i)
#define rep1(i, n) for(int i=1;i<=n;++i)
#define per1(i, n) for(int i=n;i>=1;--i)
#define Rep1(i, sta, n) for(int i=sta;i<=n;++i)
#define L k<<1
#define R k<<1|1
#define inf (0x3f3f3f3f)
#define llinf (1e18)
#define mid (tree[k].l+tree[k].r)>>1
#define ALL(A) A.begin(),A.end()
#define SIZE(A) ((int)A.size())
typedef long long i64;
using namespace std;
const int maxn = 5e4 + 32;
typedef struct Node{
    int x,y,z,index;
    bool operator<(const struct Node& n)const
    {
        if(x != n.x)
            return x < n.x;
        if(y != n.y)
            return y < n.y;
        return z < n.z;
    }
}node;
bool vis[maxn];
int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n;  cin >> n;   vector<node> v(n+1);
    rep1(i,n)
    {
        cin >> v[i].x >> v[i].y >> v[i].z;
        v[i].index = i;
    }
    sort(v.begin() + 1, v.end());
    int cur = 1;
    for(int i=2;i<=n;++i)
    {
        if(cur && v[i].x == v[cur].x && v[i].y == v[cur].y)
        {
            vis[i] = vis[cur] = true;
            cout << v[i].index << " " << v[cur].index << '\n';
            cur = 0; 
        }else 
            cur = i;
    }
    cur = 1;    while(vis[cur]) ++cur;
    for(int i=cur + 1;i<=n;++i)
    {
        if(vis[i])
            continue;
        if(cur && v[i].x == v[cur].x)
        {
            vis[i] = vis[cur] = true;
            cout << v[i].index << " " << v[cur].index << '\n';
            cur = 0; 
        }else 
            cur = i;
    }
    cur = 1;     while(vis[cur]) ++cur;
    for(int i=cur+1;i<=n;++i)
    {
        if(vis[i])  continue;
        if(cur) cout << v[cur].index << " " << v[i].index <<'\n',cur = 0;
        else cur = i;
    }
    return 0;
}

  

原文地址:https://www.cnblogs.com/newstartCY/p/11707458.html