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. css圣杯布局、等高布局

    所谓圣杯布局,就是自适应浏览器的分辨率,也称双飞翼布局. 例子: <style> body{margin:0;} .center{height:600px;background:#f60; ...

  2. Swustoj题目征集计划

    SWUST OJ题目征集计划   鉴于SWUST OJ长时间没有新题添加,题目数量和类型有限,同时也为加强同学们之间的算法交流,享受互相出题AC的乐趣,提高算法水平,现在启动题目征集计划啦~ 当你遇到 ...

  3. volley(5) 参数total_remain:totalqty, data:[{ bar_status:XX , bar_code: "XX",bar_remain:XX, bar_whcode:"XX" , bar_prodcode:"XX",bar_id:XX,bar_location: "XX", pr_detail: "XX" , bar_batchcode:method:POST

    1. 来源  : WHCombineBatchFragment.java 2. 部分代码 WHCombineBatchFragmentCombineBtnClickEvent whc2;private ...

  4. zipline

    history 多只股票时会返回某几只股票停牌没数据 if not symbol(stock) in data: 聚宽 多只股票如果某几只没有发行 600485: nan 多只股票如果某几只停牌 60 ...

  5. JDK,JRE,JVM区别与联系-理解与概括

    我们利用JDK(调用JAVA API)开发了属于我们自己的JAVA程序后,通过JDK中的编译程序(javac)将我们的文本java文件编译成JAVA字节码,在JRE上运行这些JAVA字节码,JVM解析 ...

  6. JavaScript中Element与Node的区别,children与childNodes的区别

    关于Element跟Node的区别,cilldren跟childNodes的区别很多朋友弄不清楚,本文试图让大家明白这几个概念之间的区别. Node(节点)是DOM层次结构中的任何类型的对象的通用名称 ...

  7. 学习java之HashMap和TreeMap

    HashMap和TreeMap是Map接口的两种实现,ArrayDeque和LinkedList是Queue接口的两种实现方式.下面的代码是我今天学习这四个数据结构之后写的.还是不熟悉,TreeMap ...

  8. Linux编程(获取系统时间)

    #include <stdio.h> #include <time.h> int main() { time_t now; struct tm *w; time(&no ...

  9. (转)python 优先队列

    #!/usr/bin/python from Queue import Queue from Queue import PriorityQueue a1='a1' a2='a2' a3='a3' a4 ...

  10. 深入学习Struts2

    本部分主要介绍struts.xml的常用配置. 1.1.    包配置: Struts2框架中核心组件就是Action.拦截器等,Struts2框架使用包来管理Action和拦截器等.每个包就是多个A ...