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 行和列的操作顺序是随意的. ...
随机推荐
- LAMP环境搭建博客
背景: 公司要用到lamp环境,让我装,我就开始着手找资料,一般分为源码装和yum装,源码装很容易出错,所以我选择了yum装,. 服务器:aliyun服务器 centos6.8系统 按照第一个安装完 ...
- U盘重装Windows系统
1.制作一个U盘老毛桃或者大白菜 2.进入BIOS 3.Secure Boot-Disabled,作用是关闭微软的Secure BOOT,这个功能开启会导致不能识别U盘启动系统的安装 4.Lauch ...
- 控制iOS 7中的状态栏
本文转载至:http://blog.csdn.net/pucker/article/details/12112105 苹果终于发布了iOS 7正式版,大批的用户都已经纷纷进行了升级.如果App是由Xc ...
- erase操作
#include<iostream> #include <vector> int main() { std::vector<int> vec; vec.push_b ...
- zoj3696(泊松分布)
p(k)=(y^k) / (k!) * e^(-y) 其中的y就是平均值 k就是我们要求的大小. Alien's Organ Time Limit: 2 Seconds Memory Lim ...
- IOS 十位数0补齐
NSCalendar *calendar = [NSCalendar currentCalendar]; unsigned unitFlags = NSYearCalendarUnit | NSMon ...
- Android存储Json到本地,和读取本地Json
/** * 保存json到本地 * @param mActivity * @param filename * @param content */ public static File dir = ne ...
- oracle如何给指定用户修改密码?
1.用system用户登录, 2.执行如下sql: alter user 用户名 identified by 新密码; 比如alter user scott identified by 123456; ...
- 制作item和category的mvc视图总结
View层index.phg 代码: <?php use yii\helpers\Html; use yii\grid\GridView; use yii\widgets\Pjax; use f ...
- IDEA安装Python环境,并加入Anaconda环境
为什么做这个事情? 1.首先,Anaconda中已经有各种科学计算环境,包括后面安装的tensorflow 2.通过IDEA中配置就达到了Scala.Python.Java同时运行的目的. Intel ...