A.
#include <stdio.h> #include <string.h> #include <iostream> using namespace std; inline int F() { register int aa , bb , ch; while(ch = getchar() , (ch<'0'||ch>'9') && ch != '-'); ch == '-' ? aa=bb=0 : (aa=ch-'0',bb=1); while(ch = getchar() , ch>='0'&&ch<='9') aa = aa*10 + ch-'0'; return bb ? aa : -aa; } const int Maxn = 100005; char a[Maxn] , b[Maxn]; int main() { scanf("%s",a+1); scanf("%s",b+1); int lena = strlen(a+1); int lenb = strlen(b+1); if(lena != lenb) { printf("%d\n",max(lena,lenb)); } if(lena == lenb) { bool flag = 0; for(int i=1; i<=lena; ++i) { if(a[i] != b[i]) { flag = 1; break; } } if(flag) printf("%d\n",lena); else puts("-1"); } }
B.
#include <stdio.h> #include <string.h> #include <iostream> using namespace std; inline int F() { register int aa , bb , ch; while(ch = getchar() , (ch<'0'||ch>'9') && ch != '-'); ch == '-' ? aa=bb=0 : (aa=ch-'0',bb=1); while(ch = getchar() , ch>='0'&&ch<='9') aa = aa*10 + ch-'0'; return bb ? aa : -aa; } const int Maxn = 100010; int n , a[Maxn]; int main() { n = F(); if(n > 100) puts("YES"); else { for(int i=1; i<=n; ++i) a[i] = F(); for(int i=1; i<=n; ++i) { for(int j=i+1; j<=n; ++j) { for(int k=j+1; k<=n; ++k) { if(a[i]+a[j] > a[k] && a[i]+a[k] > a[j] && a[j]+a[k] > a[i]) { puts("YES"); return 0; } } } } puts("NO"); } }
C.
#include <stdio.h> #include <string.h> #include <iostream> #include <memory.h> using namespace std; inline int F() { register int aa , bb , ch; while(ch = getchar() , (ch<'0'||ch>'9') && ch != '-'); ch == '-' ? aa=bb=0 : (aa=ch-'0',bb=1); while(ch = getchar() , ch>='0'&&ch<='9') aa = aa*10 + ch-'0'; return bb ? aa : -aa; } const int mod = 1000000007; const int Maxn = 1005; char s[Maxn]; int n , a[30] , mx = 0 , f[Maxn] , g[Maxn]; int main() { n = F(); scanf("%s",s+1); for(int i=1; i<=26; ++i) a[i] = F(); memset(g,42,sizeof(g)); f[0] = 1; g[0] = 0; for(int i=1; i<=n; ++i) { int lim = max(0,i - a[s[i]-'a'+1]); for(int j=i-1; j>=lim; --j) { lim = max(lim , i - a[s[j]-'a'+1]); if(i-j > mx) mx = i-j; f[i] = (f[i] + f[j]) % mod; g[i] = min(g[i] , g[j]+1); } } printf("%d\n%d\n%d\n",f[n],mx,g[n]); }
D.
#include <stdio.h> #include <string> #include <string.h> #include <iostream> #include <map> using namespace std; inline int F() { register int aa , bb , ch; while(ch = getchar() , (ch<'0'||ch>'9') && ch != '-'); ch == '-' ? aa=bb=0 : (aa=ch-'0',bb=1); while(ch = getchar() , ch>='0'&&ch<='9') aa = aa*10 + ch-'0'; return bb ? aa : -aa; } const int Maxn = 200010; map <string , int> mp; int n , m , q , fa[Maxn]; string tmp; int find(int x) { return fa[x] == x ? x : (fa[x] = find(fa[x]));} void ins(int a , int b) { fa[find(a)] = find(b); } int main() { n = F() , m = F() , q = F(); for(int i=1; i<=n; ++i) { cin>>tmp; mp[tmp] = i; } for(int i=1; i<=n+n; ++i) fa[i] = i; for(int i=1; i<=m; ++i) { int op = F(); cin>>tmp; int a = mp[tmp]; cin>>tmp; int b = mp[tmp]; if(op == 1) { if(find(a) == find(b)) { puts("YES"); } else if(find(a) == find(b+n)) { puts("NO"); } else { puts("YES"); ins(a,b); ins(a+n,b+n); } } else { if(find(a) == find(b)) { puts("NO"); } else if(find(a) == find(b+n)) { puts("YES"); } else { puts("YES"); ins(a,b+n); ins(b,a+n); } } } for(int i=1; i<=q; ++i) { cin>>tmp; int a = mp[tmp]; cin>>tmp; int b = mp[tmp]; if(find(a) == find(b)) { puts("1"); } else if(find(a) == find(b+n)) { puts("2"); } else puts("3"); } }
E.
#include <stdio.h> inline int F() { register int aa , bb , ch; while(ch = getchar() , (ch<'0'||ch>'9') && ch != '-'); ch == '-' ? aa=bb=0 : (aa=ch-'0',bb=1); while(ch = getchar() , ch>='0'&&ch<='9') aa = aa*10 + ch-'0'; return bb ? aa : -aa; } const int Maxn = 100010; const int Maxm = 2*Maxn; int n , a[Maxn] , f[Maxn][30] , fa[Maxn] , bin[30] , size[Maxn]; int to[Maxm] , next[Maxm] , g[Maxn] , ecnt = 0; long long ans; void ins(int a , int b) { to[++ecnt] = b; next[ecnt] = g[a]; g[a] = ecnt; } void dfs(int x) { size[x] = 1; for(int i=0; i<30; ++i) if(a[x]&bin[i]) ++f[x][i]; for(int i=g[x]; i; i=next[i]) { if(to[i] == fa[x]) continue; fa[to[i]] = x; dfs(to[i]); for(int j=0; j<30; ++j) { ans += (long long)bin[j] * (f[x][j] * (size[to[i]] - f[to[i]][j]) + f[to[i]][j] * (size[x] - f[x][j])); if(bin[j] & a[x]) f[x][j] += size[to[i]] - f[to[i]][j]; else f[x][j] += f[to[i]][j]; }size[x] += size[to[i]]; } } int main() { bin[0] = 1; for(int i=1; i<30; ++i) bin[i] = bin[i-1]<<1; n = F(); for(int i=1; i<=n; ++i) a[i] = F() , ans += a[i]; for(int i=1; i<n; ++i) { int p = F() , q = F(); ins(p , q); ins(q , p); } dfs(1); printf("%I64d\n",ans); }