读书人

杭电1116错哪了

发布时间: 2012-03-09 21:42:54 作者: rapoo

杭电1116哪里错了?
杭电1116地址http://acm.hdu.edu.cn/showproblem.php?pid=1116哪里错了。

C/C++ code
//按我的理解,就相当于形成回路,第一串的最后一个和第二串的第一个字母相同,第二串的最后一个字母和第三串的第一个字母相同。一次类推。。可是,我不知道自己怎么错了,请各位帮我查一查,100分敬上。#include<iostream>#include<string>using namespace std;int main(){    int n,m;    string str1,str2;    cin>>n;    while(n--)    {        cin>>m;        int k=1;        m--;        cin>>str1;        while(m--)        {            cin>>str2;            if(str1[str1.length()-1]!=str2[0])            {                k=0;            }            str1=str2;        }        if(k==1)            cout<<"Ordering is possible."<<endl;        else            cout<<"The door cannot be opened."<<endl;    }    return 0;}


[解决办法]
不一定是按给定顺序组成单词串 要自己搜索吧
比如 ab cd bc 你的程序能通过吗?
[解决办法]
All the plates from the list must be used, each exactly once. The words mentioned several times must be used that number of times.
If there exists such an ordering of plates, your program should print the sentence "Ordering is possible.".

意思就是让你找一种次序,看满足否,楼主答非所问,围观此题。
[解决办法]
首尾相连不见得是按照列表给定的顺序
并查集,欧拉路都可以

两组数据
2
3
ab
cd
bc
4
ab
ba
ef
fe

另外并查集find,带路径合并的可以简单的这样写
C/C++ code
int find(int x){    if(x != UFSet[x].parent)        UFSet[x].parent = find(UFSet[x].parent);    return UFSet[x].parent;}
[解决办法]
并查集怎么并的,讲讲
[解决办法]
head[26] tail[26]里面存单词开头字母的个数,结尾个数
能找到有一下情况
1. for i in 1 to 26 head[i] = tail[i]
2. 开头结尾入度出度都差一,其他相等
x y head[x]-tail[x]=1 head[y]-tail[y]=-1 其他相等

同时,注意到上面给的第二组测试数据
所有的串要在一个集合 要先用并查集判断
[解决办法]
探讨
head[26] tail[26]里面存单词开头字母的个数,结尾个数
能找到有一下情况
1. for i in 1 to 26 head[i] = tail[i]
2. 开头结尾入度出度都差一,其他相等
x y head[x]-tail[x]=1 head[y]-tail[y]=-1 其他相等

同时,注意到上面给的第二组测试数据
所有的串要在一个集合 要先用并查集判断

读书人网 >软件架构设计

热点推荐