日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【CodeForces - 764D】Timofey and rectangles (四色定理 + 找规律 + 构造)

發布時間:2023/12/10 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【CodeForces - 764D】Timofey and rectangles (四色定理 + 找规律 + 构造) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

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?4different 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

題目大意:

? ??一個無限大的平面被分為無數個小正方形格子,一些相連的格子們可以組成矩形。給出左下角和右上角的坐標來表示該矩形(比如給出 0 0 5 3 即代表坐標為(0,0)開始到(5,3)之間的所有格子組成的矩形)。矩形的長和寬只能是奇數,給出一些矩形的坐標表示,要求寫程序為所有的矩形染色,相鄰的矩形不可染同種顏色(題中已經給出所有的矩形沒有兩兩相交的情況出現,且相鄰的條件為存在大于0長度的公共邊),如果存在染色方案則輸出YES并且輸出N個矩形的每種染色情況(如果存在多種情況輸出任意一種即可),如果不存在染色方案則輸出NO結束。

解題報告:

思路描述: 由于我們已知任意一個地圖都4可著色,因此第一行一定永遠是"YES"。關于著色方案,我們重點關注所有的邊均為奇數的條件。

由于所有的邊均為奇數,那么對于兩個相鄰的矩形,我們考慮其左下角的坐標:設其為A (x1,y1)和B (x2,y2);

  當A與B水平相鄰時,即如下圖所示(黃色為A,藍綠色為B,其中(x1,y1)以及(x2,y2)分別表示紅色的點和藍色的點):

  我們可以看出對于任意兩個相鄰的矩形,其必有(x1與x2)或(y1與y2)的奇偶性不一致(因為所有矩形邊長均為奇數),由于我們有4種染色方案(設為1 2 3 4),因此我們可以構造其染色情況為

[(x%2+2*(y%2))+4]%4+1(其中x和y表示該矩形左下角坐標),即可保證相鄰的矩形中沒有同色的情況(因為該染色情況下同色當且僅當x與y的奇偶性一致)。

AC代碼:

#include<iostream> #include<cmath> using namespace std; int main() {int n, a, b, c, d;ios::sync_with_stdio(false);cin >> n;cout <<"YES"<<endl;while(n--) {cin>>a>>b>>c>>d;int tmp = abs(a) % 2 + 2 * (abs(b) % 2);cout << tmp + 1 << endl;}return 0; }

總結:

[(x%2+2*(y%2))+4]%4+1這個公式也可以,這兩種構造的方式雖然結果不同但是都符合題意。注意負數取模問題!

總結

以上是生活随笔為你收集整理的【CodeForces - 764D】Timofey and rectangles (四色定理 + 找规律 + 构造)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。