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) ...
随机推荐
- JAVA和Android的回调机制
本文出自xiaanming的博客(http://blog.csdn.net/xiaanming/article/details/17483273),请尊重他人的辛勤劳动成果,谢谢 以 前不理解什么叫回 ...
- vue 内联样式style中的background
在我们使用vue开发的时候 有很多时候我们需要用到背景图 这个时候会直接使用 内联样式 直接把你拿到的数据拼接上去 注意 在vue中直接使用style时 花括号一定别忘记 还有就是你的url一定 ...
- JAVA_SE基础——61.字符串入门
public class Demo1 { public static void main(String[] args) { String str1 = "hello"; Strin ...
- SpringBoot入门:Spring Data JPA 和 JPA(理论)
参考链接: Spring Data JPA - Reference Documentation Spring Data JPA--参考文档 中文版 纯洁的微笑:http://www.ityouknow ...
- api-gateway实践(03)新服务网关 - 网关请求拦截检查
参考链接:http://www.cnblogs.com/jivi/archive/2013/03/10/2952829.html 一.为什么要拦截检查请求? 防止重放攻击.篡改重放,进行使用规格检查 ...
- Linux实战案例(5)关闭Centos的防火墙
1.检查防火墙的状态 [root@LxfN1 ~]# service iptables status表格:filterChain INPUT (policy ACCEPT)num target pro ...
- OAuth2.0学习(1-3)OAuth2.0的参与者和流程
OAuth(开放授权)是一个开放标准.允许第三方网站在用户授权的前提下访问在用户在服务商那里存储的各种信息.而这种授权无需将用户提供用户名和密码提供给该第三方网站. OAuth允许用户提供一个令牌给第 ...
- POJ-3617 Best Cow Line---字符串贪心
题目链接: https://vjudge.net/problem/POJ-3617 题目大意: 每次都可以从字符串的首部或者尾部提取字母,使得最后的字符串的字典序最小. 思路: 贪心做即可~每次从上和 ...
- vscode设置出错, 无法自动补全
问题: 之前设置的没问题, vscode重装后, 发现vscode里面的设置还在, 但敲代码却无法识别虚拟环境中的包了, 因此相关的内容也无法自动补全. 解决: 后来发现, 实际上设置没有出错, 但重 ...
- 00-翻译IdentityServer4的目的
强迫自己阅读英文文档 加深IdentityServer4的概念认识