传送门

先来考虑一下二维时的情况,那么对于 $x$ 相同的点,我们按 $y$ 排序,然后相邻的一对对消除

最后 $x$ 坐标相同的点最多剩下一个,那么此时所有点的 $x$ 坐标都不一样

再按 $x$ 把 $x$ 相邻的一对对删除即可

扩展到三维,显然也可以同样的思路,先把 $x,y$ 相同的点按 $z$ 一对对消除,然后在把 $x$ 相同的点按 $y,z$ 相邻的一对对消除

最后按 $x,y,z$ 相邻的一对对消除即可

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
inline int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int N=5e4+;
int n;
struct dat {
int x,y,z,id;
inline bool operator < (const dat &tmp) const {
if(x!=tmp.x) return x<tmp.x;
return y!=tmp.y ? y<tmp.y : z<tmp.z;
}
}A[N];
bool vis[N];
int main()
{
n=read();
for(int i=;i<=n;i++)
A[i].x=read(),A[i].y=read(),A[i].z=read(),A[i].id=i;
sort(A+,A+n+);
int l=;
for(int i=;i<=n;i++)
if(l && A[i].x==A[l].x && A[i].y==A[l].y)
{
vis[i]=vis[l]=;
printf("%d %d\n",A[i].id,A[l].id);
l=;
}
else l=i;
l=; while(vis[l]) l++;
for(int i=l+;i<=n;i++)
{
if(vis[i]) continue;
if(l && A[i].x==A[l].x)
{
vis[i]=vis[l]=;
printf("%d %d\n",A[i].id,A[l].id);
l=;
}
else l=i;
}
l=; while(vis[l]) l++;
for(int i=l+;i<=n;i++)
{
if(vis[i]) continue;
if(l) printf("%d %d\n",A[i].id,A[l].id),l=;
else l=i;
}
return ;
}

Codeforces 1237C2. Balanced Removals (Harder)的更多相关文章

  1. C2. Balanced Removals (Harder) (幾何、思維)

    Codeforce 1237C2 Balanced Removals (Harder) (幾何.思維) 今天我們來看看CF1237C2 題目連結 題目 給你偶數個三維座標點,每次選其中兩點,如果兩點為 ...

  2. CF1237C2 【Balanced Removals (Harder)】

    这么妙的题怎么没人发题解啊 首先这是三维的,我们可以对其进行降维打击 先考虑一维怎么做? 我们可以对其该维坐标进行排序,按照顺序输出,可能会多余一个 那拓展到二维呢? 我们可以把它转化成一维,分成很多 ...

  3. [Codeforces 873B]Balanced Substring

    Description You are given a string s consisting only of characters 0 and 1. A substring [l, r] of s  ...

  4. CodeForces - 873B Balanced Substring(思维)

    inputstandard input outputstandard output You are given a string s consisting only of characters 0 a ...

  5. Codeforces 873B - Balanced Substring(思维)

    题目链接:http://codeforces.com/problemset/problem/873/B 题目大意:一个字符串全部由‘0’和‘1’组成,当一段区间[l,r]内的‘0’和‘1’个数相等,则 ...

  6. CodeForces - 999C Alphabetic Removals

    C - Alphabetic Removals ≤k≤n≤4⋅105) - the length of the string and the number of letters Polycarp wi ...

  7. Codeforces 1237F. Balanced Domino Placements

    传送门 很妙的题 首先先考虑一个简化的问题,现在有一行格子让你填 你要么填一格 要么填两格 有的格子不让你填 问你填了 $a$ 个一格和填了 $b$ 个两格有多少种方案 那么显然先只考虑放两格的方案, ...

  8. Codeforces 1237E. Balanced Binary Search Trees

    传送门 这一题是真的坑人,时间空间都在鼓励你用 $NTT$ 优化 $dp$...(但是我并不会 $NTT$) 看到题目然后考虑树形 $dp$ ,设 $f[i][0/1]$ 表示 $i$ 个节点的树,根 ...

  9. Codeforces 1237D. Balanced Playlist

    传送门 首先显然的,如果一个位置开始播放了两圈还没结束,那么就永远不会结束 先考虑位置 $1$ 开始播放,用一个 $multisetset$ 维护一下当前听的所有歌,直到某一首歌 $r$ 不合法了就停 ...

随机推荐

  1. IN和EXISTS、not in 和not exists的效率详解

    从效率来看: 1) select * from T1 where exists(select 1 from T2 where T1.a=T2.a) ; T1数据量小而T2数据量非常大时,T1<& ...

  2. Consider defining a bean of type `xxx` in your configuration问题解决

    在使用SpringBoot装配mybatis时出现了异常 *************************** APPLICATION FAILED TO START *************** ...

  3. dubbo备忘

    http://start.dubbo.io/ https://github.com/dubbo/dubbo-samples https://www.aliyun.com/product/edas ht ...

  4. python -v 和-V

    python -v 小写v:这是版本信息,包括库版本 python -V 大写v:只看python的版本

  5. CentOS 7系统配置上的变化

    http://www.linuxidc.com/Linux/2014-09/107375p4.htm CentOS 7系统配置上的变化解析 ip ss指令替代 ifconfig route arp n ...

  6. 3、inform (通知、告诉、报告) - perform (表现)

  7. Java排序方法

    下面是用JAVA代码实现的数据结构中的7种基本排序算法,希望对你有所帮助. (1)直接插入排序 /** 直接插入排序 **/ /** 数组是引用类型,元素值将被改变 **/ public static ...

  8. Python3的编译安装

    Linux环境自带了Python 2.x版本,但是如果要更新到3.x的版本,可以在Python的官方网站下载Python的源代码并通过源代码构建安装的方式进行安装,具体的步骤如下所示. 1. 安装依赖 ...

  9. JAVA 基础编程练习题9 【程序 9 求完数】

    9 [程序 9 求完数] 题目:一个数如果恰好等于它的因子之和,这个数就称为"完数".例如 6=1+2+3.编程找出 1000 以内的 所有完数. package cskaoyan ...

  10. DevOps - DevOps工具链

    不要满足于使用世界上已存在的各种方法和技术,而应重点放在希望达到的效果上! 单单使用工具不难,困难的是在团队开发中熟练使用,并形成一套理想的工作流程,只有在团队中工具和思想才能发挥最大价值. 开源工具 ...