poj 2513Colored Sticks
http://poj.org/problem?id=2513
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std; const int sign_node=;
const int max_node=;
int f[max_node];
int du[max_node];
int num=;
int ch[max_node][sign_node];
int val[max_node]; struct Trie
{
int sz;
void clear(){sz=; memset(ch[],,sizeof(ch[]));}
int idx(char c) {return c-'a';} int insert(char *s)
{
int u=,n=strlen(s);
for(int i=; i<n; i++){
int c=idx(s[i]);
if(!ch[u][c]){
memset(ch[sz],,sizeof(ch[sz]));
val[sz]=;
ch[u][c]=sz++;
}
u=ch[u][c];
}
if(!val[u]) val[u]=++num;
return val[u];
}
}; int find(int x)
{
if(x!=f[x])
f[x]=find(f[x]);
return f[x];
} void merge(int x,int y)
{
int fx=find(x);
int fy=find(y);
if(fx!=fy){
f[fx]=fy;
}
} void inti()
{
memset(du,,sizeof(du));
for(int i=; i<=max_node; i++)
f[i]=i;
} int main()
{
Trie trie;
char a[],b[];
inti();
trie.clear();
while(scanf("%s%s",a,b)!=EOF)
{
int id1=trie.insert(a);
int id2=trie.insert(b);
du[id1]++;
du[id2]++;
merge(id1,id2);
}
int ans=,ans1=;
for(int i=; i<=num; i++)
{
if(du[i]&)
ans++;
if(ans>||find()!=find(i))
{
printf("Impossible\n");
return ;
}
}
if(ans==)
printf("Impossible\n");
else
printf("Possible\n");
return ;
}
poj 2513Colored Sticks的更多相关文章
- DFS(剪枝) POJ 1011 Sticks
题目传送门 /* 题意:若干小木棍,是由多条相同长度的长木棍分割而成,问最小的原来长木棍的长度: DFS剪枝:剪枝搜索的好题!TLE好几次,终于剪枝完全! 剪枝主要在4和5:4 相同长度的木棍不再搜索 ...
- POJ 1011 - Sticks DFS+剪枝
POJ 1011 - Sticks 题意: 一把等长的木段被随机砍成 n 条小木条 已知他们各自的长度,问原来这些木段可能的最小长度是多少 分析: 1. 该长度必能被总长整除 ...
- 搜索+剪枝——POJ 1011 Sticks
搜索+剪枝--POJ 1011 Sticks 博客分类: 算法 非常经典的搜索题目,第一次做还是暑假集训的时候,前天又把它翻了出来 本来是想找点手感的,不想在原先思路的基础上,竟把它做出来了而且还是0 ...
- POJ 2452 Sticks Problem
RMQ+二分....枚举 i ,找比 i 小的第一个元素,再找之间的第一个最大元素..... Sticks Problem Time Limit: 6000MS ...
- 搜索 + 剪枝 --- POJ 1101 : Sticks
Sticks Problem's Link: http://poj.org/problem?id=1011 Mean: http://poj.org/problem?id=1011&lan ...
- poj 1011 Sticks
Sticks Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 126238 Accepted: 29477 Descrip ...
- OpenJudge 2817:木棒 / Poj 1011 Sticks
1.链接地址: http://bailian.openjudge.cn/practice/2817/ http://poj.org/problem?id=1011 2.题目: 总时间限制: 1000m ...
- poj 1011 Sticks (DFS+剪枝)
Sticks Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 127771 Accepted: 29926 Descrip ...
- POJ 1011 Sticks 【DFS 剪枝】
题目链接:http://poj.org/problem?id=1011 Sticks Time Limit: 1000MS Memory Limit: 10000K Total Submissio ...
随机推荐
- sql服务器内部参数使用详情(存储过程)
exec sp_help;返回当前数据库中的所有存储过程.exec sp_help datebase.dbo.table名称 返回当前表中的所有对象.如字段名称等.这个吊exec sp_helpfil ...
- Struts2.xml中result type属性说明
在struts2配置XML里,result中type属性有以下几种: 1.dispatcher:服务器跳转到前台,后面跟着可以是JSP.htm等等前台页面,默认是这种. 2.redirect:客户端跳 ...
- OpenCV LDA(Linnear Discriminant analysis)类的使用---OpenCV LDA演示样例
1.OpenCV中LDA类的声明 //contrib.hpp class CV_EXPORTS LDA { public: // Initializes a LDA with num_componen ...
- URL重写:RewriteCond指令与RewriteRule 指令格式(转)
Rewirte主要的功能就是实现URL的跳转和隐藏真实地址,基于Perl语言的正则表达式规范.平时帮助我们实现拟静态,拟目录,域名跳转,防止盗链等.本文将针对mod_rewrite和URL匹配的技术细 ...
- 使用Tcl脚本分配FPGA管脚
自己主动生成Tcl文件 Project -> Generate Tcl File for Project... 弹出例如以下对话框.设置脚本路径. 编辑引脚 使用set_location_ass ...
- LINUX 内核与 systemtap +GO 专家博客 一个[ 系统软件工程师] 的随手涂鸦
http://nanxiao.me/category/%E3%80%8Anix-hacking%E3%80%8B%E6%9D%82%E5%BF%97/ 月刊 https://github.co ...
- Android Rom修改
最近项目里要实现修改开机动画 屏蔽系统桌面等一些涉及到修改底层的功能 一开始研究了一番 心想着看来这是要定制系统 做rom开发了 所以就牛逼哄哄的跑去下源码 研究rom开发 后来发现这将是一个庞大的工 ...
- 在cmd窗口下运行Java程序时无法找到主类的解决办法
我是Java的初学者,昨天在cmd窗口下运行一段Java程序时总是有问题,可以编译但无法执行. 也就是javac时正确,一旦java时就不对了,提示找不到或无法加载主类,经百度谷歌再加上自己的摸索终于 ...
- java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.L(转)
09-09 10:19:59.979: E/AndroidRuntime(2767): FATAL EXCEPTION: main09-09 10:19:59.979: E/AndroidRuntim ...
- C#关于使用枚举遇到的问题----Type运算符使用的必要性
我定义了一个枚举AttributeName 然后写到下面代码: Enum .GetValues (AttributeName ): 毫无疑问的错了.别人说要加个Typeof 也就是Enum .GetV ...