SGU - 409
题目链接:https://vjudge.net/contest/239445#problem/H
题目大意:输入n,k,有n*n* n*n的网格,要求每行每列刚好有k个*,每n*n的小方格内也刚好有k个*。
思路:不是自己写出来的,大概思路就是从第一排开始放,放满k个,然后跳到下一行,在这行的基础上加上n的位置开始放,放满k个,····一直下去,当到了第i行,并且i%n==1时,从上一个i%n==1的位置的下一个位置开始放,思路就是这样了
看代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
typedef long long ll;
using namespace std;
const ll mod=1e9+;
const int maxn=4e2+;
const int maxk=+;
const int maxx=1e4+;
const ll maxe=+;
#define INF 0x3f3f3f3f3f3f
int main()
{
int n,k,ac=,flag=;
int a[maxn][maxn];
memset(a,,sizeof(a));
cin>>n>>k;
for(int i=;i<=n*n;i++)
{
if(i>&&i%n==) {flag++;ac=flag;}//当到了i%n==1时,从上一个i%n==1的位置的下一个开始放,当然i=1除外
for(int l=ac;l<ac+k;l++)
{
int z=l;
if(z>(n*n)) z=z%(n*n);
a[i][z]=;
}
ac=ac+n;//下一行跳n个放
if(ac>n*n) ac=ac%(n*n); }
for(int i=;i<=n*n;i++)
{
for(int j=;j<=n*n;j++)
{
if(a[i][j]) cout<<"*";
else cout<<".";
}
cout<<endl;
}
return ;
}
下面是题目:
The Berland is in trouble again. After the recent elections All-Berland Great Duma has divided into two coalitions: Blue-eyed coalition and Red-eyed coalition. On the independence day the following question was raised: what will the national flag look like? Both coalitions agreed that the flag should be a square of N 2 x N 2 cells, each of them painted blue of red. To make the flag acceptable for both coalitions, the following requirements must be held:
- every row of the flag must contain exactly K blue cells
- every column of the flag must contain exactly K blue cells
- if we split the flag into squares of N x N cells (there will be N x N such squares), then every such square must contain exactly K blue cells. You are the chief programmers in Berland. So, making the flag model is your duty.
Input
First line of the input contains two integer numbers N and K (1 ≤ N ≤ 20, 0 ≤ K ≤ N2).
OutputOutput description of the desired flag. Print N2 lines which consist of N2 characters
'*'
and
'.'
, where
'*'
means blue cell and
'.'
means red cell. Output
"NO SOLUTION"
(without quotes), if there is no flag which satisfies both coalitions. If there are several solutions, output any of them.
Example(s)sample input
sample output
2 2
*..*
.**.
.**.
*..*sample input
sample output
3 1
*........
...*.....
......*..
.*.......
....*....
.......*.
..*......
.....*...
........*
SGU - 409的更多相关文章
- SGU 495. Kids and Prizes
水概率....SGU里难得的水题.... 495. Kids and Prizes Time limit per test: 0.5 second(s)Memory limit: 262144 kil ...
- ACM: SGU 101 Domino- 欧拉回路-并查集
sgu 101 - Domino Time Limit:250MS Memory Limit:4096KB 64bit IO Format:%I64d & %I64u Desc ...
- 【SGU】495. Kids and Prizes
http://acm.sgu.ru/problem.php?contest=0&problem=495 题意:N个箱子M个人,初始N个箱子都有一个礼物,M个人依次等概率取一个箱子,如果有礼物则 ...
- SGU 455 Sequence analysis(Cycle detection,floyd判圈算法)
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=455 Due to the slow 'mod' and 'div' operati ...
- SGU 422 Fast Typing(概率DP)
题目大意 某人在打字机上打一个字符串,给出了他打每个字符出错的概率 q[i]. 打一个字符需要单位1的时间,删除一个字符也需要单位1的时间.在任意时刻,他可以花 t 的时间检查整个打出来的字符串,并且 ...
- sgu 104 Little shop of flowers 解题报告及测试数据
104. Little shop of flowers time limit per test: 0.25 sec. memory limit per test: 4096 KB 问题: 你想要将你的 ...
- 树形DP求树的重心 --SGU 134
令一个点的属性值为:去除这个点以及与这个点相连的所有边后得到的连通分量的节点数的最大值. 则树的重心定义为:一个点,这个点的属性值在所有点中是最小的. SGU 134 即要找出所有的重心,并且找出重心 ...
- SGU 170 Particles(规律题)
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=170 解题报告:输入两个由'+'和'-'组成的字符串,让你判断第二个串能不能由第一个 ...
- SGU 179 Brackets light(生成字典序的下一个序列)
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=179 解题报告:输入一个合法的括号串,求出这个括号串的字典序的下一个串.(认为'(' ...
随机推荐
- centos下升级mysql5.5.47到5.7.14操作过程
一. 查看已安装Mysql基础信息通过mysql –V 查看下mysql版本可以通过命令find / -name mysql 得到下面信息 1.安装目录[root@jjxnhd-192-10 mysq ...
- 2013 蓝桥杯校内选拔赛 java本科B组(题目+答案)
一.标题:正则表示 正则表达式表示了串的某种规则或规律.恰当地使用正则表达式,可以使得代码简洁.事半功倍.java的很多API都支持正则表达式作为参数.其中的String.split就是这样. ...
- 拓扑排序 POJ 1094 Sorting It All Out
题意:给定N个字和M行他们之间的关系,要求输出他们的拓扑排序.此题采用边输入边检测的方式,如果发现环,就结束并输出当前行号:如果读取到当前行时,可以确定拓扑序列就输出,不管后面的输入(可能包含环路): ...
- POJ3256:Cow Picnic
Cow Picnic Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5432 Accepted: 2243 Descri ...
- Trie(前缀树/字典树)及其应用
Trie,又经常叫前缀树,字典树等等.它有很多变种,如后缀树,Radix Tree/Trie,PATRICIA tree,以及bitwise版本的crit-bit tree.当然很多名字的意义其实有交 ...
- php命名空间(namespace)内如何使用系统类
作者:ffsystem 使用命名空间,可以更方便的组织代码,以及代码复用.新写的一个项目引入了命名空间. 简介:使用namespace,使用__autoload自动导入类. 今天将以前的一段代码,加入 ...
- 对spring、AOP、IOP的理解 (转)
spring 的优点?1.降低了组件之间的耦合性 ,实现了软件各层之间的解耦2.可以使用容易提供的众多服务,如事务管理,消息服务等3.容器提供单例模式支持4.容器提供了AOP技术,利用它很容易实现如权 ...
- QTP使用outlook发送邮件
'发邮件 Dim objOutlook Dim objOutlookMsg Dim olMailItem ' Create the Outlook object and the new mail ...
- HttpApplication 对象的创建过程及HttpModule过滤器的内部实现过程
最近通过Reflector学习了一下asp.net内部的原理,做做笔记,方便以后查阅. 先看下HttpApplication 对象的创建过程 从IHttpHandler applicationInst ...
- Linux Shell 脚本提示:sleep: 无效的时间间隔"1s\r"
问题:编写好的 Shell 脚本在 Linux 执行时提示报错:sleep: 无效的时间间隔"1s\r" : 原因:若再三确认脚本没有写错,可能是原脚本文件在 Win 下创建编写好 ...