题意:给定一个数字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. Base64 Encoding / Decoding in Node.js

    Posted on April 20th, 2012 under Node.js Tags: ASCII, Buffer, Encoding, node.js, UTF So how do you e ...

  2. The secret code

    The secret code Input file: stdinOutput file: stTime limit: 1 sec Memory limit: 256 MbAfter returnin ...

  3. iOS开发:Swift多线程NSThread的使用

    一:创建线程,NSThread创建线程常用的三种方式: //1:手动创建启动 let thread:NSThread = NSThread(target: self, selector:"d ...

  4. Android 开发问题集合

    1.屏幕横.竖切换 修改“AndroidManifest.xml”的android:screenOrientation 一般需要:landscape.portrait 2.修改应用名字 修改“Andr ...

  5. cbitmap 获取RGB CBitMap的用法

    MFC提供了位图处理的基础类CBitmap,可以完成位图(bmp图像)的创建.图像数据的获取等功能.虽然功能比较少,但是在对位图进行一些简单的处理时,CBitmap类还是可以胜任的.很多人可能会采用一 ...

  6. ffmpeg windows 雪花声解决方法

    替换所有文件里的<math.h>为<mathimf.h>即可. 我用ffmpeg-0.6.3版测试时,好像mathimf.h文件和其他文件有冲突,需要修改源码. 和qdm2.c ...

  7. lnmp脚本

    #!/bin/sh echo "欢迎使用 lnmp 脚本 (fanshengshuai@gmail.com) "; echo "增加资源..."; rpm -i ...

  8. javascript中常用数组函数

    1.split方法——通过分隔符,将字符串分割,导出字符数组 常用于:分割IP地址,分割文件路径(上传文件时)等等 <!DOCTYPE html PUBLIC "-//W3C//DTD ...

  9. MySQL基础之第1章 数据库概述

    1.1.数据存储方式 1.人工管理阶段2.文件系统阶段3.数据库系统阶段 1.2.数据库泛型 数据库泛型就是数据库应该遵循的规则.数据库泛型也称为范式.目前关系数据库最常用的四种范式分别是:第一范式( ...

  10. 11g 重建EM 报ORA-20001: SYSMAN already exists

    今天在安装11g(11.1.0.7.0)数据库之后,通过emca -config dbcontrol db -repos create 命令手工创建em的时候报错,查看日志后发现有以下错误 CONFI ...