传送门

题意:

给你一个黑白相间的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. Flutter 布局类组件:弹性布局(Flex)

    前言 弹性布局允许子组件按照一定比例来分配父容器空间,Flutter中的弹性布局主要通过Flex和Expanded来配合实现. Flex Flex组件可以沿着水平或垂直方向排列子组件,如果你知道主轴方 ...

  2. Java 安全之Weblogic 2018-2628&2018-2893分析

    Java 安全之Weblogic 2018-2628&2018-2893分析 0x00 前言 续上一个weblogic T3协议的反序列化漏洞接着分析该补丁的绕过方式,根据weblogic的补 ...

  3. 【Linux】用yum来下载rpm,而不安装

    方法一:yum yum命令本身就可以用来下载一个RPM包,标准的yum命令提供了--downloadonly(只下载)的选项来达到这个目的. $ sudo yum install --download ...

  4. 【ORA】Specified value of MEMORY_TARGET is too small, needs to be at least 3072M解决办法

    今天安装EM12C的时候遇到了一个报错: 修改好数据库中的参数大小后,重新启动报错 Specified value of MEMORY_TARGET is too small, needs to be ...

  5. 【RAC】运行root.sh的时候报错root.sh Oracle CRS stack is already configured and will be running under init(1M)

    环境:oracle10g 系统:CentOS6.4 开始的时候,在节点1上运行root.sh发现出现90s 的时候hang住了,结束掉,结局完事后,再次运行root.sh报错 WARNING: dir ...

  6. Hadoop 专栏 - MapReduce 入门

    MapReduce的基本思想 先举一个简单的例子: 打个比方我们有三个人斗地主, 要数数牌够不够, 一种最简单的方法可以找一个人数数是不是有54张(传统单机计算); 还可以三个人各分一摞牌数各自的(M ...

  7. 你这样用过DO循环吗?

    DATA: BEGIN OF text,        word1(4) TYPE c VALUE 'This',        word2(4) TYPE c VALUE 'is',         ...

  8. kubernetes 核心技术-Controller 控制器

    一.什么是Controller? Controller是在集群上管理和运行容器的对象,Controller是实际存在的,Pod是抽象的,主要创建管理pod 二.Pod和Controller的关系 Po ...

  9. 使用Swagger2

    一.Swagger2是什么? Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务. 优点: 及时性 (接口变更后,能够及时准确地通知相关前后端开 ...

  10. jmeter报Address already in use: connect

    jmeter报Address already in use: connect   用windows进行jmeter压测出现java.net.BindException: Address already ...