UVaLive 7269 Snake Carpet (找规律,模拟)
题意:给定一个数字n,表示有n条蛇,然后蛇的长度是 i ,如果 i 是奇数,那么它只能拐奇数个弯,如果是偶数只能拐偶数个,1, 2除外,然后把这 n 条蛇,
放到一个w*h的矩阵里,要求正好放满,让你输出一个解,如果没有,输出0 0.
析:这个题目是找规律,先画一下前几个,画到第7个,就应该能找到规律,假设现在是第6个,并且是最后一个了,那么我们就可以在第5个基础上,在矩阵的
右边放上两列,正好是6,而且拐弯为偶数,如果是要放到7,那么就可以这样放,把第7条,放到第4行到第六列再向上一个,正好是7个,在右面放两排,
正好是6个,放上6即可。其他的都可以依次来推。
注意输出的顺序,是要按蛇的顺序来输出,蛇身不能断开。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
using namespace std ; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
const int dr[] = {0, 0, -1, 1};
const int dc[] = {-1, 1, 0, 0};
int n, m;
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
} void solve(){
if(n & 1) printf("%d %d\n", n/2+1, n);
else printf("%d %d\n", n/2, n+1);
puts("3 4"); puts("1 4 1 5"); puts("2 4 2 5 3 5"); puts("2 2 2 3 3 3 3 2"); puts("3 1 2 1 1 1 1 2 1 3");
if(n & 1) m = n;
else m = n - 1; for(int i = 6; i <= m; ++i){
int x = (i+1) / 2;
if(i & 1){
for(int j = 1; j < i; ++j)
printf("%d %d ", x, j);
printf("%d %d\n", x-1, i-1);
}
else{
int yy = i/2-1;
for(int j = yy; j > 0; --j)
printf("%d %d ", j, i);
for(int j = 1; j <= x; ++j)
printf("%d %d ", j, i+1);
printf("%d %d\n", x+1, i+1);
}
} if(n & 1) return ; for(int i = n/2; i > 0; --i)
printf("%d %d ", i, n);
for(int i = 1; i < n/2; ++i)
printf("%d %d ", i, n+1);
printf("%d %d\n", n/2, n+1);
} int main(){
while(scanf("%d", &n) == 1){
if(1 == n) printf("1 1\n1 1\n");
else if(2 == n){
printf("1 3\n"); printf("1 1\n"); printf("1 2 1 3\n");
}
else if(3 == n){
puts("2 3"); puts("1 2"); puts("1 3 2 3"); puts("1 1 2 1 2 2");
}
else if(4 == n){
puts("2 5"); puts("1 4"); puts("1 5 2 5"); puts("1 1 2 1 2 2"); puts("1 2 1 3 2 3 2 4");
}
else if(5 == n){
puts("3 5"); puts("3 4"); puts("1 4 1 5"); puts("2 4 2 5 3 5"); puts("2 2 2 3 3 3 3 2"); puts("3 1 2 1 1 1 1 2 1 3");
}
else solve();
}
return 0;
}
UVaLive 7269 Snake Carpet (找规律,模拟)的更多相关文章
- UVALive 7269 Snake Carpet (构造)
题目:传送门. 题意:构造出一个矩阵,使得矩阵含有n条蛇,每条蛇的长度是1到n,并且奇数长度的蛇有奇数个拐弯,偶数长度 的蛇有偶数个拐弯. 奇数和偶数分开构造,奇数可以是: 1357 3357 555 ...
- 洛谷 P1014 Cantor表【蛇皮矩阵/找规律/模拟】
题目描述 现代数学的著名证明之一是Georg Cantor证明了有理数是可枚举的.他是用下面这一张表来证明这一命题的: 1/1 1/2 1/3 1/4 1/5 … 2/1 2/2 2/3 2/4 … ...
- hdu 1998 奇数阶魔方(找规律+模拟)
应该不算太水吧. 17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 ...
- Codeforce-CodeCraft-20 (Div. 2)-B. String Modification (找规律+模拟)
Vasya has a string s of length n. He decides to make the following modification to the string: Pick ...
- Minimum Euler Cycle(找规律+模拟)
\(给你一个nnn个结点的完全有向图,求其字典序最小的欧拉回路,输出lll到rrr之间的结点为多少.\) 模拟一下n=5的时候 开始肯定是1-2-1-3-1-4-1-5 注意这个时候不能再从5到1,否 ...
- HDU 6121 Build a tree(找规律+模拟)
Build a tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)To ...
- 【8.30校内测试】【找规律模拟】【DP】【二分+贪心】
对于和规律或者数学有关的题真的束手无策啊QAQ 首先发现两个性质: 1.不管中间怎么碰撞,所有蚂蚁的相对位置不会改变,即后面的蚂蚁不会超过前面的蚂蚁或者落后更后面的蚂蚁. 2.因为所有蚂蚁速度一样,不 ...
- CF 996B World Cup 【找规律/模拟】
CF [题意]:圆形球场有n个门,Allen想要进去看比赛.Allen采取以下方案进入球场:开始Allen站在第一个门,如果当前门前面有人Allen会花费单位时间走到下一个门,如果没人Allen从这个 ...
- UVALive 6862 Triples (找规律 暴力)
Triples 题目链接: http://acm.hust.edu.cn/vjudge/contest/130303#problem/H Description http://7xjob4.com1. ...
随机推荐
- 1137. Bus Routes(dfs)
1137 做过一样的 怎么又忘了 再一次搜超时 不用回溯 #include <iostream> #include<cstdio> #include<cstring> ...
- iOS开发:插件记录
进入沙盒的插件 https://github.com/TongeJie/ZLGotoSandboxPlugin 图片提示的插件 https://github.com/ksuther/KSImageNa ...
- build path功能详解
在项目上右键>Build path>Config build path “web project”中,一般把"src"设置为source folder,把WEB-INF ...
- BZOJ3850: ZCC Loves Codefires
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3850 题解:类似于国王游戏,推一下相邻两个元素交换的条件然后排个序就可以了. 代码: #inc ...
- 由于管理员设置的策略,该磁盘处于脱机状态-Win 2008 R2
问题截图: 做了个小说网站www.114369.cn,使用的是云主机,系统是Win 2008 R2,进入服务器后发现磁盘有问题 只有c盘,没有d盘,提示:由于管理员设置的策略,该磁盘处于脱机状态 解决 ...
- kendo ui grid控件在选择行时如何取得所选行的某一列数据
$("#grid").kendoGrid({ dataSource: dataSrc, columns: [ { template: '#=material_id#', width ...
- TS数据结构分析
1.TS包得数据结构 2. // Transport packet headertypedef struct TS_packet_header{ unsigned sync_byte ...
- ubuntun安装ssh,并远程链接服务器操作
SSH是一种以安全.加密方式连接远程主机或服务器的方法.SSH服务器接受从有SSH的客户机的连接,允许操作者象在本地一样地登录系统.你可以用SSH从远程运行shell和X程序. (1)安装SSH服务器 ...
- 一天一个Java基础——数组
一天一个变成了几天一个,最近接受的新东西太多.太快,有好多需要blog的但没有时间,这些基础知识应该是要深挖并好好研究的,不应该每次都草草了事,只看个皮毛. 数组: JVM将数组存储在一个称为堆(he ...
- Python 3 加密简介
导读 Python 3 的标准库中是没多少用来解决加密的,不过却有用于处理哈希的库.在这里我们会对其进行一个简单的介绍,但重点会放在两个第三方的软件包:PyCrypto 和 cryptography ...