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 ...
随机推荐
- PHP开发调优clockwork工具
clockwork对于曾经做过C,c++代码调优的工程师并不会陌生,它可以指出代码中的潜在问题,比如内存泄漏,数组越界等.他也可以做profiler动作,指出系统各个函数的执行时间,性能瓶颈到底在哪里 ...
- VMware11安装Mac OS X10提示不可恢复错误解决
VMware11安装Mac OS X10提示不可恢复错误(vcpu-0)怎么办?本文将详细介绍如何解决VMware11安装Mac OS X10提示不可恢复错误. 工具/原料 VMware11 PC ...
- 漫游Kafka实战篇之搭建Kafka运行环境
接下来一步一步搭建Kafka运行环境. Step 1: 下载Kafka 点击下载最新的版本并解压. > tar -xzf kafka_2.9.2-0.8.1.1.tgz > cd kafk ...
- Replication in Kafka
Replication简介 Kafka中的Replication功能是为了给每个partition提供备份,当某个Broker挂掉时可以迅速实现故障切换(failover).我们可以在创建或修改top ...
- phpcms v9 搬家
1.修改/caches/configs/system.php里面所有和域名有关的,把以前的老域名修改为新域名. 2.进入后台设置--站点管理,对相应的站点的域名修改为新域名. 3.点击后台右上角的更新 ...
- phpcms还原被删除的栏目
1.在这个目录下/caches/bakup/default导出文件category.sql 2.登录网站的数据管理页面phpmyadmin 3.导入数据库选择category.sql 4.登陆网站后台 ...
- 收缩Oracle数据文件
最近有网友提到收缩Oracle数据文件的问题,这是DBA经常碰到的一个常见问题.通常我们需要收缩相应的数据文件以减少来自磁盘空间的压力以及提高数据库的整体性能.但这并非对于所有情形都是适用的,尤其是生 ...
- 用list<类>集合接收一个网址返回的一个类的集合的XML
JavaScriptSerializer serializer = new JavaScriptSerializer(); string json = Share.Helper.HttpRequest ...
- 实测 windows下nginx很不稳定,换成squid好多了
在windows server 2003 下尝试了号称支持50,000个并发连接数响应的nginx,结果相当不理想. 具体表现为时不时网页就卡住不动了,需要再刷新一次网页才能显示,而服务器cpu和内存 ...
- iframe根据子页面自动调整大小
//iframe高度自适应 function IFrameReSize(iframename) { var pTar = document.getElementById(iframename); if ...