传送门

题意:

给你一个黑白相间的1e9*1e9的棋盘,你需要从里面找出来由b个黑色的格子和w个白色的格子组成的连通器(就是你找出来的b+w个格子要连接在一起,不需要成环)。问你可不可以找出来,如果可以就先打印YES,再打印出所有格子的坐标,否则打印出NO。

题解:

参考博客

如果b和w相等的时候,那么就可以用棋盘的一行来表示。

对于不相等的情况:

如果max(w,b)>min(w,b)*3+1那么这样是找出不来符合条件的连通区域的。

看图中的红色部分你会知道只有这样十十的连接起来才是最大构成情况(这样写代码其实并不麻烦,你不需要一个十一个十的来拼接,可以看一下代码)

就这个十十的拼接可以就是一个十一个十的先拼接,之后多余出来的颜色格子,就用bfs添加到十的周围,但是代码确实太麻烦了

代码:

 1 #include<stdio.h>
2 #include<string.h>
3 #include<iostream>
4 #include<algorithm>
5 #include<map>
6 #include<math.h>
7 using namespace std;
8 typedef long long ll;
9 const int maxn=1e5+5;
10 const int mod=26;
11 const int INF=0x3f3f3f3f;
12 const int block=300;
13 int cnt1=0,cnt2=0;
14 int main()
15 {
16 int t;
17 scanf("%d",&t);
18 while(t--)
19 {
20 int w,b;
21 scanf("%d%d",&b,&w);//b黑色 w白色
22 if(max(w,b)>min(w,b)*3+1)
23 {
24 printf("NO\n");
25 continue;
26 }
27 if(w==b)
28 {
29 printf("YES\n");
30 for(int i=3; i<=w+b+2; ++i)
31 printf("5 %d\n",i);
32 }
33 else if(b<w)
34 {
35 printf("YES\n");
36 w=w-b-1;//将在一行的减掉
37 for(int i=4; i<=b*2+4; i++)
38 {
39 printf("4 %d\n",i);
40 if(w>0 && i&1)
41 {
42 printf("3 %d\n",i);
43 w--;
44 }
45 if(w>0 && i&1 )
46 {
47 printf("5 %d\n",i);
48 w--;
49 }
50 }
51 }
52 else if(b>w)
53 {
54 swap(b,w);
55 printf("YES\n");
56 w=w-b-1;//将在一行的减掉,再对这一行的某些部分添加格子变成十
57 for(int i=4; i<=b*2+4; i++)
58 {
59 printf("3 %d\n",i);
60 if(w>0 && i&1)
61 {
62 printf("2 %d\n",i);
63 w--;
64 }
65 if(w>0 && i&1 )
66 {
67 printf("4 %d\n",i);
68 w--;
69 }
70 }
71 }
72 }
73 return 0;
74 }

Codeforces Round #575 (Div. 3) E. Connected Component on a Chessboard的更多相关文章

  1. Codeforces Round #575 (Div. 3) E. Connected Component on a Chessboard(思维,构造)

    E. Connected Component on a Chessboard time limit per test2 seconds memory limit per test256 megabyt ...

  2. Codeforces Round #575 (Div. 3) 昨天的div3 补题

    Codeforces Round #575 (Div. 3) 这个div3打的太差了,心态都崩了. B. Odd Sum Segments B 题我就想了很久,这个题目我是找的奇数的个数,因为奇数想分 ...

  3. Codeforces Round #575 (Div. 3) 题解

    比赛链接:https://codeforc.es/contest/1196 A. Three Piles of Candies 题意:两个人分三堆糖果,两个人先各拿一堆,然后剩下一堆随意分配,使两个人 ...

  4. Codeforces Round #575 (Div. 3)

    本蒟蒻已经掉到灰名了(菜到落泪),希望这次打完能重回绿名吧...... 这次赛中A了三题 下面是本蒟蒻的题解 A.Three Piles of Candies 这题没啥好说的,相加除2就完事了 #in ...

  5. Codeforces Round #575 (Div. 3) D2. RGB Substring (hard version) 水题

    D2. RGB Substring (hard version) inputstandard input outputstandard output The only difference betwe ...

  6. Codeforces Round #575 (Div. 3) D1+D2. RGB Substring (easy version) D2. RGB Substring (hard version) (思维,枚举,前缀和)

    D1. RGB Substring (easy version) time limit per test2 seconds memory limit per test256 megabytes inp ...

  7. Codeforces Round #575 (Div. 3) C. Robot Breakout (模拟,实现)

    C. Robot Breakout time limit per test3 seconds memory limit per test256 megabytes inputstandard inpu ...

  8. Codeforces Round #575 (Div. 3) B. Odd Sum Segments (构造,数学)

    B. Odd Sum Segments time limit per test3 seconds memory limit per test256 megabytes inputstandard in ...

  9. Codeforces Round #575 (Div. 3) (A. Three Piles of Candies)(数学)

    A. Three Piles of Candies time limit per test1 second memory limit per test256 megabytes inputstanda ...

随机推荐

  1. MongoDB Sharding(二) -- 搭建分片集群

    在上一篇文章中,我们基本了解了分片的概念,本文将着手实践,进行分片集群的搭建 首先我们再来了解一下分片集群的架构,分片集群由三部分构成: mongos:查询路由,在客户端程序和分片之间提供接口.本次实 ...

  2. SpringSecurity应用篇

    前面吹水原理吹了一篇幅了,现在讲解下应用篇幅,前面说过,如果要用SpringSecurity的话要先导入一个包 <dependency> <groupId>org.spring ...

  3. Windows同一软件不同窗口如何快速切换

    windows快速切换应用的快捷键是Alt + Tab 这个快捷键可以在多个应用之间快速切换,但是软件多开时,而此时我只想在同一软件内的多个窗口切换,一切换好多个窗口扑面而来,我还要去用找并用鼠标点击 ...

  4. ps -p 进程号

    [root@ma ~]# ps -p 1 PID TTY TIME CMD 1 ? 00:00:01 init

  5. linux下删除文件夹及下面所有文件

    使用rm -rf 目录名字 命令即可 -r 就是向下递归,不管有多少级目录,一并删除-f 就是直接强行删除,不作任何提示的意思 rm 不带参数 只能删除文件 rm test.txt mkdir /us ...

  6. 面试官问我CAS,我一点都不慌

    文章以纯面试的角度去讲解,所以有很多的细节是未铺垫的. 文章中写到的处理线程安全的思路每一项技术都可以写出一篇文章,AQS.Synchronized.Atomic...周末肝起来!下周再来给大家安排! ...

  7. 【Android初级】使用TypeFace设置TextView的文字字体(附源码)

    在Android里面设置一个TextView的文字颜色和文字大小,都很简单,也是一个常用的基本功能.但很少有设置文字字体的,今天要分享的是通过TypeFace去设置TextView的文字字体,布局里面 ...

  8. 浅析鸿蒙中的 Gn 与 Ninja(一)

    目录: Ninja简介 make 的 3 个特性 举例说明Ninja 的用法 如何向构建工具 Ninja 描述构建图 后记 鸿蒙系统的编译构建是基于 Gn 和 Ninja 完成的,那么 Gn 和 Ni ...

  9. Linux下运行java报错:Error: Could not find or load main class SocketIOPropertites

    [root@node01 testfileio]# javac SocketIOPropertites.java && java Soc ketIOPropertitesError: ...

  10. Web自动化测试python环境中安装 --selenium安装、火狐和火狐驱动版本、谷歌和谷歌驱动版本、测试

    一.安装selenium Windows命令行(cmd)输入pip install selenium(无须指定版本默认最新)或 pip install selenium==3.141.0(可指定版本) ...