poj1386 Play on words

Play on words

题目背景:

poj1386

分析:题意应该比较好理解,重点是怎么实现,我们可以发现,他需要我们求的是一条欧拉路径,并且我们可以发现,其实对于一个单词而言中间的字母是没有用的,只有两头的有用,然后我们的思路就比较清晰了,从每一个单词的首字母向尾字母连边,之后就形成了一个有26个点的有向图,然后我们针对这个图求解是否存在欧拉路径或欧拉回路即可。

Source:

#include 
      
      
       
       
#include 
       
       
        
        
#include 
        
        
         
         
#include 
         
         
          
          
#include 
          
          
            #include 
           
             #include 
            
              using namespace std; inline void R(int &v) { char c = 0; bool p = true; v = 0; while(!isdigit(c)) { if(c == '-') p = false; c = getchar(); } while(isdigit(c)) { v = (v << 3) + (v << 1) + (c ^ '0'); c = getchar(); } if(!p) v = -v; } char st[100010][2]; int first[150], tot, n; int in[150], out[150], t; bool vis[150]; char s[1100]; struct node { int next; int to; }edge[200010]; inline void create(int x, int y) { tot++, edge[tot].next = first[x], first[x] = tot, edge[tot].to = y; } void read() { R(n); for(int i = 1; i <= n; ++i) { scanf("%s", s); st[i][0] = s[0], st[i][1] = s[strlen(s) - 1]; create(st[i][0], st[i][1]); create(st[i][1], st[i][0]); int a = st[i][0], b = st[i][1]; out[a]++, in[b]++; } } void dfs(int cur) { vis[cur] = true; for(int p = first[cur]; p; p = edge[p].next) if(!vis[edge[p].to]) dfs(edge[p].to); } void work() { for(int i = (int)'a'; i <= (int)'z'; ++i) if(in[i] || out[i]) { dfs(i); break; } for(int i = (int)'a'; i <= (int)'z'; ++i) if(in[i] || out[i]) if(!vis[i]) { cout << "The door cannot be opened." << '\n'; return ; } int flag1 = false, flag2 = false; for(int i = (int)'a'; i <= (int)'z'; ++i) if(in[i] == out[i]) continue; else if(in[i] == out[i] + 1) { if(flag1) { cout << "The door cannot be opened." << '\n'; return ; } else flag1 = true; } else if(out[i] == in[i] + 1) { if(flag2) { cout << "The door cannot be opened." << '\n'; return ; } else flag2 = true; } else { cout << "The door cannot be opened." << '\n'; return ; } if(!flag1 && !flag2) cout << "Ordering is possible." <<'\n'; else if(flag1 && flag2) cout << "Ordering is possible." << '\n'; else cout << "The door cannot be opened." << '\n'; } void clear() { tot = 0; memset(first, 0, sizeof(first)); memset(in, 0, sizeof(in)); memset(out, 0, sizeof(out)); memset(vis, 0 ,sizeof(vis)); } int main() { R(t); while(t--) { read(); work(); clear(); } return 0; } 
             
            
          
         
         
        
        
       
       
      
      

 

内容概要:本文详细介绍了使用KGDB(Kernel GNU Debugger)调试Linux内核的方法及其重要性。文章首先强调了Linux内核作为系统核心的重要性及其调试的必要性,随后介绍了KGDB的基本原理和优势,包括其基于调试stub和GDB串行协议的工作机制。接着,文章详细描述了使用KGDB调试内核的具体步骤,包括准备工作、内核配置、设置启动参数、建立调试连接和进行调试操作。文中还通过一个实战案例展示了KGDB在解决实际问题中的应用,并总结了使用KGDB时的注意事项和常见问题的解决方法。最后,文章展望了KGDB未来的发展方向和应用场景,如优化调试性能、支持新型硬件架构以及在嵌入式系统、云计算和大数据领域的应用。 适合人群:具备一定Linux系统开发经验的研发人员,尤其是那些需要调试和优化Linux内核的工程师。 使用场景及目标:①帮助开发者深入了解Linux内核的运行状态,精准定位并修复内核问题;②优化内核性能,提高系统的稳定性和可靠性;③适用于嵌入式系统开发、远程服务器维护等场景,特别是在硬件资源有限或无法直接接触设备的情况下。 其他说明:在使用KGDB进行调试时,需特别注意串口设置的一致性、内核版本的兼容性以及调试信息的完整性。同时,要解决常见的连接失败、断点无效等问题,确保调试过程顺利进行。未来,KGDB有望在技术上不断优化,并拓展到更多应用场景中,为Linux系统的持续发展提供支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值