A:差点开场懵逼。只要有相邻两位不同就可以作为答案。
#include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; int read() { int x=0,f=1;char c=getchar(); while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();} while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar(); return x*f; } #define N 1010 int n,cnt[N][26]; char s[N]; int main() { n=read(); scanf("%s",s+1); for (int i=1;i<n;i++) if (s[i]!=s[i+1]) {cout<<"YES "<<s[i]<<s[i+1];return 0;} cout<<"NO"; return 0; }
B:模拟。
#include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; int read() { int x=0,f=1;char c=getchar(); while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();} while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar(); return x*f; } #define N 200010 int n,a[N],b[N]; bool flag[N]; int main() { n=read(); for (int i=1;i<=n;i++) a[i]=read(); for (int i=1;i<=n;i++) b[i]=read(); int x=0; for (int i=1;i<=n;i++) { int t=0; if (!flag[b[i]]) { while (a[x+1]!=b[i]) x++,flag[a[x]]=1,t++; x++,flag[a[x]]=1,t++; } printf("%d ",t); } return 0; }
C:存在长度为n的移动序列能够到达(x,y)的充要条件显然是n>=abs(x)+abs(y)且n和x+y奇偶性相同。枚举修改区间的左端点,二分右端点即可。
#include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; int read() { int x=0,f=1;char c=getchar(); while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();} while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar(); return x*f; } #define N 200010 int n,x,y,p,q,cnt[4],a[N],cntx[N],cnty[N],ans=N; char s[N]; int wx[4]={0,0,-1,1},wy[4]={1,-1,0,0}; int main() { n=read(); scanf("%s",s+1); for (int i=1;i<=n;i++) { if (s[i]=='U') a[i]=0; if (s[i]=='D') a[i]=1; if (s[i]=='L') a[i]=2; if (s[i]=='R') a[i]=3; } x=read(),y=read(); if (n<abs(x)+abs(y)||(n&1)!=(abs(x)+abs(y)&1)) {cout<<-1;return 0;} for (int i=n;i>=1;i--) cntx[i]=cntx[i+1]+wx[a[i]],cnty[i]=cnty[i+1]+wy[a[i]]; for (int i=1;i<=n;i++) { int l=i-1,r=n,t=N*2; while (l<=r) { int mid=l+r>>1; if (abs(p+cntx[mid+1]-x)+abs(q+cnty[mid+1]-y)<=mid-i+1&&(abs(p+cntx[mid+1]-x)+abs(q+cnty[mid+1]-y)&1)==(mid-i+1&1)) t=mid,r=mid-1; else l=mid+1; } ans=min(ans,t-i+1); p+=wx[a[i]],q+=wy[a[i]]; } cout<<ans; return 0; }
D:每次先把能跑完整整一圈的减掉,然后暴力。由a%b<=a/2(a>=b),复杂度nlog。根本想不到复杂度是对的啊?
E:比赛时非常弱智的弃掉D去看E。直到最后也没调出来。数位dp(其实根本算不上dp),枚举到第几位卡限制,计算每个位置上数字的贡献,这只要dp出f[i][j]为已经确定了有j种数字存在还剩i位要填时的方案数,就可以暴力计算了。注意前导0不能算在数字集里。不明白为什么绝大多数人都写的状压。
#include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; int read() { int x=0,f=1;char c=getchar(); while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();} while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar(); return x*f; } #define ll long long #define P 998244353 ll l,r; int k,a[20],p[20],f[20][13]; void inc(int &x,int y){x+=y;if (x>=P) x-=P;} int calc(ll m) { int ans=0,n=-1; while (m) a[++n]=m%10,m/=10; bool flag[10]; for (int i=n;~i;i--) { for (int j=(i==n?1:0);j<a[i];j++) { memset(flag,0,sizeof(flag)); for (int k=n;k>i;k--) flag[a[k]]=1; flag[j]=1; int cnt=0; for (int k=0;k<10;k++) cnt+=flag[k]; if (cnt>k) continue; int last=0; for (int k=n;k>i;k--) last=(10ll*last+a[k])%P; last=(10ll*last+j)%P; last=1ll*last*p[i]%P; last=1ll*last*f[i][cnt]%P; inc(ans,last); for (int x=i-1;x>=0;x--) { for (int y=0;y<10;y++) if (flag[y]) inc(ans,1ll*y*p[x]%P*f[i-1][cnt]%P); else inc(ans,1ll*y*p[x]%P*f[i-1][cnt+1]%P); } } } for (int i=n-1;~i;i--) { for (int j=1;j<10;j++) { memset(flag,0,sizeof(flag)); flag[j]=1; int cnt=0; for (int k=0;k<10;k++) cnt+=flag[k]; if (cnt>k) continue; int last=j; last=1ll*last*p[i]%P; last=1ll*last*f[i][cnt]%P; inc(ans,last); for (int x=i-1;x>=0;x--) { for (int y=0;y<10;y++) if (flag[y]) inc(ans,1ll*y*p[x]%P*f[i-1][cnt]%P); else inc(ans,1ll*y*p[x]%P*f[i-1][cnt+1]%P); } } } return ans; } int main() { cin>>l>>r>>k; p[0]=1;for (int i=1;i<=19;i++) p[i]=10ll*p[i-1]%P; memset(f,0,sizeof(f)); for (int i=0;i<=k;i++) f[0][i]=1; for (int i=1;i<=19;i++) for (int j=0;j<=k;j++) f[i][j]=(1ll*f[i-1][j]*j+1ll*f[i-1][j+1]*(10-j))%P; cout<<(calc(r+1)-calc(l)+P)%P; return 0; }
F:没看
G:没认真看,似乎几乎是SA的板子题。
小号打的。result:rank 484 rating +58 感觉没什么救了。