POJ 3080.Blue Jeans
来源:互联网 发布:知道mac地址怎么查ip 编辑:程序博客网 时间:2024/06/03 23:39
题目:http://poj.org/problem?id=3080
AC代码(C++):
#include <iostream>#include <algorithm>#include <stdio.h>#include <vector>#include <queue>#include <math.h>#include <string>#include <string.h>#include <bitset>#define INF 0xfffffff#define MAXN 2005using namespace std;int main(){int n;cin>>n;char seq[15][65];for(int nn = 0; nn < n; nn++){int m;int maxlen = 0;char subseq[65];char maxsubseq[65];cin>>m;for(int mm = 0; mm < m; mm++)cin>>seq[mm];for(int i = 0; i < 60; i++){for(int j = i+1; j <= 60; j++){if(i == 0&&j == 8){i++;i--;}int kk = i;for(; kk < j; kk++){subseq[kk-i] = seq[0][kk];}subseq[kk-i] = '\0';int len = kk-i;bool flag3 = true;for(int jj = 1; jj < m; jj++){bool flag2 = false;for(int k = 0; k < 60; k++){bool flag = true;for(int l = k; l < k+len; l++){if(l>=60){flag = false;break;}if(seq[jj][l]!=subseq[l-k]){flag = false;break;}}if(flag){flag2 = true;break;}}if(flag2==false){flag3 = false;break;}}if(flag3){if(maxlen<len){maxlen = len;int jj = 0;for(; jj < len; jj++)maxsubseq[jj] = subseq[jj];maxsubseq[jj] = '\0';}else if(maxlen==len){bool flag = true;for(int k = 0; k < len; k++){if(subseq[k]>maxsubseq[k]){flag = false;break;}else if(subseq[k]<maxsubseq[k]){break;}}if(flag){int jj = 0;for(; jj < len; jj++)maxsubseq[jj] = subseq[jj];maxsubseq[jj] = '\0';}}}}}if(maxlen>=3)cout<<maxsubseq<<endl;else cout<<"no significant commonalities\n";}}总结: 刚开始有点懵逼, 看了解题报告后才知道可以暴力解. 具体的暴力方法是枚举第一串中的所有子串, 然后在其他串中查找. 注意答案要求如果长度相同则比较字典序.
阅读全文
0 0
- POJ 3080.Blue Jeans
- poj 3080 Blue Jeans
- poj 3080 Blue Jeans
- poj 3080 Blue Jeans
- poj 3080 Blue Jeans
- poj 3080 Blue Jeans
- POJ 3080 Blue Jeans
- POJ 3080 Blue Jeans
- POJ 3080 Blue Jeans
- POJ 3080 Blue Jeans
- Poj 3080 Blue Jeans
- POJ 3080 Blue Jeans
- POJ 3080 Blue Jeans
- POJ 3080 Blue Jeans
- poj 3080 Blue Jeans
- poj 3080 Blue jeans
- POJ 3080 Blue Jeans
- POJ 3080 Blue Jeans
- 九九乘法表
- 进程间互斥、同步
- java 反射机制-学习笔记(3)
- 顺序存储的稀疏矩阵(三元组)的转置
- 从铁路技术装备展的科技“攀比”看合作共赢
- POJ 3080.Blue Jeans
- hdu1010 Tempter of the Bone(dfs) java
- VS2012尝试运行项目时出错 无法启动程序 请参见应用程序日志时间
- 强连通分量——tarjan
- 第二讲 类加载器
- Leetcode 5. Longest Palindromic Substring(java版)
- 4 Values whose Sum is 0(poj 2785)
- shiro的org.apache.shiro.UnavailableSecurityManagerException错误
- a messy week