codeforces 644A Parliament of Berland
1 second
256 megabytes
standard input
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.
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 3
1 2
8 4 3
7 8 3
0 1 4
6 0 5
0 2 0
10 2 2
-1
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的更多相关文章
- Code Forces 644A Parliament of Berland
A. Parliament of Berland time limit per test1 second memory limit per test256 megabytes inputstandar ...
- codeforces 808G Anthem of Berland
codeforces 808G Anthem of Berland 题面 给定\(s\)串和\(t\)串,字符集是小写字母.\(s\)串中有些位置的值不确定,要求你确定这些位置上的值,使得\(t\)在 ...
- 【Codeforces 644A】Parliament of Berland
[链接] 我是链接,点我呀:) [题意] 题意 [题解] https://blog.csdn.net/V5ZSQ/article/details/70873661 看这个人的吧. [代码] #incl ...
- CodeForces 164 B. Ancient Berland Hieroglyphs 单调队列
B. Ancient Berland Hieroglyphs 题目连接: http://codeforces.com/problemset/problem/164/B Descriptionww.co ...
- 【模拟】Codeforces 691A Fashion in Berland
题目链接: http://codeforces.com/problemset/problem/691/A 题目大意: n个数0或1,要求恰好n-1个1,如果n为1则那个数一定要是1 题目思路: [模拟 ...
- Codeforces 808G Anthem of Berland - KMP - 动态规划
题目传送门 传送点I 传送点II 传送点III 题目大意 给定一个字符串$s$,和一个字符串$t$,$t$只包含小写字母,$s$包含小写字母和通配符'?'.询问$t$可能在$s$中出现最多多少次. 原 ...
- 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 ...
- CodeForces - 1C:Ancient Berland Circus (几何)
Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things ...
- Codeforces 691A Fashion in Berland
水题. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #includ ...
随机推荐
- 安装 Visual Stuidio 2010 失败
百思不得其解,尝试解压安装iso文件,解压都正常,怀疑Daemon Tools 是不是有问题? 最终问题还是定位在文件出问题了.SHA值不一样,囧!
- OpenERP 安装在Windows server上时间显示不对的解决办法
这个问题一直困扰着我,后台设置关于时区也参考过一些文章(如改配置文件),显示时间总是差8个小时,后来看了上面的文章后才搞定,虽然那个是解决OE7.0的,但原理一样: server\openerp\ad ...
- scala学习笔记(8): 列表的map,flatMap,zip和reduce
map,flatMap,zip和reduce函数可以让我们更容易处理列表函数. 1 map函数map将一个函数应用于列表的每一个元素并且将其作为一个新的列表返回.我们可以这样对列表的元素进行平方: s ...
- ThreadPoolExecutor使用和思考(上)-线程池大小设置与BlockingQueue的三种实现区别
工作中多处接触到了ThreadPoolExecutor.趁着现在还算空,学习总结一下. 前记: jdk官方文档(javadoc)是学习的最好,最权威的参考. 文章分上中下.上篇中主要介绍ThreadP ...
- 大数据分析的众包平台—Kaggle
众包(Jeff Howe,2006)是一种在互联网蓬勃发展的背景下产生的一种创新的生产组织形式.在这样的商业模式下,企业利用网络将工作分配出去,通过让更合适的人群参与其中来发现创意和解决技术问题.比较 ...
- MySQL与Oracle 差异比较之五存储过程&Function
存储过程&Function 编号 类别 ORACLE MYSQL 注释 1 创建存储过程语句不同 create or replace procedure P_ADD_FAC( id_fac ...
- 实用js+css多级树形展开效果导航菜单
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- android 中如何获取camera当前状态
/** * 测试当前摄像头能否被使用 * * @return */ public static boolean isCameraCanUse() { boolean canUse = true; Ca ...
- Bootstrap-select:美化原生select
官网:http://silviomoreto.github.io/bootstrap-select/ 1.下载zip 2.html代码 <select class="selectpic ...
- Maps
Maps.uniqueIndex()将列表转换为map //iterator各个元素作为Map.values, key为Function.apply返回值 Maps.uniqueIndex(ps.i ...