HDU 4172解题报告
来源:互联网 发布:java开源微信商城系统 编辑:程序博客网 时间:2024/06/05 09:02
版权声明:本文为博主Ticholas-Huang原创文章,转载请注明出处
Octagons
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 217 Accepted Submission(s): 82
Problem Description
Below is a picture of an infinite hyperbolic tessellation of octagons. If we think of this as a graph of vertices (of degree three), then there exists an isomorphism of the graph which maps any vertex x onto any other vertex y. Every edge is given a label from the set {a,b,c} in such a way that every vertex has all three types of edges incident on it, and the labels alternate around each octagon. Part of this labeling is illustrated in the diagram.
So a path in this graph (starting from any vertex) can be specified by a sequence of edge labels. Your job is to write a program which, given a squence of labels such as “abcbcbcabcaccabb”, returns “closed” if the path ends on the same vertex where it starts, and returns “open” otherwise.
Input
The input will begin with a number Z ≤ 200 on a line by itself. This is followed by Z lines, each of which is a squence of length at least 1 and at most 40 of ‘a’s ‘b’s and ‘c’s.
Output
For each input instance, the output will be the words “closed” or “open”, each on a single line.
Sample Input
2
abababab
abcbcbcbcba
Sample Output
closed
open
这道题题意就是有 一堆 八边形 每条边可以用a b c中任一个标记
相邻两条边的标记不同
每个八边形中只有两个标记
比如: babababa
或 cacacaca
输入一个字串
问能不能按字串的顺序来走八边形 最终回到起点
这道题其实就是字符串处理:
根据几何知识可以知道
规则1 abababa 可换成 b 八边形两个方向走 走7条边和走另一方向的1条边是一样的
规则2 ababab 可换成 ba 6条边 换 两条边
规则3 ababa 可换成 bab 5条边换3条边
规则4 bb 可去掉 一条边来回走
然后仔细点可以发现
只需要 规则3 和 规则4 就可以实现所有规则
不说了
上代码
/*author: Ticholas-Huang*//*2016.4.3*/#include <iostream>#include <string>using namespace std;bool transfer(string ss){ size_t size = ss.size(); if (size == 0) return true; for (int i = 0; i + 1 < size; i++) { if (ss[i] == ss[i + 1]) return transfer(ss.substr(0, i) + ss.substr(i + 2)); } for (int i = 0; i + 4 < size; i++) { if (ss[i] == ss[i + 2] && ss[i] == ss[i + 4] && ss[i + 1] == ss[i + 3]) return transfer(ss.substr(0, i) + ss.substr(i + 1,3) + ss.substr(i + 5)); } return false;}int main(int argc, char const *argv[]){ int Case = 0; cin >> Case; string testStr; while (Case) { cin >> testStr; if (transfer(testStr)) { cout << "closed" << endl; } else { cout << "open" << endl; } Case--; } return 0;}
- HDU 4172解题报告
- HDU 3342 解题报告
- HDU 3336 解题报告
- HDU 3335 解题报告
- hdu 2516解题报告
- hdu 1004解题报告
- hdu 2139解题报告
- hdu 1019解题报告
- hdu 1064 解题报告
- HDU 1113 解题报告
- hdu 1068 解题报告
- HDU:2050解题报告
- hdu 4001解题报告
- hdu 1005解题报告
- HDU解题报告--1003
- HDU解题报告--1004
- HDU解题报告--1005
- HDU 1005 解题报告
- (四)一个简单的删除链表中某个元素的算法
- 第六课 linux下进程描述与进程创建
- HTML学习(八)——多媒体
- 揭秘12306技术改造(三):传统框架云化迁移到内存数据平台
- Hadoop 2.6.0 hbase 0.98 Java API 调用实例
- HDU 4172解题报告
- [网络基本功系列八]细说TCP滑动窗口
- 我是一个线程(修订版)
- 依赖与关联的比较
- 第六周上机实践项目-项目3-IP地址类
- 提取树莓派的rootfs到ext4
- 趣味编程_打印余弦函数
- Educational Codeforces Round 1 C. Nearest vectors 【极角排序atan2法】
- 数据结构实验之队列一:排队买饭