题意:给定一个数字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. 纯tarjan poj2186

    tarjan,叙叙旧咯 #include<cstdio>#define maxn 50005int e[maxn],ne[maxn],be[maxn],all;int DFN[maxn], ...

  2. codeforces 333B - Chips

    注意:横向纵向交叉时,只要两条边不是正中的边(当n&1!=1),就可以余下两个chip. 代码里数组a[][]第二维下标 0表示横向边,1表示纵向边. #include<stdio.h& ...

  3. php服务器安装memcache

    https://pecl.php.net/get/memcache-3.0.8.tgz wget https://pecl.php.net/get/memcache-3.0.8.tgzgzip -d ...

  4. ActionBarSherlock的学习笔记(三) ------------ ActionBarSherlock中的overflow及item的点击事件

    定义一个自定义的ActionBar的title,并添加一个overflow的Action   Item. 代码实现 如下  : import android.os.Bundle; import and ...

  5. Oracle RAC 客户端连接负载均衡(Load Balance)

    实现负载均衡(Load Balance)是Oracle RAC最重要的特性之一,主要是把负载平均分配到集群中的各个节点,以提高系统的整体吞吐能力.通常情况下有两种方式来实现负载均衡,一个是基于客户端连 ...

  6. Oracle日常维护脚本

    1.正常停库流程     ps -ef|grep LOCAL=NO|cut -c 9-15|xargs kill -9      shutdown immediate; 2.备份数据库     bac ...

  7. 【转】ios app 应用内购买配置完全指南

    转自:http://blog.sina.com.cn/s/blog_4b55f6860100sbfb.html 第一印象觉得In-App Purchase(简称IAP)非常简单.Apple提供的大量文 ...

  8. PHP经验集锦

    最近刚刚完成手中的项目,比较闲.来这儿转转,把积累的一些技巧分享给大家!1.关于PHP重定向 方法一:header("Location: index.php"); 方法二:echo ...

  9. 兼容个个浏览器Cookie的读写

    function readCookie(name) {   var nameEQ = name + "=";   var ca = document.cookie.split('; ...

  10. HDU 4422 The Little Girl who Picks Mushrooms

    题意:一共有5座山,已知小女孩在n座山采了n篮蘑菇,如果n小于5则在其他的山里采了任意重量的蘑菇,给出每篮蘑菇的重量,她回去的时候会遇到仨女巫要她交出三篮蘑菇的重量和恰好为1024的倍数,否则就把她的 ...