Codeforces#302-B-Sea and Islands-水题
来源:互联网 发布:java选择文件保存路径 编辑:程序博客网 时间:2024/06/05 19:45
http://codeforces.com/contest/544/problem/B
题意:
给你n,k;
在n*n的矩阵插入m个L,使得最后有k块 连在一起的L集合;
如果2个L在上下左右的边上相邻则算为连在一起 (对角线不算)
最大的块数就是
if (n%2) big=n/2 * n + (n+1)/2; else big=n*n/2;
然后 间隔地插入就好了。。。插够了剩下的空位直接全部输出
#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <algorithm>#include <iostream>#include <queue>#include <map>#include <set>#include <vector>using namespace std;int main(){ int i,j; int n,m; scanf("%d%d",&n,&m); int big; if (n%2) big=n/2 * n + (n+1)/2; else big=n*n/2; if ( m>big) { printf("NO\n"); return 0; } printf("YES\n"); int cun=0; j=0; for (i=1;i<=n;i++) { if (m==cun) break; if (i%2) { for (j=1;j<=n;j++) { if (j%2) { printf("L"); cun++; if (cun==m) break; } else printf("S"); } if (cun==m) break; } else { for (j=1;j<=n;j++) { if (j%2==0) { printf("L"); cun++; if (cun==m) break; } else printf("S"); } if (cun==m) break; } printf("\n"); } for (j++;j<=n;j++) { printf("S"); } printf("\n"); for (i++;i<=n;i++) { for (j=1;j<=n;j++) { printf("S"); } printf("\n"); } return 0; }
0 0
- Codeforces#302-B-Sea and Islands-水题
- Codeforces Round #302 (Div. 2) B. Sea and Islands
- codeforces-544B-Sea and Islands【构造】
- Codeforces 544B - Sea and Islands(构造)
- Codeforces Round #302 (Div. 2) A.Set of Strings&B.Sea and Islands&C.Writing Code
- Codeforces544B:Sea and Islands
- Codeforces Round #380 Div. 1 B. Sea Battle(贪心)
- codeforces 302B. Eugeny and Play List
- codeforces 302 B. Eugeny and Play List
- codeforces 302B - Eugeny and Play List
- codeforces 302B. Eugeny and Play List
- Codeforces 459B Pashmak and Flowers(水题)
- Codeforces 463B Caisa and Pylons(水题)
- codeforces 557B Pasha and Tea-水题
- CodeForces 525B Pasha and String 水题
- Codeforces 599B Spongebob and Joke 【水题】
- CodeForces 703B Mishka and trip【水题】
- Codeforces 401B Sereja and Contests【水题】
- 【开发纪事】简易版音乐播放器(四大组件)
- Spark storage系列------3.Spark cache数据块之后对后继Job任务调度的影响,以及后继Job Task执行的影响
- C++ builder TTS5.1实现语音播放 生成wav文件
- RabbitMQ消息队列(六):使用主题进行消息分发
- pt-table-checksum数据一致性校验工具和pt-table-sync数据同步工具解析
- Codeforces#302-B-Sea and Islands-水题
- touch的理解
- 一个比较有意思的算法题,猴子选大王
- PCM 音量调节
- memcached了解使用和常用命令详解
- RabbitMQ消息队列(七):适用于云计算集群的远程调用(RPC)
- PLSQL初级爬坑篇
- svn错误信息汇总
- Android 之屏幕适配