hihocoder 1632 Secret Poems
来源:互联网 发布:淘宝宝贝竖图怎么弄 编辑:程序博客网 时间:2024/06/05 03:28
题目链接:Secret Poems
题目大意:给你一个某种路径形成的字符串,还原后用另一种方法表示
题目思路:按题意模拟就好了,还原的时候分一下上下三角,然后上下三件移动的方向是成循环的,下半角需要分一下奇偶以确定初始方向
#include <map>#include <set>#include <cmath>#include <vector>#include <cstdio>#include <cstring>#include <cstdlib>#include <iostream>#include <algorithm>using namespace std;const int maxn = 1e6+10;int main(){ int n; char mp[200][200]; while(~scanf("%d",&n)){ for(int i = 1;i <= n;i++) for(int j = 1;j <= n;j++) cin>>mp[j][i]; int x = 1,y = 1; string dir = "R"; string str = ""; str += mp[1][1]; int flag = 0; while(1){ if(x == n&&y == n) break; if(x == n&&y == 1){ flag = 1; if(n&1) dir = "D"; else dir = "LD"; } if(flag == 0){//shang if(dir == "R"){ dir = "LD"; x++; str += mp[x][y]; } else if(dir == "LD"){ if(y + 1 > n||x - 1 <= 0) dir = "D"; else x--,y++,str += mp[x][y]; } else if(dir == "D"){ dir = "RU"; y++; str += mp[x][y]; } else if(dir == "RU"){ if(x + 1 > n||y - 1 <= 0) dir = "R"; else x++,y--,str += mp[x][y]; } } else{ if(dir == "D"){ dir = "LD"; y++; str += mp[x][y]; } else if(dir == "LD"){ if(y + 1 > n||x - 1 <= 0) dir = "R"; else x--,y++,str += mp[x][y]; } else if(dir == "R"){ dir = "RU"; x++; str += mp[x][y]; } else if(dir == "RU"){ if(x + 1 > n||y - 1 <= 0) dir = "D"; else x++,y--,str += mp[x][y]; } } } x = 1,y = 1; int ct = 1,cnt = 1; memset(mp,'*',sizeof(mp)); mp[1][1] = str[0]; dir = "R"; while(1){ if(cnt == n*n) break; if(dir == "R"){ if(x + 1 > n||mp[x+1][y] != '*') dir = "D"; else cnt++,x++,mp[x][y] = str[ct++]; } else if(dir == "D"){ if(y + 1 > n||mp[x][y+1] != '*') dir = "L"; else cnt++,y++,mp[x][y] = str[ct++]; } else if(dir == "L"){ if(x - 1 <= 0||mp[x-1][y] != '*') dir = "U"; else cnt++,x--,mp[x][y] = str[ct++]; } else if(dir == "U"){ if(y - 1 <= 0||mp[x][y-1] != '*') dir = "R"; else cnt++,y--,mp[x][y] = str[ct++]; } } for(int i = 1;i <= n;i++){ for(int j = 1;j <= n;j++){ printf("%c",mp[j][i]); } puts(""); } } return 0;}
阅读全文
0 0
- hihocoder 1632 Secret Poems
- Hihocoder 1632 : Secret Poems 思维|技巧
- hihoCoder-1632-Secret Poems(大模拟)
- Secret Poems(字符串处理)
- hihoCoder 1632 secret poem (2017北京赛区)
- Secret Poems 2017ACM-ICPC北京赛区/hihoCoder1632
- ACM-ICPC北京赛区2017网络同步赛(题目6 : Secret Poems)
- ACM-ICPC北京赛区2017网络同步赛 题目6 : Secret Poems
- 2017ACM-ICPC亚洲区域赛北京站 F.Secret Poems(模拟)
- sort poems
- Secret
- Secret
- Secret
- Project 3: Sort Poems
- Poems on Spring
- hihocoder:
- hihoCoder
- Hihocoder
- 基于FFmpeg+SDL的简单视频播放器
- Storm简介
- 读《Programming Collective Intelligence》chapter 2
- MapReduce
- 移动端 头部信息
- hihocoder 1632 Secret Poems
- Boost performance of pagination with infinite scrolling using Slice
- 1007. Maximum Subsequence Sum (25)(java版)
- Java 中的 WeakHashMap
- 城市级联处理逻辑
- ftp常用命令
- 带摇晃特效的扁平风格登录注册表单界面 一天一个界面持续更新
- Awake()与Start()的区别 在Unity圣典中的解释
- 数据库的完整性约束及触发器