A. Parliament of Berland
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

There are n parliamentarians in Berland. They are numbered with integers from 1 to n. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republicans.

New parliament assembly hall is a rectangle consisting of a × b chairs — a rows of b chairs each. Two chairs are considered neighbouring if they share as side. For example, chair number 5 in row number 2is neighbouring to chairs number 4 and 6 in this row and chairs with number 5 in rows 1 and 3. Thus, chairs have four neighbours in general, except for the chairs on the border of the hall

We know that if two parliamentarians from one political party (that is two Democrats or two Republicans) seat nearby they spent all time discussing internal party issues.

Write the program that given the number of parliamentarians and the sizes of the hall determine if there is a way to find a seat for any parliamentarian, such that no two members of the same party share neighbouring seats.

Input

The first line of the input contains three integers na and b (1 ≤ n ≤ 10 000, 1 ≤ a, b ≤ 100) — the number of parliamentarians, the number of rows in the assembly hall and the number of seats in each row, respectively.

Output

If there is no way to assigns seats to parliamentarians in a proper way print -1.

Otherwise print the solution in a lines, each containing b integers. The j-th integer of the i-th line should be equal to the index of parliamentarian occupying this seat, or 0 if this seat should remain empty. If there are multiple possible solution, you may print any of them.

Examples
input
3 2 2
output
0 3
1 2
input
8 4 3
output
7 8 3
0 1 4
6 0 5
0 2 0
input
10 2 2
output
-1
Note

In the first sample there are many other possible solutions. For example,

3 2
0 1

and

2 1
3 0

The following assignment

3 2
1 0

is incorrect, because parliamentarians 1 and 3 are both from Democrats party but will occupy neighbouring seats.

用1~n   n个数填a*b的矩阵,要求奇数与奇数不相邻,偶数与偶数不相邻,如果a*b<n输出-1

#include<stdio.h>
#include<string.h>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<math.h>
#include<algorithm>
#define LL long long
#define PI atan(1.0)*4
#define II __int64
#define DD double
#define MAX 10010
#define mod 10003
#define INF 0x3f3f3f
using namespace std;
int s[110][110];
int main()
{
int t,n,m,a,b,i,j,k;
while(scanf("%d%d%d",&n,&a,&b)!=EOF)
{
if(a*b<n)
{
printf("-1\n");
continue;
}
memset(s,0,sizeof(s));
i=1;j=1;k=1;
for(i=1;i<=a;i++)
{ if(i&1)
for(j=1;j<=b;j++)
{
if(k>n) break;
s[i][j]=k++;
}
else
for(j=b;j>=1;j--)
{
if(k>n) break;
s[i][j]=k++;
}
if(k>n) break;
}
for(i=1;i<=a;i++)
{
for(j=1;j<=b;j++)
printf("%d ",s[i][j]);
printf("\n");
}
}
return 0;
}

  

codeforces 644A Parliament of Berland的更多相关文章

  1. Code Forces 644A Parliament of Berland

    A. Parliament of Berland time limit per test1 second memory limit per test256 megabytes inputstandar ...

  2. codeforces 808G Anthem of Berland

    codeforces 808G Anthem of Berland 题面 给定\(s\)串和\(t\)串,字符集是小写字母.\(s\)串中有些位置的值不确定,要求你确定这些位置上的值,使得\(t\)在 ...

  3. 【Codeforces 644A】Parliament of Berland

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] https://blog.csdn.net/V5ZSQ/article/details/70873661 看这个人的吧. [代码] #incl ...

  4. CodeForces 164 B. Ancient Berland Hieroglyphs 单调队列

    B. Ancient Berland Hieroglyphs 题目连接: http://codeforces.com/problemset/problem/164/B Descriptionww.co ...

  5. 【模拟】Codeforces 691A Fashion in Berland

    题目链接: http://codeforces.com/problemset/problem/691/A 题目大意: n个数0或1,要求恰好n-1个1,如果n为1则那个数一定要是1 题目思路: [模拟 ...

  6. Codeforces 808G Anthem of Berland - KMP - 动态规划

    题目传送门 传送点I 传送点II 传送点III 题目大意 给定一个字符串$s$,和一个字符串$t$,$t$只包含小写字母,$s$包含小写字母和通配符'?'.询问$t$可能在$s$中出现最多多少次. 原 ...

  7. Codeforces 1 C. Ancient Berland Circus-几何数学题+浮点数求gcd ( Codeforces Beta Round #1)

    C. Ancient Berland Circus time limit per test 2 seconds memory limit per test 64 megabytes input sta ...

  8. CodeForces - 1C:Ancient Berland Circus (几何)

    Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things ...

  9. Codeforces 691A Fashion in Berland

    水题. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #includ ...

随机推荐

  1. HDU 1072 (不一样的入队条件) Nightmare

    之前的BFS都是需要一个标记数组,但这个题不一样,因为可能一个格子不止走一次. 那么我们就要寻找新的入队条件:left比上次经过的时候大才入队(left表示上次经过该点时剩余的时间). 为什么呢?我们 ...

  2. BZOJ 3624 免费道路

    第一反应:这不先0后1做并查集就行了吗? 然后WA了... 哦....啊?哦...233 如果按顺序做并查集,有些0的边可能很重要(只能由它作为0连起两个联通块),但并没有被选. 于是先按1做并查集, ...

  3. BZOJ 1406 密码箱

    直接两层枚举就行了. 避免排序可以用set. #include<iostream> #include<cstdio> #include<cstring> #incl ...

  4. android studio 加载第三方类库

    以引入Xutil包为例 1. 将Xutil包导入到module的libs目录下 2. File->project structure 还有一种方法是在libs目录下右键点击Add as libr ...

  5. 【解题报告】PKU 2318 TOYS AND PKU 2398 Toy Storage

    题目连接: http://poj.org/problem?id=2318     http://poj.org/problem?id=2398 两题类似的题目,2398是2318的升级版. 题目大概是 ...

  6. Java多线程-工具篇-BlockingQueue

    前言: 在新增的Concurrent包中,BlockingQueue很好的解决了多线程中,如何高效安全“传输”数据的问题.通过这些高效并且线程安全的队列 类,为我们快速搭建高质量的多线程程序带来极大的 ...

  7. Android 动画 6问6答

    1.view 动画有哪些需要注意的? 答:view动画 本身比较简单.http://www.cnblogs.com/punkisnotdead/p/5179115.html 看这篇文章的第五问就可以了 ...

  8. 64 位系统遇到未在本地计算机上注册 Microsoft.Jet.OLEDB.4.0

    本人写的.net程序部署在windowsserver 2003的操作系统上正常,部署到windows server 2008上时候报错“未在本地计算机上注册 Microsoft.Jet.OLEDB.4 ...

  9. socket基础函数(2)

    http://www.cnblogs.com/RascallySnake/archive/2013/07/11/3185071.html   一.select  winsock中 #include & ...

  10. Linux下常用软件

    一, vmtool安装, 进入桌面就后,如果没有看到VMware Tools光盘, 请点击VMware Station菜单栏上的“虚拟机”,然后选择“安装VMware Tools”,就可以在桌面上以看 ...