传送门

题意:

给你一个黑白相间的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. python学习笔记 | 国内常用源镜像地址

    各镜像列表 清华:https://pypi.tuna.tsinghua.edu.cn/simple 阿里云:http://mirrors.aliyun.com/pypi/simple/ 中国科技大学 ...

  2. docker 创建数据卷容器

    数据卷容器 --volumes-from 容器名/id 先起一个容器 docker run -it --name docker01 centos 然后同步 docker01 的数据卷 --volume ...

  3. window10系统安装

    准备工作: 一个U盘,大概8GB左右的存储,用于存放windows镜像文件与驱动精灵离线版网卡驱动以及相关的应用应用软件等. window10镜像文件(iso文件) 微PE工具软件 软件下载: 前提: ...

  4. px转rem的填坑之路

    这是要为一个vue项目做自适应,设计稿是1920*1080的,要适应各种手机.ipad.3840*2160的超大屏,所以就选择了rem,包用的是 postcss-pxtorem 在适配的时候遇到了很多 ...

  5. Android 中使用 config.gradle

    各位同学大家好,当然了如果不是同学,那么大家也同好.哈哈. 大家知道config.gradle 是什么吗?我也不知道.开个完笑,其实config.gradle 就是我们为了统一gradle 中的各种配 ...

  6. java 记录数据持续变化时间

    1.需求:获取count为null和不为null的持续变化 [{count=0, time=0}, {count=10, time=1000}, {count=20, time=2000}, {cou ...

  7. Spring Bean详解

    Spring Bean 在Spring的应用中,Spring IoC容器可以创建.装配和配置应用组件对象,这里的组件对象称为Bean. Bean的配置 Spring可以看作一个大型工厂,用于生产和管理 ...

  8. 注解 @AutoConfigureBefore 和 @AutoConfigureAfter 的用途

    注解 @AutoConfigureBefore 和 @AutoConfigureAfter 的用途 介绍: 如果你想将在SpringBoot项目中的配置类进行排序,那么用到spring-boot-au ...

  9. .NET Core 问题记录

    前言: 最近在项目中遇到了遇到了写部署步骤过多的问题,为了减少.net core项目部署步骤:需要对一些基础问题进行验证: 如端口设置.单页应用程序(angluar)合并部署方式等相关问题,特将解决过 ...

  10. CACTI优化-流量接口统计total输入和输出流量数据

    看图,没有优化前(没有显示流入和流出的总流量是多少): 优化后(有显示流入和流出总流量统计): 如何实现呢?本节就是处理的过程小结.第一步:登陆cacti管理平台进入控制台->模板->图形 ...