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
  1. 3 2 2
output
  1. 0 3
    1 2
input
  1. 8 4 3
output
  1. 7 8 3
    0 1 4
    6 0 5
    0 2 0
input
  1. 10 2 2
output
  1. -1
Note

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

  1. 3 2
    0 1

and

  1. 2 1
    3 0

The following assignment

  1. 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

  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<vector>
  4. #include<map>
  5. #include<queue>
  6. #include<stack>
  7. #include<cstdio>
  8. #include<string>
  9. #include<math.h>
  10. #include<algorithm>
  11. #define LL long long
  12. #define PI atan(1.0)*4
  13. #define II __int64
  14. #define DD double
  15. #define MAX 10010
  16. #define mod 10003
  17. #define INF 0x3f3f3f
  18. using namespace std;
  19. int s[110][110];
  20. int main()
  21. {
  22. int t,n,m,a,b,i,j,k;
  23. while(scanf("%d%d%d",&n,&a,&b)!=EOF)
  24. {
  25. if(a*b<n)
  26. {
  27. printf("-1\n");
  28. continue;
  29. }
  30. memset(s,0,sizeof(s));
  31. i=1;j=1;k=1;
  32. for(i=1;i<=a;i++)
  33. {
  34.  
  35. if(i&1)
  36. for(j=1;j<=b;j++)
  37. {
  38. if(k>n) break;
  39. s[i][j]=k++;
  40. }
  41. else
  42. for(j=b;j>=1;j--)
  43. {
  44. if(k>n) break;
  45. s[i][j]=k++;
  46. }
  47. if(k>n) break;
  48. }
  49. for(i=1;i<=a;i++)
  50. {
  51. for(j=1;j<=b;j++)
  52. printf("%d ",s[i][j]);
  53. printf("\n");
  54. }
  55. }
  56. return 0;
  57. }

  

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. git subtree有效管理公共第三方lib

    如果你的项目中有很多第三方的lib,你希望使用它,并且也希望可能对该lib做修改并且贡献到原始的项目中去,或者你的项目希望模块化,分为几个repo单独维护,那么git subtree就是一个选择.gi ...

  2. core—线程与IO

    CPU执行线程期间,从内存里调用指令,然后运行,这些指令有可能要从硬盘里面,网络里,读取数据.我们知道在计算机硬件体系中,从内存读取数据的速度会大于从硬盘或网络里面的速度.线程必须要等到硬盘里面的数据 ...

  3. 理解ASP.NET MVC的路由系统

    引言 路由,正如其名,是决定消息经由何处被传递到何处的过程.也正如网络设备路由器Router一样,ASP.NET MVC框架处理请求URL的方式,同样依赖于一张预定义的路由表.以该路由表为转发依据,请 ...

  4. (二)win7下用Intelij IDEA 远程调试spark standalone 集群

    关于这个spark的环境搭建了好久,踩了一堆坑,今天 环境: WIN7笔记本  spark 集群(4个虚拟机搭建的) Intelij IDEA15 scala-2.10.4 java-1.7.0 版本 ...

  5. 免费的WebService

    天气预报Web服务,数据来源于中国气象局 Endpoint :     http://www.webxml.com.cn/WebServices/WeatherWebService.asmx Disc ...

  6. 安装完eclipse,dbwear后,需要在他们解压文件.ini下加上你liux的jdk的安装路径,才能正常使用

    -vm/usr/java/jdk/jdk1.6.0_45/bin/java

  7. 使用svcutil.exe 生成服务的代码

    @echo offcall "c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"svcuti ...

  8. linux下的加减运算

    命令: echo rep 如果你有些编程方面的概念,最有意思的是用gdb,它可以进行进制转换,浮点数运算,数据类型占用字节数等等,很方便. (gdb) p 2+5$21 = 7(gdb) p 2/5$ ...

  9. ECSide标签属性说明之<ec:table>

    <ec:table>标签说明 ◆ 属性: tableId描述: 设置列表的唯一标识,默认为"ec",当一个页面内有多个ECSIDE列表时,必须为每个列表指定不同的tab ...

  10. -Xbootclasspath参数、java -jar参数运行应用时classpath的设置方法

    当用java -jar yourJarExe.jar来运行一个经过打包的应用程序的时候,你会发现如何设置-classpath参数应用程序都找不到相应的第三方类,报ClassNotFound错误.实际上 ...