# Group Competition 4th 2017 Chinese College Students Programming Competition - Hangzhou Station

A - Super-palindrome

Topic:
Given a string, you can change any letter at a time, and find the minimum number of operations to make all odd-length substrings palindrome strings
Title Analysis:
Check-in questions, as an example shows, strings that meet the requirements must match both odd and even numbers of characters equally
Code:

```#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define int long long
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int>PII;
typedef pair<double,double>PDD;
typedef set<int>::iterator SIT;
int dx[]={0,-1,0,1},dy[]={-1,0,1,0};
int gcd(int a,int b) {return b?gcd(b,a%b):a;}
int lcm(int a,int b) {return a/gcd(a,b)*b;}
const double eps=1e-6;
const int INF=0x3f3f3f3f,mod=1e9+7;
const int N=110;
int odd[N],even[N];
char s[N];
signed main(){
fast;
int T;
cin>>T;
while(T--){
memset(odd,0,sizeof(odd));
memset(even,0,sizeof(even));
cin>>s+1;
int n=strlen(s+1);
for(int i=1;i<=n;i++){
if(i&1) odd[s[i]-'a']++;
else even[s[i]-'a']++;
}
int maxv=-1;
int sum=0;
for(int i=0;i<26;i++)
maxv=max(maxv,odd[i]);
sum+=maxv;
maxv=-1;
for(int i=0;i<26;i++)
maxv=max(maxv,even[i]);
sum+=maxv;
cout<<n-sum<<endl;
}
return 0;
}
```

J - Master of GCD (Differential + Fast Power)

Topic:
An array of length n is initialized to 1, and then m operations are performed, each time multiplying the number on the interval [l, r] by 2 or 3, and finding the gcd of the interval
Title Analysis:
First thought it was a segment tree, then copied the board and adjusted it for half a day (find out how well your segment tree is written). Then the teammate counted the number of occurrences of 2 and 3. The answer is the smallest power of 2 times the smallest power of 3. The data is large and the number of statistics can be maintained with a difference array.
Code:

```#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define int long long
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int>PII;
typedef pair<double,double>PDD;
typedef set<int>::iterator SIT;
int dx[]={0,-1,0,1},dy[]={-1,0,1,0};
int gcd(int a,int b) {return b?gcd(b,a%b):a;}
int lcm(int a,int b) {return a/gcd(a,b)*b;}
const double eps=1e-6;
const int INF=0x3f3f3f3f,mod=998244353;
const int N=1e5+10;
int a2[N],b2[N];
int a3[N],b3[N];
int n,m;
int qmi(int a,int b,int p)
{
int res=1%p;
while(b){
if(b&1) res=res*a%p;
a=a*a%p;
b>>=1;
}
return res;
}
signed main()
{
fast;
int T;
cin>>T;
while(T--){
memset(a2,0,sizeof(a2));
memset(b2,0,sizeof(b2));
memset(a3,0,sizeof(a3));
memset(b3,0,sizeof(b3));
cin>>n>>m;
while(m--){
int l,r,c;
cin>>l>>r>>c;
if(c==2){
b2[l]++;
b2[r+1]--;
}
else if(c==3){
b3[l]++;
b3[r+1]--;
}
}
int min2=INF,min3=INF;
for(int i=1;i<=n;i++){
a2[i]=b2[i]+a2[i-1];
a3[i]=b3[i]+a3[i-1];
min2=min(min2,a2[i]);
min3=min(min3,a3[i]);
}
int ans=1;
ans=qmi(2,min2,mod);
ans=ans*qmi(3,min3,mod)%mod;
cout<<ans%mod<<endl;
}
return 0;
}
```

C - Hakase and Nano (Thought + Game)

Topic:
Given the number of n heaps of stones and the order of succession, the first person can choose a heap of stones to remove at least one stone, the second person can operate twice, who takes the last heap wins, and if the second wins, outputs Yes, otherwise outputs No
Title Analysis: The search for winning or losing game is an important point to solve. Through analysis, we can know that the second person must lose if he starts first. The state of the second person must be n times 3 and the number of stones in all heaps must be 1. If the first person starts first, we can think about what conditions can be changed into the second person's losing state by one operation, because we canOne operation, where n-1 is a multiple of 3 and the number of heaps in 1 is n-1 or n, the other is a multiple of n-3 and the number of 1 is n-1
Code:

```#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define int long long
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int>PII;
typedef pair<double,double>PDD;
typedef set<int>::iterator SIT;
int dx[]={0,-1,0,1},dy[]={-1,0,1,0};
int gcd(int a,int b) {return b?gcd(b,a%b):a;}
int lcm(int a,int b) {return a/gcd(a,b)*b;}
const double eps=1e-6;
const int INF=0x3f3f3f3f,mod=998244353;
const int N=1e6+10;
int n,op;
int a[N];
signed main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%d %d",&n,&op);
int cnt=0;
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
if(a[i]==1) cnt++;
}
if(op==1){
if(n%3==0&&cnt==n)
puts("No");
else
puts("Yes");
}
else{
if((n%3==1&&cnt>=n-1)||(n%3==0&&cnt==n-1))
puts("No");
else
puts("Yes");
}
}
return 0;
}
```

B D to be filled

Posted on Sun, 12 Sep 2021 12:27:18 -0400 by goodgeneguo