【CROC 2016 — QualificationA】【水题】nm棋盘填人奇偶不相邻
来源:互联网 发布:手机传软件 编辑:程序博客网 时间:2024/05/20 15:09
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 2 is 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.
The first line of the input contains three integers n, a 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.
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.
3 2 2
0 31 2
8 4 3
7 8 30 1 46 0 50 2 0
10 2 2
-1
In the first sample there are many other possible solutions. For example,
3 20 1
and
2 13 0
The following assignment
3 21 0
is incorrect, because parliamentarians 1 and 3 are both from Democrats party but will occupy neighbouring seats.
#include<stdio.h>#include<iostream>#include<string.h>#include<string>#include<ctype.h>#include<math.h>#include<set>#include<map>#include<vector>#include<queue>#include<bitset>#include<algorithm>#include<time.h>using namespace std;void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }#define MS(x,y) memset(x,y,sizeof(x))#define MC(x,y) memcpy(x,y,sizeof(x))#define MP(x,y) make_pair(x,y)#define ls o<<1#define rs o<<1|1typedef long long LL;typedef unsigned long long UL;typedef unsigned int UI;template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }const int N = 105, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;int casenum, casei;int num, n, m;int a[N][N];int main(){//num个人,n*m的棋盘while(~scanf("%d%d%d",&num,&n,&m)){MS(a, 0);int x = 1;int y = 2;for (int i = 1; i <= n; ++i){for (int j = 1; j <= m; ++j){if ((i + j) % 2 == 0){if (x <= num)a[i][j] = x;x += 2;}else{if (y <= num)a[i][j] = y;y += 2;}}}if (x <= num || y <= num)puts("-1");else for (int i = 1; i <= n; ++i){for (int j = 1; j <= m; ++j){printf("%d ", a[i][j]);}puts("");}}return 0;}
- 【CROC 2016 — QualificationA】【水题】nm棋盘填人奇偶不相邻
- 棋盘上放棋子(任意两个棋子不相邻)
- CROC 2016
- CROC 2016
- CROC 2016
- 解题报告:CROC 2016
- 不相邻组合问题
- 不相邻的组合
- Codeforces CROC 2016 - Elimination Round
- 方格填数【相邻两数互质】-DFS深度优先搜索
- 【CROC 2016 - Elimination RoundA】【水题 循环暴力】Amity Assessment 2x2华容道
- 【CROC 2016 - Elimination RoundC】【二分】Enduring Exodus 最小的人看守与羊距离
- CROC 2016 - Elimination Round C 二分
- CROC 2016 - Elimination Round(A)bfs
- CROC 2016 - Qualification-B. Processing Queries(队列)
- NM 多人博客
- 关于JQ获取同级元素问题(相邻、不相邻)
- nm
- 常用SQL查询语句
- 【April Fools Day Contest 2014H】【愚人节脑洞】A + B Strikes Back 连续提交5次才能AC
- Android音量控制调节
- bzoj 4238: 电压 dfs
- Python清屏小结
- 【CROC 2016 — QualificationA】【水题】nm棋盘填人奇偶不相邻
- 【CROC 2016 — QualificationB】【队列模拟】Processing Queries 按时间顺序处理任务 队列长度不超过siz
- java 中的printStackTrace()方法
- maven构建项目若干问题整理
- 问题 H: 2.4.5 Fractions to Decimals 分数化小数
- OC中Foundation框架字符串NSString和NSMutableString的使用
- android studio gradle 空项目
- ERROR 1840 (HY000) at line 24: GTID_PURGED can only be set when GTID_EXECUTED is empty.
- 第三周项目(4):百鸡问题