题意

题目链接

Sol

说实话这题我到现在都不知道咋A的。

考试的时候是对任意相邻点之间连边,然后一分没有

然后改成每两个之间连一条边就A了。。

按说是可以过掉任意坐标上的点都是偶数的数据啊。。

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
#include<cstring>
#include<queue>
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
using namespace std;
const int MAXN = 2e5 + 10, INF = 1e9 + 10, mod = 998244353;
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N;
int x[MAXN], y[MAXN], date[MAXN], numx[MAXN], numy[MAXN];
vector<int> E[MAXN];
vector<Pair> tmp[MAXN];
void Get(int *a) {
for(int i = 1; i <= N; i++) date[i] = a[i];
sort(date + 1, date + N + 1);
int num = unique(date + 1, date + N + 1) - date - 1;
for(int i = 0; i <= num; i++) tmp[i].clear();
for(int i = 1; i <= N; i++) a[i] = lower_bound(date + 1, date + num + 1, a[i]) - date - 1, tmp[a[i]].push_back(MP(a[i], i));
for(int i = 0; i <= num; i++) {
if(tmp[i].size() < 2) continue;
sort(tmp[i].begin(), tmp[i].end());
for(int j = 0; j < tmp[i].size() - 1; j += 2) {
int x = tmp[i][j].se, y = tmp[i][j + 1].se;
E[x].push_back(y);
E[y].push_back(x);
}
}
}
int vis[MAXN], vis2[MAXN];
void BFS(int k) {
queue<int> q;
vis[k] = 1; q.push(k);
while(!q.empty()) {
int p = q.front(); q.pop();
if(vis2[p]) continue; vis2[p] = 1;
for(int i = 0; i < E[p].size(); i++) {
int to = E[p][i];
vis[to] = vis[p] ^ 1;
q.push(to);
}
} }
int main() {
N = read();
for(int i = 1; i <= N; i++) x[i] = read(), y[i] = read();
Get(x); Get(y);
for(int i = 1; i <= N; i++) if(!vis2[i]) BFS(i);
for(int i = 1; i <= N; i++) putchar(vis[i] == 0 ? 'b' : 'r');
return 0;
}

cf547D. Mike and Fish(欧拉回路)的更多相关文章

  1. CF547D Mike and Fish

    欧拉回路,巧妙的解法. 发现每一个点$(x, y)$实际上是把横坐标和$x$和纵坐标$y$连一条线,然后代进去跑欧拉回路,这样里一条边对应了一个点,我们只要按照欧拉回路间隔染色即可. 注意到原图可能并 ...

  2. CF547D Mike and Fish 建图

    题意: 有点长→CF547DMike and Fish. 分析: 其实也没什么好分析的,我这也是看的题解. (不过,那篇题解好像文字的代码不太对劲) 这里直接说做法,正确性自证: 对输入的,将横.纵坐 ...

  3. 「CF547D」 Mike and Fish

    「CF547D」 Mike and Fish 传送门 介绍三种做法. \(\texttt{Solution 1}\) 上下界网络流 我们将每一行.每一列看成一个点. 两种颜色的数量最多相差 \(1\) ...

  4. CF 547 D. Mike and Fish

    D. Mike and Fish http://codeforces.com/contest/547/problem/D 题意: 给定平面上n个点,将这些点染成红或者蓝色,要求每行.每列红色点与蓝色点 ...

  5. Codeforces 247D Mike and Fish

    Mike and Fish 我们可以把这个模型转换一下就变成有两类点,一类是X轴, 一类是Y轴, 每个点相当于对应的点之间建一条边, 如果这条边变红两点同时+1, 变蓝两点同时-1. 我们能发现这个图 ...

  6. CodeForces - 547D: Mike and Fish (转化为欧拉回路)(优化dfs稠密图)(定向问题)

    As everyone knows, bears love fish. But Mike is a strange bear; He hates fish! The even more strange ...

  7. Codeforces.547D.Mike and Fish(思路 欧拉回路)

    题目链接 \(Description\) 给定平面上n个点,将这些点染成红or蓝色,要求每行.每列红色点与蓝色点数量的差的绝对值<=1.输出方案(保证有解). \(Solution\) 参考这 ...

  8. Codeforces 547D - Mike and Fish(欧拉回路)

    Codeforces 题目传送门 & 洛谷题目传送门 首先考虑将题目中的条件转化为图论的语言.看到"行""列",我们很自然地想到二分图中行.列转点,点转 ...

  9. Codeforces 547D Mike and Fish

    Description 题面 题目大意:有一个的网格图,给出其中的 \(n\) 个点,要你给这些点染蓝色或红色,满足对于每一行每一列都有红蓝数量的绝对值之差不超过1 Solution 首先建立二分图, ...

随机推荐

  1. struts2配置文件中的method={1}详解

    struts.xml中的配置: <!-- 配置用户模块的action --> <action name="user_*" class="userActi ...

  2. 如果将markdown视作一门编程语言可以做哪些有趣的事情?

    如题,然后就有了为解决这个好奇而开的项目:https://github.com/racaljk/llmd 源码主要是parser+interpreter,其中parser使用sundown,然后生成l ...

  3. HTTP上下文表单内容转为实体对象

    using ServiceStack.Web; using System; using System.Collections.Generic; using System.Linq; using Sys ...

  4. 怎样关闭adobe reader的自动更新

    https://jingyan.baidu.com/article/1612d5004390ebe20f1eee50.html

  5. js 原生JS实现轮播图

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. 查看 tensorflow 是GPU版本 还是CPU版本

    在Python环境中输入: import os from tensorflow.python.client import device_lib os.environ["TF_CPP_MIN_ ...

  7. JAVA之I/O 输入输出流详解

    简    介 如何在Java中进行文件的读写,Java IO流是必备的知识.这篇博文主要为您带来Java中的输入输出流的内容,包括文件编码.使用File类对文件和目录进行管理.字节流和字符流的基本操作 ...

  8. 洛谷 P4093 [HEOI2016/TJOI2016]序列(Cdq+dp)

    题面 luogu 题解 \(Cdq分治+dp\) \(mx[i],mn[i]\)分别表示第\(i\)位最大,最小能取到多少 那么有 \(j < i\) \(mx[j] \le a[i]\) \( ...

  9. Luogu P1801 黑匣子_NOI导刊2010提高(06)

    P1801 黑匣子_NOI导刊2010提高(06) 题目描述 Black Box是一种原始的数据库.它可以储存一个整数数组,还有一个特别的变量i.最开始的时候Black Box是空的.而i等于0.这个 ...

  10. Game of Credit Cards(贪心+思维)

    After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle betwe ...