博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj1635
阅读量:7244 次
发布时间:2019-06-29

本文共 3109 字,大约阅读时间需要 10 分钟。

Subway tree systems
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 5735   Accepted: 2370

Description

Some major cities have subway systems in the form of a tree, i.e. between any pair of stations, there is one and only one way of going by subway. Moreover, most of these cities have a unique central station. Imagine you are a tourist in one of these cities and you want to explore all of the subway system. You start at the central station and pick a subway line at random and jump aboard the subway car. Every time you arrive at a station, you pick one of the subway lines you have not yet travelled on. If there is none left to explore at your current station, you take the subway line back on which you first came to the station, until you eventually have travelled along all of the lines twice,once for each direction. At that point you are back at the central station. Afterwards, all you remember of the order of your exploration is whether you went further away from the central station or back towards it at any given time, i.e. you could encode your tour as a binary string, where 0 encodes taking a subway line getting you one station further away from the central station, and 1 encodes getting you one station closer to the central station. 

Input

On the first line of input is a single positive integer n, telling the number of test scenarios to follow.Each test scenario consists of two lines, each containing a string of the characters '0' and '1' of length at most 3000, both describing a correct exploration tour of a subway tree system.

Output

exploration tours of the same subway tree system, or the text "different" if the two strings cannot be exploration tours of the same subway tree system.

Sample Input

20010011101001011010001101100101101001011001001110011000111010101

Sample Output

samedifferent

Source

 
#include 
#include
#include
#include
using namespace std;string str1, str2;char temp[3001];void format_tree(string &str, int begin, int end){ vector
vec; int count = 0, j = begin, i, k; if (begin > end) return; for (i = begin; i <= end; i++) { if (str[i] == '0') count++; else count--; if (count == 0) { format_tree(str, j+1, i-1); for (k = j; k <= i; k++) temp[k-j] = str[k]; temp[i-j+1] = '\0'; vec.push_back(temp); j = i+1; } } sort(vec.begin(), vec.end()); k = begin; for (i = 0; i < vec.size(); i++) { for (j = 0; j < vec[i].length(); j++) str[k++] = vec[i][j]; } vec.clear();}int main(){ int n; cin >> n; while (n--) { cin >> str1 >> str2; format_tree(str1, 0, str1.length()-1); format_tree(str2, 0, str2.length()-1); if (str1 == str2) cout << "same" << endl; else cout << "different" << endl; } return 0;}

 

转载于:https://www.cnblogs.com/eric-blog/archive/2012/08/19/2646830.html

你可能感兴趣的文章
快速制作美观的微信公共号二维码?
查看>>
(十二)JAVA springboot ssm b2b2c多用户商城系统源码:使用Spring Cloud Sleuth和Zipkin进行分布式链路跟踪...
查看>>
直击KubeCon 2018 |云原生正在改变你的衣食住行
查看>>
拦截器
查看>>
AWK 简明教程
查看>>
设置SPFILE中的参数值
查看>>
openstack目前个人认为要解决的问题总结,会持续更新
查看>>
我的友情链接
查看>>
iops计算详解
查看>>
Android编译报R.java报不到的错误解决办法
查看>>
CentOS5.x下安装配置FTP服务器
查看>>
正则数量词及非捕获
查看>>
MPLS 配置步骤
查看>>
Exchange Server 2007灾难恢复(AD+Ex)
查看>>
GRUB2
查看>>
Go性能优化技巧 1/10
查看>>
DNS 域名解析服务器---案例详解
查看>>
疑似电信版GALAXY S4现身官网 或配八核处理器
查看>>
我的Linux生涯之系统语言环境及中文输入法的操作
查看>>
c#获取当前页面名字
查看>>