AtCoder Regular Contest 080 D - Grid Coloring
地址:http://arc080.contest.atcoder.jp/tasks/arc080_b
题目:
D - Grid Coloring
Time limit : 2sec / Memory limit : 256MB
Score : 400 points
Problem Statement
We have a grid with H rows and W columns of squares. Snuke is painting these squares in colors 1, 2, …, N. Here, the following conditions should be satisfied:
- For each i (1≤i≤N), there are exactly ai squares painted in Color i. Here, a1+a2+…+aN=HW.
- For each i (1≤i≤N), the squares painted in Color i are 4-connected. That is, every square painted in Color i can be reached from every square painted in Color i by repeatedly traveling to a horizontally or vertically adjacent square painted in Color i.
Find a way to paint the squares so that the conditions are satisfied. It can be shown that a solution always exists.
Constraints
- 1≤H,W≤100
- 1≤N≤HW
- ai≥1
- a1+a2+…+aN=HW
Input
Input is given from Standard Input in the following format:
H W
N
a1 a2 … aN
Output
Print one way to paint the squares that satisfies the conditions. Output in the following format:
c11 … c1W
:
cH1 … cHW
Here, cij is the color of the square at the i-th row from the top and j-th column from the left.
思路:蛇形填数即可
#include <bits/stdc++.h> using namespace std; #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e6+;
const int mod=1e9+; int r,c,n,x,y,ans[][]; int main(void)
{
scanf("%d%d%d",&r,&c,&n);
x=,y=;
for(int i=,cnt;i<=n;i++)
{
scanf("%d",&cnt);
while(cnt--)
{
ans[x][y]=i;
if(y==c&&x%==)
y=c,x++;
else if(y==&&x%==)
y=,x++;
else if(x&)
y++;
else
y--;
}
}
for(int i=;i<=r;i++)
for(int j=;j<=c;j++)
printf("%d%c",ans[i][j],j==c?'\n':' ');
return ;
}
AtCoder Regular Contest 080 D - Grid Coloring的更多相关文章
- AtCoder Regular Contest 080 [CDEF]
C - 4-adjacent Time limit : 2sec / Memory limit : 256MB Problem Statement We have a sequence of leng ...
- AtCoder Regular Contest 080
手贱去开了abc,这么无聊.直接arc啊 C - 4-adjacent Time limit : 2sec / Memory limit : 256MB Score : 400 points Prob ...
- AtCoder Regular Contest 080 E - Young Maids
地址:http://arc080.contest.atcoder.jp/tasks/arc080_c 题目: E - Young Maids Time limit : 2sec / Memory li ...
- AtCoder Regular Contest 080 C - 4-adjacent
地址:http://arc080.contest.atcoder.jp/tasks/arc080_a 题目: C - 4-adjacent Time limit : 2sec / Memory lim ...
- AtCoder Regular Contest 080 E:Young Maids
题目传送门:https://arc080.contest.atcoder.jp/tasks/arc080_c 题目翻译 给你一个\(n\)的排列\(p\),一个空序列\(q\),你每次可以从\(p\) ...
- AtCoder Regular Contest 061 DSnuke's Coloring
http://arc061.contest.atcoder.jp/tasks/arc061_b 题意: H行W列的矩阵中,然后挖了n个洞,输出j(0-9)行,对于第i行输出,有多少个3*3区域中有i个 ...
- AtCoder Regular Contest 080 (ARC080) E - Young Maids 线段树 堆
原文链接http://www.cnblogs.com/zhouzhendong/p/8934377.html 题目传送门 - ARC080 E - Young Maids 题意 给定一个长度为$n$的 ...
- 【递归】【线段树】【堆】AtCoder Regular Contest 080 E - Young Maids
给你一个1~n的排列p,n是偶数,每次从中任选一对相邻的数出来,插到排列q的开头,如此循环,问你所能得到的字典序最小的排列q. 我们先确定q开头的两个数q1,q2,q1一定是p的奇数位的最小的数,而q ...
- AtCoder Regular Contest 095E - Symmetric Grid
$n \leq 12,m \leq 12$,$n$行$m$列小写字母,现可做无数次操作:交换两行:交换两列.问是否有可能把他变成中心对称的. 没有去想分组枚举的复杂度QAQ 行和列的操作顺序是随意的. ...
随机推荐
- RabbitMQ组成及原理介绍-3
rabbitmq作为成熟的企业消息中间件,实现了应用程序间接口调用的解耦,提高系统的吞吐量. 1.RabbitMQ组成 是由 LShift 提供的一个 Advanced Message Queuing ...
- H5学习之--前端和PHP后端的简单交互
最近在学习前端的东西,H5+CSS3+JS,又分别学习了原生JS和jQuery库,还有Bootstrap框架,因为我是做ios开发的,所以先熟悉WebApp相关的开发知识,其他的学习资料,网上有很多的 ...
- 【BZOJ1935/4822】[Shoi2007]Tree 园丁的烦恼/[Cqoi2017]老C的任务 树状数组
题意:两道题差不多,都是给你一堆平面上的点,每个点有权值,然后m次询问求某一矩形区域内的点权和 题解:先离散化,然后将询问拆成左右两条线段,然后将点和这些线段一起按x坐标排序,在y轴上维护树状数组.然 ...
- PS学习笔记 1---- 光和色的关系(上)
在HSB模式中,H(hues)表示色相,S(saturation)表示饱和度,B(brightness)表示亮度. HSB模式对应的媒介是人眼.HSB模式中S和B呈现的数值越高,饱和度明度越高,页面色 ...
- QQ空间的文艺打开方法
QQ空间被限制?打不开? 看看这里 第一种:http://user.qzone.qq.com/627911903 第二种:http://627911903.qzone.qq.com 第三种:http: ...
- JAVA编程你必须知道的那些英文单词
第一章: JDK(Java Development Kit) java开发工具包 JVM(Java Virtual Machine) java虚拟机 Javac 编译命令 ...
- Code Forces 21 A(模拟)
A. Jabber ID time limit per test 0.5 second memory limit per test 256 megabytes input standard input ...
- 背景图片拉伸显示CSS
.divbackimg{ width:150px; height:50px; background-image:url(./btn.png); -moz-background-size: 100% 1 ...
- HDU2855—Fibonacci Check-up
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2855 题目意思:求一个式子g[n]=∑C(n,k)*f[k],n很大,很明显是一个矩阵快速幂.可以打表 ...
- 【Python数据挖掘】回归模型与应用
线性回归 ( Linear Regression ) 线性回归中,只包括一个自变量和一个因变量,且二者的关系可用一条直线近似表示,这种回归称为一元线性回归. 如果回归分析中包括两个或两个以上的自变量, ...