hihocoder1257(构造)(2015北京ACM/ICPC)
题意:
给你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)的更多相关文章
- 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 ...
- 2015 ACM / ICPC 亚洲区域赛总结(长春站&北京站)
队名:Unlimited Code Works(无尽编码) 队员:Wu.Wang.Zhou 先说一下队伍:Wu是大三学长:Wang高中noip省一:我最渣,去年来大学开始学的a+b,参加今年区域赛之 ...
- 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 ...
- 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 ...
- 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 ...
- HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)
HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...
- HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)
HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others) Memory Limit: ...
- (并查集)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 ...
- (二叉树)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) ...
随机推荐
- python的项目结构
项目结构 知识点 创建项目,编写 __init__ 文件 使用 setuptools 模块,编写 setup.py 和 MANIFEST.in 文件 创建源文件的发布版本 项目注册&上传到 P ...
- jav音频格式转换 ffmpeg 微信录音amr转mp3
项目背景: 之前公司开发了一个微信公众号,要求把js-sdk录音文件在web网页也能播放.众所周知,html的<audio>标签ogg,mp3,wav,也有所说苹果safari支持m4a格 ...
- Struts2之Action的实现
对于Struts2框架来说,最重要的莫过于Action类的编写,类比于Servlet,Action类也是通过类的实例对象调用方法来处理请求的,Action类的实例对象是由Struts2的核心Filte ...
- OpenCASCADE Trihedron Law
OpenCASCADE Trihedron Law eryar@163.com Abstract. In differential geometry the Frenet-Serret formula ...
- R语言-推荐系统
一.概述 目的:使用推荐系统可以给用户推荐更好的商品和服务,使得产品的利润更高 算法:协同过滤 协同过滤是推荐系统最常见的算法之一,算法适用用户过去的购买记录和偏好进行推荐 基于商品的协同过滤(IBC ...
- apache的重写规则
RewriteEngine OnRewriteCond %{REQUEST_FILENAME} .*\.(jpg|jpeg|gif|png) [NC]RewriteRule .* http://i8. ...
- 验证码进阶(TensorFlow--基于卷积神经网络的验证码识别)
本人的第一个深度学习实战项目,参考了网络上诸多牛人的代码,在此谢过,因时间久已,不记出处,就不一一列出,罪过罪过. 我的数据集是我用脚本在网页上扒的,标签是用之前写的验证码识别方法打的.大概用了400 ...
- 改变this不要怕!!!
在之前的学习和工作中,会不必要的涉及到 改变this的指向问题: 脑子里会想到的是 apply, call, bind 这三个 可逆知道他的区别吗? 1. bind区别于 apply和call 是因为 ...
- 【Vue中的swiper轮播组件】
<template> <swiper :options="swiperOption" ref="mySwiper"> <!-- s ...
- CentOS7 安装eclipse
1. 首先将eclipse的压缩包文件解压到/opt目录下,要使用root权限.执行如下解压命令:tar -zxvf eclipse-jee-oxygen-1a-linux-gtk-x86_64.ta ...