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. ...
随机推荐
- TC SRM 593 DIV1 250(dfs)
这图最多3色就可以 搜2就行了 #include <iostream> #include<cstdio> #include<cstring> #include< ...
- fil_system_struct
/** The tablespace memory cache */ typedef struct fil_system_struct fil_system_t; /** The tablespace ...
- javascript中的关键字和保留字
javascript中关键字的问题,将名称替换了下,确实就没有问题了.现在将它的关键字和保留字贴出来,便于日后查看和避免在次出现类似的问题. 1 关键字breakcasecatchcontinuede ...
- BZOJ 1861 书架
(╯-_-)╯╧╧ 此处为错误代码. #include<iostream> #include<cstdio> #include<cstring> #include& ...
- HDU 4635 Strongly connected (强连通分量)
题意 给定一个N个点M条边的简单图,求最多能加几条边,使得这个图仍然不是一个强连通图. 思路 2013多校第四场1004题.和官方题解思路一样,就直接贴了~ 最终添加完边的图,肯定可以分成两个部X和Y ...
- MYSQL的分区字段,必须包含在主键字段内
MYSQL的分区字段,必须包含在主键字段内 MYSQL的分区字段,必须包含在主键字段内 在对表进行分区时,如果分区字段没有包含在主键字段内,如表A的主键为ID,分区字段为createtime ,按 ...
- Java [Leetcode 94]Binary Tree Inorder Traversal
题目描述: Given a binary tree, return the inorder traversal of its nodes' values. For example:Given bina ...
- FFMPEG + SDL音频播放分析
目录 [hide] 1 抽象流程: 2 关键实现: 2.1 main()函数 2.2 decode_thread()读取文件信息和音频包 2.3 stream_component_open():设置音 ...
- ECshop 每个数据库表结构说明
ecs_account_log // 用户账目日志表 ecs_activity // 活动表(代码,名称,开始,结束,描述) ecs_ad // 广告表(位置,类型,名称,链接,图片,开始,结束,广告 ...
- linux命令——rm
rm是常用的命令,该命令的功能为删除一个目录中的一个或多个文件或目录,它也可以将某个目录及其下的所有文件及子目录均删除.对于链接文件,只是删除了链接,原有文件均保持不变. rm是一个危险的命令,使用的 ...