Codeforces Round #575 (Div. 3) E. Connected Component on a Chessboard
题意:
给你一个黑白相间的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的更多相关文章
- 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 ...
- Codeforces Round #575 (Div. 3) 昨天的div3 补题
Codeforces Round #575 (Div. 3) 这个div3打的太差了,心态都崩了. B. Odd Sum Segments B 题我就想了很久,这个题目我是找的奇数的个数,因为奇数想分 ...
- Codeforces Round #575 (Div. 3) 题解
比赛链接:https://codeforc.es/contest/1196 A. Three Piles of Candies 题意:两个人分三堆糖果,两个人先各拿一堆,然后剩下一堆随意分配,使两个人 ...
- Codeforces Round #575 (Div. 3)
本蒟蒻已经掉到灰名了(菜到落泪),希望这次打完能重回绿名吧...... 这次赛中A了三题 下面是本蒟蒻的题解 A.Three Piles of Candies 这题没啥好说的,相加除2就完事了 #in ...
- Codeforces Round #575 (Div. 3) D2. RGB Substring (hard version) 水题
D2. RGB Substring (hard version) inputstandard input outputstandard output The only difference betwe ...
- 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 ...
- Codeforces Round #575 (Div. 3) C. Robot Breakout (模拟,实现)
C. Robot Breakout time limit per test3 seconds memory limit per test256 megabytes inputstandard inpu ...
- 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 ...
- 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 ...
随机推荐
- oracle坚决不挂01(表,索引,视图的创建,修改,删除,查询)
考试快来了,来篇oracle干货,复习一下(挣扎一下) 废话不多说,开始写! 这篇是数据库对象的有关操作的总结! 数据库对象有熟悉的表,视图,索引,序列,同义词等(这个oracle东西真不少,小声bb ...
- Ossec 安装并配置邮件通知
Ossec 安装并配置邮件通知 目录 Ossec 安装并配置邮件通知 1. 介绍 2. 软硬件环境 3. 安装步骤 3.1 Server 3.2 Agent 3.3 配置邮件通知 4. 参考资料 1. ...
- DHCP最佳实践(二)
这是Windows DHCP最佳实践和技巧的最终指南. 如果您有任何最佳做法或技巧,请在下面的评论中发布它们. 在本指南(二)中,我将分享以下DHCP最佳实践和技巧. 从DHCP作用域中排除IP 了解 ...
- 【Linux】shell脚本实现多并发
情景 shell脚本的执行效率虽高,但当任务量巨大时仍然需要较长的时间,尤其是需要执行一大批的命令时.因为默认情况下,shell脚本中的命令是串行执行的.如果这些命令相互之间是独立的,则可以使用&qu ...
- 使用 gRPCurl 调试.NET 5的gPRC服务
介绍 你用过 Curl 吗?这个工具允许你通过 http 来发送数据,现在有一个适用于gGRPC的工具,gRPCurl,在本文中,我将介绍如何下载安装这个工具,然后通过这个工具调试我们.NET 5上面 ...
- python协程爬取某网站的老赖数据
import re import json import aiohttp import asyncio import time import pymysql from asyncio.locks im ...
- 使用.net中的API网关模式封装微服务
在本文中,我们将了解如何使用API网关模式来封装微服务并抽象出底层实现细节,从而允许使用者拥有进入我们系统的一致入口点. 为了构建和测试我们的应用程序,我们需要: 1.Visual Studio 20 ...
- QT串口助手(二):参数配置
作者:zzssdd2 E-mail:zzssdd2@foxmail.com 一.前言 主要实现功能 串口参数的配置:波特率.数据位.停止位.校验位 本机串口设备的查询与添加显示 串口设备的手动更新与打 ...
- 浅谈前端常用脚手架cli工具及案例
前端常用脚手架工具 前端有很多特定的脚手架工具大多都是为了特定的项目类型服务的,比如react项目中的reate-react-app,vue项目中的vue-cli,angular 项目中的angula ...
- vscode远程开发安装
https://www.cnblogs.com/xiaoqi/p/vs-code-remote.html ============================= https://blog.csdn ...