Minieye杯第十五届华中科技大学程序设计邀请赛网络赛D Grid(简单构造)
链接:https://ac.nowcoder.com/acm/contest/560/D
来源:牛客网
题目描述
Each grid is black initially. You can turn some grids into white.
A grid A(x,y) is connected with grid B if the coordinate of B is (x+1, y),(x-1, y),(x, y+1) or (x, y-1).
And your task is to propose a plan of the gird which has exactly n connected components of black part.
If there is no valid plan containing n connected components of black part, output -1.
输入描述:
Three integers h, w, n(1≤h,w≤200,1≤n≤109)(1≤h,w≤200,1≤n≤109) as described above.
输出描述:
Print h rows and w columns, '#' represents a black grid and '*' represents a white grid, indicating your solution.
输出
#*#*#*#*#* 题意:
给你一个高h,宽w,一个数量k。让你构建一个h*w的数组,使之只含有两种元素,黑和白,即#和*
要求黑色块的联通集个数刚好是K。 思路:显然每一行中交叉填黑白,换行后每一行交叉填白黑,这样可以让这个h*w的数组中出现最大数量的黑色的联通块。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=;while(b){if(b%)ans=ans*a%MOD;a=a*a%MOD;b/=;}return ans;}
inline void getInt(int* p);
const int maxn=;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
ll h,w,n;
int main()
{
//freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
//freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
gbtb;
cin>>h>>w>>n;
ll cnt=0ll;
int flag=;
repd(i,,h)
{
if(flag)
{
cnt+=(w+)/;
}else
{
cnt+=(w-)/;
}
flag=!flag;
}
if(cnt>=n)
{
flag=;
repd(i,,h)
{
if(flag)
{
repd(j,,w)
{
if(j&)
{
if(n>)
{
cout<<"#";
n--;
}else
{
cout<<"*";
} }else
{
cout<<"*";
}
}
cout<<endl;
}else
{
repd(j,,w)
{
if(j&)
{
cout<<"*";
}else
{
if(n>)
{
cout<<"#";
n--;
}else
{
cout<<"*";
} }
}
cout<<endl;
}
flag=!flag;
}
}else
{
cout<<-<<endl;
} return ;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '');
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * - ch + '';
}
}
else {
*p = ch - '';
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * + ch - '';
}
}
}
Minieye杯第十五届华中科技大学程序设计邀请赛网络赛D Grid(简单构造)的更多相关文章
- Minieye杯第十五届华中科技大学程序设计邀请赛网络赛 部分题目
链接:https://pan.baidu.com/s/12gSzPHEgSNbT5Dl2QqDNpA 提取码:fw39 复制这段内容后打开百度网盘手机App,操作更方便哦 D Grid #inc ...
- H-Modify Minieye杯第十五届华中科技大学程序设计邀请赛现场赛
题面见 https://ac.nowcoder.com/acm/contest/700#question 题目大意是有n个单词,有k条替换规则(单向替换),每个单词会有一个元音度(单词里元音的个数)和 ...
- Minieye杯第十五届华中科技大学程序设计邀请赛现场同步赛 I Matrix Again
Minieye杯第十五届华中科技大学程序设计邀请赛现场同步赛 I Matrix Again https://ac.nowcoder.com/acm/contest/700/I 时间限制:C/C++ 1 ...
- 第十四届华中科技大学程序设计竞赛决赛同步赛 A - Beauty of Trees
A - Beauty of Trees 题意: 链接:https://www.nowcoder.com/acm/contest/119/A来源:牛客网 Beauty of Trees 时间限制:C/C ...
- 第十四届华中科技大学程序设计竞赛决赛同步赛 F Beautiful Land(01背包,背包体积超大时)
链接:https://www.nowcoder.com/acm/contest/119/F来源:牛客网 Beautiful Land 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1 ...
- 第十四届华中科技大学程序设计竞赛 K Walking in the Forest【二分答案/最小化最大值】
链接:https://www.nowcoder.com/acm/contest/106/K 来源:牛客网 题目描述 It's universally acknowledged that there'r ...
- 第十四届华中科技大学程序设计竞赛 J Various Tree【数值型一维BFS/最小步数】
链接:https://www.nowcoder.com/acm/contest/106/J 来源:牛客网 题目描述 It's universally acknowledged that there'r ...
- 第十四届华中科技大学程序设计竞赛 C Professional Manager【并查集删除/虚点】
题目描述 It's universally acknowledged that there're innumerable trees in the campus of HUST. Thus a pro ...
- 第十四届华中科技大学程序设计竞赛 B Beautiful Trees Cutting【组合数学/费马小定理求逆元/快速幂】
链接:https://www.nowcoder.com/acm/contest/106/B 来源:牛客网 题目描述 It's universally acknowledged that there'r ...
随机推荐
- Python之celery的简介与使用
celery的简介 celery是一个基于分布式消息传输的异步任务队列,它专注于实时处理,同时也支持任务调度.它的执行单元为任务(task),利用多线程,如Eventlet,gevent等,它们能 ...
- [转]GitLab-CI与GitLab-Runner
本文转自:https://www.jianshu.com/p/2b43151fb92e 一.持续集成(Continuous Integration) 要了解GitLab-CI与GitLab Runne ...
- [前端]css前端样式的模块化
css样式文件结构( 模块划分的单入口 ) common|_ _ _ _ _ _reset.css|_ _ _ _ _ _common.css 公用样式 libs|_ _ _ _ _ _bootstr ...
- 微信小程序picker的坑
js文件: Companyarr: [{ id: '公司id1', companyname: "公司1的名字" }, { id: '公司id2', companyname: &qu ...
- vue中computed计算属性与methods对象中的this指针
this 指针问题 methods与computed中的this指针 应该指向的是它们自己,可是为什么this指针却可以访问data对象中的成员呢? 因为new Vue对象实例化后data中的成员和c ...
- Windows中通过命令行新建文件夹、新建文件,和一些常用命令
新建文件 和Linux不太一样,Linux中的touch和vi命令创建新文件的方法都不能用了,在windows命令行下得用type nul>文件名.后缀名来创建: F:\study\vue\wo ...
- 左侧固定,右侧自适应的布局方式理解margin负值理论
一.浮动布局 1.先让固定宽度的div浮动!使其脱离文档流.2.margin-left的值等于固定div的宽度相等. .aside{ float: left; width: 200px; backgr ...
- bitset中_Find_first()与_Find_next()函数
bitset中_Find_first()与_Find_next()函数 很有趣但是没怎么有用的两个函数. _Find_fisrt就是找到从低位到高位第一个1的位置 #include<bits/s ...
- 商汤科技汤晓鸥:其实不存在AI行业,唯一存在的是“AI+“行业
https://mp.weixin.qq.com/s/bU-TFh8lBAF5L0JrWEGgUQ 9 月 17 日,2018 世界人工智能大会在上海召开,在上午主论坛大会上,商汤科技联合创始人汤晓鸥 ...
- ionic3 Alert组件的使用方法
html页面 <button ion-button color="danger" class="button-block button-round-ios" ...