题意:

给你n条蛇,a[i]的长度为i,要求组成一个矩形。奇数蛇可折叠奇数次,偶数蛇折叠偶数次,然后按蛇的次序输出

(即一条蛇的输出只能是一个方向的)

2 3

1 2

1 3 2 3

1 1 2 1 2 2

2 5

1 4

1 5 2 5

1 1 2 1 2 2

1 2 1 3 2 3 2 4

3 5

3 4

1 4 1 5

2 4 2 5 3 5

2 2 2 3 3 3 3 2

3 1 2 1 1 1 1 2 1 3

思路:

构造的话一般都是找规律,通过前面的推出后面的:

首先我们可以发现矩形的长宽是取决于n

1: 1 1                          2:1 2

3: 2 3                          4:2 5

5: 3 4                          6:3 7

然后是找矩形的关系

我们可以发现偶数矩形可以由它的前一个组成,即在后面加上

3: 1 3 3              4:1 3 3 4 4

2 2 3                2 2 3 4 4

然后看奇数矩形,通过长宽不停的从前找规律可以发现f[n]与f[n-3]有一定的关系

1 3 3 4 4                    1 3 3 4 4 5 7

2 2 3 4 4         -->        2 2 3 4 4 5 7

6 6 6 5 5 5 7

6 6 6 7 7 7 7

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring> using namespace std; void fin(int cur)
{
if(cur == 1)
{
printf("1 1\n");
return ;
}
if(cur == 2)
{
printf("1 1\n");
printf("1 2 1 3\n");
return;
}
if(cur == 3)
{
printf("2 1\n");
printf("1 1 1 2\n");
printf("1 3 2 3 2 2\n");
return;
}
int tx = (cur+1)/2;
int ty = (cur%2)? tx*2-1:tx*2+1; if(cur % 2 == 0)
{
fin(cur-1);
for(int i = 1; i <= cur/2; i ++)
printf("%d %d ",i,ty-1);
for(int i = cur/2; i >= 1; i--)
printf("%d %d ",i,ty);
printf("\n");
return ;
}
else
{
fin(cur-3);
for(int i = 1; i <= (cur-2)/2; i++)
printf("%d %d ",i,ty-1);
for(int i = 1; i <= (cur-2)/2+1; i++)
printf("%d %d ",tx-1,ty-i);
printf("\n"); for(int i = 1; i <= (cur-1)/2; i++)
printf("%d %d ",tx-1,i);
for(int i = 0; i <= (cur-1)/2-1; i++)
printf("%d %d ",tx,(cur-1)/2-i);
printf("\n"); for(int i = 0; i < cur/2+1; i++)
printf("%d %d ",tx,ty-cur/2+i);
for(int i = 0; i < cur/2; i++)
printf("%d %d ",tx-i-1,ty);
printf("\n");
return ;
}
} int main()
{
int n;
while(scanf("%d",&n) != EOF)
{
printf("%d %d\n",(n+1)/2,(n%2)? (n+1)/2*2-1:(n+1)/2*2+1);
fin(n);
}
return 0;
}

  

hihocoder1257(构造)(2015北京ACM/ICPC)的更多相关文章

  1. HDU 5874 Friends and Enemies 【构造】 (2016 ACM/ICPC Asia Regional Dalian Online)

    Friends and Enemies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  2. 2015 ACM / ICPC 亚洲区域赛总结(长春站&北京站)

    队名:Unlimited Code Works(无尽编码)  队员:Wu.Wang.Zhou 先说一下队伍:Wu是大三学长:Wang高中noip省一:我最渣,去年来大学开始学的a+b,参加今年区域赛之 ...

  3. ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 G. Garden Gathering

    Problem G. Garden Gathering Input file: standard input Output file: standard output Time limit: 3 se ...

  4. ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 D. Delay Time

    Problem D. Delay Time Input file: standard input Output file: standard output Time limit: 1 second M ...

  5. hdu 5444 Elven Postman(二叉树)——2015 ACM/ICPC Asia Regional Changchun Online

    Problem Description Elves are very peculiar creatures. As we all know, they can live for a very long ...

  6. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

  7. HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)

    HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: ...

  8. (并查集)Travel -- hdu -- 5441(2015 ACM/ICPC Asia Regional Changchun Online )

    http://acm.hdu.edu.cn/showproblem.php?pid=5441 Travel Time Limit: 1500/1000 MS (Java/Others)    Memo ...

  9. (二叉树)Elven Postman -- HDU -- 54444(2015 ACM/ICPC Asia Regional Changchun Online)

    http://acm.hdu.edu.cn/showproblem.php?pid=5444 Elven Postman Time Limit: 1500/1000 MS (Java/Others)  ...

随机推荐

  1. 关于java中的数组

    前言:最近刚刚看完了<Java编程思想>中关于数组的一章,所有关于Java数组的知识,应该算是了解的差不多了.在此再梳理一遍,以便以后遇到模糊的知识,方便查阅. Java中持有对象的方式, ...

  2. nyoj Color the fence

    Color the fence 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 Tom has fallen in love with Mary. Now Tom w ...

  3. openfalcon

    一.环境准备 操作系统:centos7(minimal,www.centos.org下载的包是CentOS-7-x86_64-Minimal-1611.iso) 1.1 更换阿里yum(个人习惯) 步 ...

  4. Node入门教程(4)第三章:第一个 Nodejs 程序

    第一个 Nodejs 程序 本教程仅适合您已经有一定的JS编程的基础或者是后端语言开发的基础.如果您是零基础,建议您先学一下老马的前端免费视频教程 第一步:创建项目文件夹 首先创建 demos 文件夹 ...

  5. Ajax.html:35 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org

    AJAX的容易错误的地方 Ajax.html:35 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated ...

  6. pthon/零起点(一、集合)

    pthon/零起点(一.集合) set( )集合,集合是无序的,集合是可变的,集合是可迭代的 set()强型转成集合数据类型 set()集合本身就是去掉重复的元素 集合更新操作案列: j={1,2,3 ...

  7. background属性的学习整理转述

    前言:这是笔者学习之后自己的理解与整理.如果有错误或者疑问的地方,请大家指正,我会持续更新! background我们一般用到的的属性有: background-attachment:背景(图片)是否 ...

  8. Java集合框架的四个接口

    接口 [四个接口  collection  list  set  map 的区别] collection 存储不唯一的无序的数据 list 存储有序的不唯一的数据 set   存储无序的唯一的数据 m ...

  9. 定点分析: MySQL InnoDB是如何保证系统异常断电情况下的数据可靠性?

    MySQL支持事务,所以保证数据可靠的前提是对数据的修改事务已经成功提交 这个问题可以解释为'MySQL InnoDB是如何保证事务C(一致性)D(持久性)性的?' 可能出现的两种情况: (一致性)数 ...

  10. JavaScript 递归

    递归是一种解决问题的方法,它解决问题的各个小部分,直到解决最初的大问题.通常涉及 函数调用自身. 能够像下面这样直接调用自身的方法或函数,是递归函数: var recursiveFunction = ...