「CF525X」Codeforces Round #297 (Div. 2)
A. Vitaliy and Pie
模拟
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
#include<cmath> #include<ctime> #include<cstdio> #include<vector> #include<bitset> #include<cstring> #include<iostream> #include<algorithm> #define ll long long #define mod 1000000009 #define inf 1000000000 using namespace std; ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int n,ans; char ch[200005]; int cnt[100005]; int main() { n=read(); scanf("%s",ch+1); for(int i=1;i<n;i++) { cnt[ch[2*i-1]-'a']++; if(!cnt[ch[2*i]-'A']) ans++; else cnt[ch[2*i]-'A']--; } printf("%d\n",ans); return 0; } |
B. Pasha and String
前缀和记录一下每个点的翻转次数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
#include<cmath> #include<ctime> #include<cstdio> #include<vector> #include<bitset> #include<cstring> #include<iostream> #include<algorithm> #define ll long long #define mod 1000000009 #define inf 1000000000 using namespace std; ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int n,m,x; char a[200005]; int t[200005]; int main() { scanf("%s",a+1); n=strlen(a+1); m=read(); for(int i=1;i<=m;i++) { int x=read(); t[x]++;t[n-x+2]--; } for(int i=1;i<=n;i++) { t[i]+=t[i-1]; if(t[i]%2==0)printf("%c",a[i]); else printf("%c",a[n-i+1]); } return 0; } |
C. Ilya and Sticks
排序后从大到小贪心
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
#include<cmath> #include<ctime> #include<cstdio> #include<vector> #include<bitset> #include<cstring> #include<iostream> #include<algorithm> #define ll long long #define mod 1000000009 #define inf 1000000000 using namespace std; ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int n; ll a[100005],x,ans; int main() { n=read(); for(int i=1;i<=n;i++)a[i]=read(); sort(a+1,a+n+1); for(int i=n-1;i>=1;i--) { if(a[i+1]-a[i]<2) { if(x)ans+=x*a[i],x=0; else x=a[i]; i--; } } printf("%I64d\n",ans); return 0; } |
D. Arthur and Walls
如果某四个格子只有一个*,则把它变成.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
#include<map> #include<cmath> #include<ctime> #include<cstdio> #include<vector> #include<bitset> #include<cstring> #include<iostream> #include<algorithm> #define ll long long #define mod 1000000009 #define inf 1000000000 #define p(x,y) (x-1)*m+y using namespace std; ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int xx[4]={0,0,1,-1},yy[4]={1,-1,0,0}; int n,m; char a[2005][2005]; void dfs(int x,int y) { if(x<1||y<1||x==n||y==m)return; int t=0; for(int i=0;i<2;i++) for(int j=0;j<2;j++) if(a[i+x][j+y]=='*')t++; if(t==1) { for(int i=0;i<2;i++) for(int j=0;j<2;j++) a[i+x][j+y]='.'; for(int i=-1;i<2;i++) for(int j=-1;j<2;j++) dfs(i+x,j+y); } } int main() { n=read();m=read(); for(int i=1;i<=n;i++) scanf("%s",a[i]+1); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) dfs(i,j); for(int i=1;i<=n;i++) printf("%s\n",a[i]+1); return 0; } |
E.Anya and Cubes
折半搜索一下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
#include<map> #include<cmath> #include<ctime> #include<cstdio> #include<vector> #include<bitset> #include<cstring> #include<iostream> #include<algorithm> #define ll long long #define mod 1000000009 #define inf 1000000000 using namespace std; ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int n,K,m; ll S,ans,fac[25],a[30]; map<ll,int>f[30]; void dfs(int x,ll tot,int t) { if(tot>S||t>K)return; if(x==m+1) { if(m==n)f[t][S-tot]++; else { for(int i=0;i<=K-t;i++) ans+=f[i][tot]; } return; } if(a[x]<=20) dfs(x+1,tot+fac[a[x]],t+1); dfs(x+1,tot+a[x],t); dfs(x+1,tot,t); } int main() { fac[1]=1;for(int i=2;i<=20;i++)fac[i]=fac[i-1]*i; n=read();K=read();S=read(); for(int i=1;i<=n;i++)a[i]=read(); sort(a+1,a+n+1); m=n; dfs(n/2+1,0,0); m=n/2; dfs(1,0,0); cout<<ans<<endl; return 0; } |
[…] 我:先记录一下不同的位置各翻转了多少次,同一区间翻转两次相当于没有进行任何操作,所以直接%2。然后模拟一下输出 hzwer:差分+前缀和记录翻转 传送门 […]