D DNA Analysis
暴力枚举第一次翻转,记正反串。
折半搜索
#include<bits/stdc++.h>
using namespace std;
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
For(j,m-1) cout<<a[i][j]<<' ';\
cout<<a[i][m]<<endl; \
}
#pragma
#define
#define
#define
#define
#define
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
#define
string Filename="dna";
char s[40],s2[40];
int n;
ull seed=123;
ull f[MAXN][MAXN],g[MAXN][MAXN],p2[MAXN];
set<ull> S;
void get() {
cin>>(s+1);
p2[0]=1;
For(i,35) p2[i]=p2[i-1]*seed;
int n=strlen(s+1);
For(i,n) {
Fork(j,i,n) {
reverse(s+i,s+j+1);
For(i,n) {
f[i][i]=g[i][i]=s[i];
}
Fork(len,2,n) {
For(i,n-len+1) {
int j=i+len-1;
f[i][j]=f[i][j-1]*seed+s[j];
g[i][j]=g[i+1][j]*seed+s[i];
}
}
For(k,n)
Fork(l,k,n) {
ll ans=0;
if (1<k) ans=f[1][k-1];
ans=ans*p2[l-k+1]+g[k][l];
if (l<n) ans=ans*p2[n-l]+f[l+1][n];
// cout<<ans<<' ';
S.insert(ans);
}
reverse(s+i,s+j+1);
}
}
}
bool get2() {
cin>>(s+1);
p2[0]=1;
For(i,35) p2[i]=p2[i-1]*seed;
int n=strlen(s+1);
For(i,n) {
Fork(j,i,n) {
reverse(s+i,s+j+1);
For(i,n) {
f[i][i]=g[i][i]=s[i];
}
Fork(len,2,n) {
For(i,n-len+1) {
int j=i+len-1;
f[i][j]=f[i][j-1]*seed+s[j];
g[i][j]=g[i+1][j]*seed+s[i];
}
}
For(k,n)
Fork(l,k,n) {
ll ans=0;
if (1<k) ans=f[1][k-1];
ans=ans*p2[l-k+1]+g[k][l];
if (l<n) ans=ans*p2[n-l]+f[l+1][n];
if (S.count(ans)) return 1;
}
reverse(s+i,s+j+1);
}
}
return 0;
}
int main()
{
freopen((Filename+".in").c_str(), "r", stdin);
freopen((Filename+".out").c_str(), "w", stdout);
get();
puts(get2() ? "Similar": "Different") ;
return 0;
}
Surface Genus
在拓扑学中,定义genus为多面体的洞(比如球是0个。甜甜圈1个,手铐2个……),给一个只由三角形组成的多面体,问孔的个数
孔的个数只与点数和面数有关。