地址:http://codeforces.com/contest/764/problem/D

题目:

D. Timofey and rectangles
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.

Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.

Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length

The picture corresponds to the first example

Input

The first line contains single integer n (1 ≤ n ≤ 5·105) — the number of rectangles.

n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 ≤ x1 < x2 ≤ 109,  - 109 ≤ y1 < y2 ≤ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.

It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.

Output

Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.

Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 ≤ ci ≤ 4) — the color of i-th rectangle.

Example
input
8
0 0 5 3
2 -1 5 0
-3 -4 2 -1
-1 -1 2 0
-3 0 0 5
5 2 10 3
7 -3 10 2
4 -2 7 -1
output
YES
1
2
2
3
2
2
4
1
题意:给你n个边长都为奇数的长方形,问你能否使用四种颜色使所有相邻的长方形涂成不用颜色。
思路: 这题一定有解的,因为四色定理嘛,,然而比赛时想歪了,想先把长方形转化成图,相邻的长方形直接建一条无向边,然后用图的着色方法进行求解,这一点可以百度图的着色。
  然而发现建图的时间复杂度太高,然后就GG了。。。。(其实可以扫描线建图,不过感觉太麻烦了)
  做这题感觉智商被碾压了,其实这个题没有这么复杂。因为边长都为奇数,所以可以根据长方形的某一个顶点的坐标的奇偶进行染色。
  以左下顶点为例,进行反证:
    1.如果(a,b)与(c,d)涂了相同颜色,那么有a与c同奇偶,b与d同奇偶。(用长方形的左下顶点代表长方形)
    2.因为长方形相邻,有 奇数(第一个长方形的顶点坐标x)+奇数(任意一个长方形的边长)=偶数(另一个长方形的对应顶点)
    可以得出1与2相悖,所以假设不成立,其他情况同理可证。
  所以按照长方形的某一个顶点的坐标的奇偶进行染色即可,,,感觉智商被碾压0.0
 #include <bits/stdc++.h>

 using namespace std;

 #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e6+;
const int mod=1e9+; int main(void)
{
int n;cin>>n;
printf("YES\n");
for(int i=,a,b,c,d,ans;i<=n;i++)
{
scanf("%d%d%d%d",&a,&b,&c,&d);
if(a&)
{
if(b&)
ans=;
else
ans=;
}
else
{
if(b&)
ans=;
else
ans=;
}
printf("%d\n",ans);
} return ;
}

Codeforces Round #395 (Div. 2) D. Timofey and rectangles的更多相关文章

  1. 【分类讨论】Codeforces Round #395 (Div. 2) D. Timofey and rectangles

    D题: 题目思路:给你n个不想交的矩形并别边长为奇数(很有用)问你可以可以只用四种颜色给n个矩形染色使得相接触的 矩形的颜色不相同,我们首先考虑可不可能,我们分析下最多有几个矩形互相接触,两个时可以都 ...

  2. Codeforces Round #395 (Div. 2) C. Timofey and a tree

    地址:http://codeforces.com/contest/764/problem/C 题目: C. Timofey and a tree time limit per test 2 secon ...

  3. Codeforces Round #395 (Div. 2)B. Timofey and cubes

    地址:http://codeforces.com/contest/764/problem/B 题目: B. Timofey and cubes time limit per test 1 second ...

  4. 【树形DP】Codeforces Round #395 (Div. 2) C. Timofey and a tree

    标题写的树形DP是瞎扯的. 先把1看作根. 预处理出f[i]表示以i为根的子树是什么颜色,如果是杂色的话,就是0. 然后从根节点开始转移,转移到某个子节点时,如果其子节点都是纯色,并且它上面的那一坨结 ...

  5. Codeforces Round #395 (Div. 2)(未完)

    2.2.2017 9:35~11:35 A - Taymyr is calling you 直接模拟 #include <iostream> #include <cstdio> ...

  6. Codeforces Round #395 (Div. 2)

    今天自己模拟了一套题,只写出两道来,第三道时间到了过了几分钟才写出来,啊,太菜了. A. Taymyr is calling you 水题,问你在z范围内  两个序列  n,2*n,3*n...... ...

  7. Codeforces Round #395 (Div. 2)(A.思维,B,水)

    A. Taymyr is calling you time limit per test:1 second memory limit per test:256 megabytes input:stan ...

  8. Codeforces Round #395 (Div. 2) D

    Description One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On t ...

  9. Codeforces Round #395 (Div. 2) B

    Description Young Timofey has a birthday today! He got kit of n cubes as a birthday present from his ...

随机推荐

  1. sublime text 格式化html css 与显示函数列表

    sublime 格式化html css 1.ctrl + shift + p 2.输入install package,选择install package 3.输入:HTML-CSS-JS Pretti ...

  2. SVN版本库的备份、还原、移植(初级篇、中级篇和高级篇)

    版本库数据的移植:svnadmin dump.svnadmin load 导出: $svnlook youngest myrepos //查看到目前为止最新的版本号 $svnadmin dump my ...

  3. jquery图片上传前预览剪裁

    http://www.webmotionuk.co.uk/jquery/image_upload_crop.php http://keleyi.com/a/bjad/liuvpkke.htm 不错的d ...

  4. 利用Java编写简单的WebService实例

    使用Axis编写WebService比較简单,就我的理解,WebService的实现代码和编写Java代码事实上没有什么差别,主要是将哪些Java类公布为WebService. 以下是一个从编写測试样 ...

  5. DB2 SQL Error: SQLCODE=-668, SQLSTATE=57016错误解决方法

    这个错误是:表处于"装入暂挂"状态. 经多次尝试 总结方法: 1:reorg table <表>: 假如不好使 则下面方法 2,先前尝试装入(LOAD)此表失败.表的状 ...

  6. Django admin 注册多个app

    class game(models.Model): content = models.TextField() def __str__(self): return 'To game %s' % self ...

  7. UITabBarItem如何更改高度

    本文转载至 http://www.cocoachina.com/bbs/read.php?tid=255361 我目前有个UITabBar,改了它的高度.但是我切换页签后,这个UITabBar样式又变 ...

  8. Windows下将gvim8配置为Python IDE

    目录 1.准备工作 2.安装 3.配置 _vimrc 4.编写和编译运行程序 正文 Windows下将gvim配置为Python IDE 回到顶部 1.准备工作 将下面的安装包或者文件下载好 1) P ...

  9. 160627、你想知道的关于JavaScript作用域的一切

    JavaScript中有许多章节是关于scope的,但是对于初学者来说(甚至是一些有经验的JavaScript开发者),这些有关作用域的章节既不直接也不容易理解. 这篇文章的目的就是为了帮助那些想更深 ...

  10. 160719、Spring + Dubbo + zookeeper (linux) 框架搭建

    转载一篇博客,写得不错(至少我参考一下搭建成功了) 转载地址:http://my.oschina.net/wangt10/blog/522799 dubbo简介 节点角色说明: Provider: 暴 ...