http://codeforces.com/gym/100623/attachments E题
Posted war1111
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了http://codeforces.com/gym/100623/attachments E题相关的知识,希望对你有一定的参考价值。
http://codeforces.com/gym/100623/attachments E题
第一个优化
它虽然是镜像对称,但它毕竟是一一对称的,所以可以匹配串和模式串都从头到尾颠倒一下
第二个优化,与次数无关,所以排个序就完事了
1 #include<iostream> 2 #include<cstdio> 3 #include<queue> 4 #include<algorithm> 5 #include<cmath> 6 #include<ctime> 7 #include<set> 8 #include<map> 9 #include<stack> 10 #include<cstring> 11 #define inf 2147483647 12 #define ls rt<<1 13 #define rs rt<<1|1 14 #define lson ls,nl,mid,l,r 15 #define rson rs,mid+1,nr,l,r 16 #define N 100010 17 #define For(i,a,b) for(int i=a;i<=b;i++) 18 #define p(a) putchar(a) 19 #define g() getchar() 20 21 using namespace std; 22 int n; 23 char a[110],b[110],c[110],d[110]; 24 25 struct node{ 26 int f; 27 int s; 28 bool operator < (const node & temp)const{ 29 if(f==temp.f) 30 return s<temp.s; 31 return f<temp.f; 32 } 33 }a1[110],a2[110]; 34 35 void in(int &x){ 36 int y=1; 37 char c=g();x=0; 38 while(c<‘0‘||c>‘9‘){ 39 if(c==‘-‘)y=-1; 40 c=g(); 41 } 42 while(c<=‘9‘&&c>=‘0‘){ 43 x=(x<<1)+(x<<3)+c-‘0‘;c=g(); 44 } 45 x*=y; 46 } 47 void o(int x){ 48 if(x<0){ 49 p(‘-‘); 50 x=-x; 51 } 52 if(x>9)o(x/10); 53 p(x%10+‘0‘); 54 } 55 int main(){ 56 freopen("enchanted.in","r",stdin); 57 freopen("enchanted.out","w",stdout); 58 cin>>(a+1)>>(b+1)>>(c+1)>>(d+1); 59 n=strlen(a+1); 60 For(i,1,n){ 61 a1[i].f=a[i]-‘A‘+1; 62 a1[i].s=b[n-i+1]-‘A‘+1; 63 } 64 For(i,1,n){ 65 a2[i].f=c[i]-‘A‘+1; 66 a2[i].s=d[n-i+1]-‘A‘+1; 67 } 68 sort(a1+1,a1+n+1); 69 sort(a2+1,a2+n+1); 70 For(i,1,n) 71 if(a1[i].f!=a2[i].f||a1[i].s!=a2[i].s){ 72 cout<<"No"; 73 return 0; 74 } 75 cout<<"Yes"; 76 return 0; 77 }
以上是关于http://codeforces.com/gym/100623/attachments E题的主要内容,如果未能解决你的问题,请参考以下文章
http://codeforces.com/gym/100694/problem/M The Fifth Season (巴什博奕)
Codeforces Gym 100269 Dwarf Tower (最短路)