A超级水,三分钟1a
#include<map> #include<set> #include<cmath> #include<queue> #include<stack> #include<vector> #include<cstdio> #include<cassert> #include<iomanip> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define C 0.5772156649 #define pi acos(-1.0) #define ll long long #define mod 1000000007 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-7; const int N=100000+10,maxn=500+100,inf=0x3f3f3f; int main() { ios::sync_with_stdio(false); cin.tie(0); ll a,b; cin>>a>>b; ll ans=a/b; if(ans&1)cout<<"YES"<<endl; else cout<<"NO"<<endl; return 0; } /********************* *********************/
B有点坑啊,我分了很多种情况考虑,最后重判还是wa了,考虑输入字符串与原来字符串的长度问题
#include<map> #include<set> #include<cmath> #include<queue> #include<stack> #include<vector> #include<cstdio> #include<cassert> #include<iomanip> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define C 0.5772156649 #define pi acos(-1.0) #define ll long long #define mod 1000000007 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-7; const int N=100000+10,maxn=500+100,inf=0x3f3f3f; bool good[30]; int main() { ios::sync_with_stdio(false); cin.tie(0); string s,p; cin>>s>>p; memset(good,0,sizeof good); for(int i=0;i<s.size();i++) good[s[i]-'a']=1; int k; cin>>k; while(k--){ string a; cin>>a; if(a.size()>p.size()) { bool ok=1; int res=a.size()-p.size(),i,j; for(i=0,j=0;i<p.size()&&j<a.size();) { if(p[i]=='?') { if(!good[a[j]-'a']) { ok=0; break; } } else if(p[i]=='*') { for(int l=i;l<=i+res;l++) if(good[a[l]-'a']) { ok=0; break; } } else { if(p[i]!=a[j]) { // cout<<i<<" "<<j<<endl; ok=0; break; } } if(p[i]=='*')i++,j+=res+1; else i++,j++; } // cout<<i<<" "<<j<<endl; if(ok&&j==a.size())cout<<"YES"<<endl; else cout<<"NO"<<endl; } else if(a.size()+1==p.size()) { bool ok=1; int i,j; for(i=0,j=0;i<p.size();) { if(p[i]=='?') { if(!good[a[j]-'a']) { ok=0; break; } } else if(p[i]!='*') { if(a[j]!=p[i]) { ok=0; break; } } if(p[i]=='*')i++; else i++,j++; // cout<<i<<" "<<j<<endl; } if(ok&&i==p.size())cout<<"YES"<<endl; else cout<<"NO"<<endl; } else if(a.size()+1<p.size()) { cout<<"NO"<<endl; continue; } else { bool ok=1; for(int i=0;i<p.size();i++) { if(p[i]=='?') { if(!good[a[i]-'a']) { ok=0; break; } } else if(p[i]=='*') { if(good[a[i]-'a']) { ok=0; break; } } else { if(a[i]!=p[i]) { ok=0; break; } } } if(ok)cout<<"YES"<<endl; else cout<<"NO"<<endl; } } return 0; } /********************* a ab 1 a *********************/
C过的人很少,放弃了
D比赛的时候知道是lca,但是不会lca了(太弱了。)
先三个点求lca,找到最深的节点就是转折点,然后求转折点到三个点的最大距离+1就是答案了
#include<map> #include<set> #include<cmath> #include<queue> #include<stack> #include<vector> #include<cstdio> #include<cassert> #include<iomanip> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define C 0.5772156649 #define pi acos(-1.0) #define ll long long #define ull unsigned long long #define mod 1000000007 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-12; const int N=100000+10,maxn=500+100,inf=0x3f3f3f; vector<int>v[N]; int depth[N],father[20][N]; void dfs(int u,int f,int d) { father[0][u]=f; depth[u]=d; for(int i=0;i<v[u].size();i++) if(v[u][i]!=f) dfs(v[u][i],u,d+1); } int lca(int x,int y) { if(depth[x]>depth[y])swap(x,y); for(int k=0;k<20;k++) if((depth[y]-depth[x])>>k&1) y=father[k][y]; if(x==y)return x; for(int k=20-1;k>=0;k--) { if(father[k][x]!=father[k][y]) { x=father[k][x]; y=father[k][y]; } } return father[0][x]; } int dis(int x,int y) { return depth[x]+depth[y]-2*depth[lca(x,y)]; } void init(int n) { dfs(1,-1,0); for(int i=1;i<20;i++) { for(int j=1;j<=n;j++) { father[i][j]=father[i-1][father[i-1][j]]; } } } int main() { /* ios::sync_with_stdio(false); cin.tie(0);*/ int n,q; scanf("%d%d",&n,&q); for(int i=1;i<=n;i++)v[i].clear(); for(int i=2;i<=n;i++) { int a; scanf("%d",&a); v[i].push_back(a); v[a].push_back(i); } memset(father,-1,sizeof father); memset(depth,0,sizeof depth); init(n); while(q--){ int a,b,c; scanf("%d%d%d",&a,&b,&c); int x=lca(a,b),y=lca(b,c),z=lca(a,c); //cout<<x<<" "<<y<<" "<<z<<endl; if(depth[x]<depth[y])x=y; if(depth[x]<depth[z])x=z; printf("%d ",max(dis(x,a),max(dis(x,b),dis(x,c)))+1); } return 0; } /********************* 3 2 1 1 1 2 3 2 3 3 *********************/