题目:题目链接

思路:1到4是很容易写出来的,我们先考虑这四种情况的绘制顺序

  1:ru

  2:rulu

  3:rululdlu

  4:rululdluldrdldlu

  不难发现,相较于前一行,每一次增加一倍数量,并且增加的这部分前一半和原来正好相反,后一半相同,根据这一性质,预处理出极端情况13的解答字符串,然后绘制即可,注意控制行尾空格

AC代码:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque> #define FRER() freopen("in.txt", "r", stdin)
#define FREW() freopen("out.txt", "w", stdout) #define INF 0x3f3f3f3f using namespace std; char ans[], _map[][];
int _max[]; char cal(char ch) {
if(ch == 'l')
return 'r';
if(ch == 'r')
return 'l';
if(ch == 'u')
return 'd';
if(ch == 'd')
return 'u';
} int main()
{
//FRER();
//FREW();
ios::sync_with_stdio();
cin.tie(); ans[] = 'r';
ans[] = 'u';
for(int i = ; i < ; ++i) {
int n = << (i - ), m = << (i - );
for(int j = ; j < n; ++j) {
ans[j + m] = cal(ans[j]);
}
for(int j = ; j < << (i - ); ++j) {
ans[j + m + n] = ans[j + n];
}
}
ans[ << ] = '\0';
cout << ans << endl;
int n;
while(cin >> n, n) {
memset(_map, , sizeof(_map));
memset(_max, , sizeof(_max));
int minl = , maxl = , minc = , maxc = ;
int l = , c = ;
int m = << n;
_max[] = ;
_map[l][c] = '_';
for(int i = ; i < m; ++i) {
if(ans[i - ] == 'l')
--c;
else if(ans[i - ] == 'r')
++c;
else if(ans[i - ] == 'u')
--l; if(ans[i] == 'u') { _map[l][c] = '|';
}
else if(ans[i] == 'd') {
++l;
_map[l][c] = '|';
}
else if(ans[i] == 'l') {
--c;
_map[l][c] = '_';
}
else {
++c;
_map[l][c] = '_';
}
minl = min(minl, l);
minc = min(minc, c);
maxl = max(maxl, l);
_max[l] = max(_max[l], c);
}
for(int i = minl; i <= maxl; ++i) {
for(int j = minc; j <= _max[i]; ++j)
cout << (_map[i][j] == ? ' ' : _map[i][j]);
cout << endl;
}
cout << '^' << endl;
}
return ;
}

Paper Folding UVA - 177 模拟+思路+找规律的更多相关文章

  1. UVa 1620 Lazy Susan (找规律)

    题意:给 n 个数,每次可以把4个连续的数字翻转,问你能不能形成1-n的环状排列. 析:找一下奇偶性,写几个数试试,就会找到规律. 代码如下: #include <cstdio> #inc ...

  2. UVA 10706 Number Sequence (找规律 + 打表 + 查找)

    Problem B Number Sequence Input: standard input Output: standard output Time Limit: 1 second A singl ...

  3. Uva 11549 - Calculator Conundrum 找规律加map

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  4. UVa 12627 (递归 计数 找规律) Erratic Expansion

    直接说几个比较明显的规律吧. k个小时以后,红气球的个数为3k. 单独观察一行: 令f(r, k)为k个小时后第r行红气球的个数. 如果r为奇数,f(r, k) = f((r+1)/2, k-1) * ...

  5. UVA 11489 - Integer Game(找规律)

    题目链接 #include <cstdio> #include <cstring> #include <string> #include <cmath> ...

  6. 【数论,找规律】Uva 11526 - H(n)

    原来做过的题再看还是没想出来,看来当时必然没有真正理解.这次回顾感觉理解更透彻了. 网上的题解差不多都是一个版本,而且感觉有点扯.根据n=20猜出来的? 好吧哪能根据一个就猜到那么变态的公式.其实这题 ...

  7. uva 10706 Number Sequence(数学规律)

    题目连接:10706 - Number Sequence 题目大意:有一个有0 ~ 9组成的序列,1   1 2    1 2 3   1 2 3 4   1 2 3 4 5 ....就是第一位为1. ...

  8. 汉诺塔问题hdu 2065——找规律

    这类题目就是纸上模拟,找规律. 问题描述:在一块铜板上有三根杆,目的是将最左边杆上的盘全部移到右边的杆上,条件是不允许直接从最左(右)边移到最右(左)边(每次移动一定是移到中间杆或从中间移出),也不允 ...

  9. hdu 2147 kiki's game 组合游戏 找规律

    题目链接 题意 两人轮流将硬币从\((n,m)\)移动到\((1,1)\),每次只能向下或向左或向左下移动一格,最后无法移动者输.问先手会赢还是会输. 思路 找规律 -- P N P N P N P ...

随机推荐

  1. json java simple-json

    http://code.google.com/p/json-simple/wiki/EncodingExamples#Example_1-1_-_Encode_a_JSON_object javac ...

  2. java常见数据结构举例

    1. ArrayList(参考) import java.util.*; public class Test{ public static void main(String [] args){ Arr ...

  3. Response.Redirect 打开新窗口的两种方法

    一般情况下,Response.Redirect 方法是在服务器端进行转向,因此,除非使用 Response.Write("<script>window.location='htt ...

  4. Unity3d中使用assetbundle

    1.导出assetbundle: ①单个资源导出成assetbundle: ②多个资源导出成一个assetbundle: 2.读取assetbundle: ①加载到内存: ②解压为具体资源. 1.导出 ...

  5. iOS书摘之Objective-C编程之道 iOS设计模式解析

    来自<Objective-C编程之道iOS设计模式解析>一书的摘要总结 一.Prototype 原型模式 定义:使用原型实例指定创建对象的种类,并通过复制这个原型创建新的对象.(<设 ...

  6. linux启动mysql报错 Starting MySQL... ERROR! The server quit without updating PID file (XXXX pid文件位置)

    最近在云服务器上安装mysql  启动时报错了,从错误中可以看出,定位在pid文件上,有三种解决方案 1.重启服务器:因为服务器更新时,可能会禁用某些守护进程,重启后即可恢复 2.删除配置文件,重启试 ...

  7. hibernate课程 初探单表映射3-1 hibernate单表操作简介

    本章简介: 1 单一主键 2 基本类型 3 对象类型 4 组件属性 5 单表操作CRUD实例

  8. SSM整合笔记

    SSM整合笔记 1,创建maven项目 创建maven项目过程省略 ps:如果创建完maven项目之后项目报错,可能是没有配置Tomcat 2,在pom.xml里面导入相应的jar的依赖 <pr ...

  9. 如何修改HDFS上文件

    如果只想append操作: . echo "<Text to append>" | hdfs dfs -appendToFile - yourHdfsPath/test ...

  10. 时序js插件cubism使用

    document http://iwantmyreal.name/blog/2012/09/16/visualising-conair-data-with-cubism-dot-js https:// ...