• POJ Subway tree systems


     

    Subway tree systems
    Time Limit: 1000MSMemory Limit: 10000K
    Total Submissions: 6215Accepted: 2590

    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. 
    POJ Subway tree systems - qhn999 - 码代码的猿猿

    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

    2
    0010011101001011
    0100011011001011
    0100101100100111
    0011000111010101

    Sample Output

    same
    different

    Source

    Northwestern Europe 2003 
     


    #include <iostream>
    #include <string>
    #include <vector>
    #include <algorithm>

    using namespace std;

    string x;

    string calc(int i)
    {
        vector<string> v;
        int n=x.size();

        while(i<n&&x!='1')
        {
            v.push_back('0'+calc(i+1));
            i+=v.back().size();
        }

        string r;
        sort(v.begin(),v.end());

        for(int i=0;i<(int)v.size();i++)
        {
            r+=v;
        }

        return r+'1';
    }

    int main()
    {
        int T;
        cin>>T;

    while(T--)
    {
        string a,b;
        cin>>x; a=calc(0);
        cin>>x; b=calc(0);
        if(a==b)
        {
            cout<<"same ";
        }
        else
        {
            cout<<"different ";
        }
    }

        return  0;
    }

  • 相关阅读:
    html页面模板布局内容的继承,block
    url分发
    显示年月,注册页面和后台数据交互,不涉及数据库
    static文件夹中文件引用方式,如html页面引用js
    pycharm写django之返回一个页面
    pycharm编写django第一步
    VUE清除keepalive页面缓存
    js设置html根节点的style字体【Vue动态调整全局字体大小】
    npm 依赖重新安装或更新版本
    antd 自定义表头slots.title不生效
  • 原文地址:https://www.cnblogs.com/CKboss/p/3350966.html
Copyright © 2020-2023  润新知