题意:给定一个数字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 (找规律,模拟)的更多相关文章

  1. UVALive 7269 Snake Carpet (构造)

    题目:传送门. 题意:构造出一个矩阵,使得矩阵含有n条蛇,每条蛇的长度是1到n,并且奇数长度的蛇有奇数个拐弯,偶数长度 的蛇有偶数个拐弯. 奇数和偶数分开构造,奇数可以是: 1357 3357 555 ...

  2. 洛谷 P1014 Cantor表【蛇皮矩阵/找规律/模拟】

    题目描述 现代数学的著名证明之一是Georg Cantor证明了有理数是可枚举的.他是用下面这一张表来证明这一命题的: 1/1 1/2 1/3 1/4 1/5 … 2/1 2/2 2/3 2/4 … ...

  3. hdu 1998 奇数阶魔方(找规律+模拟)

    应该不算太水吧. 17  24   1   8  15   23   5   7  14  16    4   6  13  20  22   10  12  19  21   3   11  18 ...

  4. 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 ...

  5. Minimum Euler Cycle(找规律+模拟)

    \(给你一个nnn个结点的完全有向图,求其字典序最小的欧拉回路,输出lll到rrr之间的结点为多少.\) 模拟一下n=5的时候 开始肯定是1-2-1-3-1-4-1-5 注意这个时候不能再从5到1,否 ...

  6. HDU 6121 Build a tree(找规律+模拟)

    Build a tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)To ...

  7. 【8.30校内测试】【找规律模拟】【DP】【二分+贪心】

    对于和规律或者数学有关的题真的束手无策啊QAQ 首先发现两个性质: 1.不管中间怎么碰撞,所有蚂蚁的相对位置不会改变,即后面的蚂蚁不会超过前面的蚂蚁或者落后更后面的蚂蚁. 2.因为所有蚂蚁速度一样,不 ...

  8. CF 996B World Cup 【找规律/模拟】

    CF [题意]:圆形球场有n个门,Allen想要进去看比赛.Allen采取以下方案进入球场:开始Allen站在第一个门,如果当前门前面有人Allen会花费单位时间走到下一个门,如果没人Allen从这个 ...

  9. UVALive 6862 Triples (找规律 暴力)

    Triples 题目链接: http://acm.hust.edu.cn/vjudge/contest/130303#problem/H Description http://7xjob4.com1. ...

随机推荐

  1. 对于oracle监听器的配置

    oracle 的 net configuration  assist中配置完第一项的监听程序配置(对应文件listener.ora)之后,还要重新配置下第三项本地网络服务名配置(对应文件tnsname ...

  2. POJ 3233 矩阵乘法

    题意:求解A+A^2+...+A^k 题解: 1)利用通和公式,原式=(A^k+1 - A)(A - O)^-1 时间复杂度O(n^3lgk) 2)递归求解,A+A^2+...+A^k=(A+A^2+ ...

  3. POJ2135 最小费用最大流模板题

    练练最小费用最大流 此外此题也是一经典图论题 题意:找出两条从s到t的不同的路径,距离最短. 要注意:这里是无向边,要变成两条有向边 #include <cstdio> #include ...

  4. bzoj2794

    这题我得到一个经验,bool型的dp一定要想办法把bool去掉来表示更多的东西(1933也是这个道理) 暴力大家都会,这里有两个限制条件 一个限制条件我们可以排序不断加入,另一个呢 我们可以用f[i] ...

  5. UVA 11374 Airport Express(最短路)

    最短路. 把题目抽象一下:已知一张图,边上的权值表示长度.现在又有一些边,只能从其中选一条加入原图,使起点->终点的距离最小. 当加上一条边a->b,如果这条边更新了最短路,那么起点st- ...

  6. MVC&WebForm对照学习:ajax异步请求

    写在前面:由于工作需要,本人刚接触asp.net mvc,虽然webform的项目干过几个.但是也不是很精通.抛开asp.net webform和asp.net mvc的各自优劣和诸多差异先不说.我认 ...

  7. 【Java】Java处理double相加的结果异常

    方式一(四舍五入):保留两位小数 double f = 111231.5585; BigDecimal b = new BigDecimal(f); double f1 = b.setScale(2, ...

  8. 【转】使用 Auto Layout 的典型痛点和技巧

    layoutIfNeeded()强制立刻更新布局 原文网址:http://www.jianshu.com/p/0f031606e5f2 官方文档:Auto Layout Guide 加上去年WWDC上 ...

  9. POJ 1716 Integer Intervals

    题意:给出一些区间,求一个集合的长度要求每个区间里都至少有两个集合里的数. 解法:贪心或者差分约束.贪心的思路很简单,只要将区间按右边界排序,如果集合里最后两个元素都不在当前区间内,就把这个区间内的最 ...

  10. [Everyday Mathematics]20150106

    (1). 设 $f\in C[0,T]$, $g$ 是 $T$-周期函数, 试证: $$\bex \vlm{n}\int_0^T f(x)g(nx)\rd x=\frac{1}{T}\int_0^T ...