table of Contents:
T1:魔法阵~
T2:小biu放牛
T3:小A的游戏
T4:小biu闯关
……
T1: Magic Array~
analysis:
It can be concluded that if you want to cut a regular polygon , the number of remaining sides must be nnn isa factor
we directenumeration of all of the remaining polygons and maximumon the line
CODE:
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=20005;
int n,a[N],fac_num,sum,factor[N],maxn,k,fac_tot,edge,nowfac;
void count_fac(int x)
{
for(int i=2;i<x;i++)
if(x%i==0)
{
fac_num++;
factor[fac_num]=i; //统计因数
}
}
void tp()
{
if(fac_num==0||n==3) //特判
{
printf("%d",sum);
exit(0);
}
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
maxn=sum; count_fac(n); tp();
for(int i=0;i<fac_num;i++)
{
nowfac=factor[i];k=1;
while(nowfac--)
{
fac_tot=0;edge=0;
for(int j=k;j<=n;j+=factor[i])
{
fac_tot+=a[j];
edge++; //枚举nowfac边形的所有和
}
if(edge>=3)
maxn=max(maxn,fac_tot); //最大和
k++;
}
}
printf("%d",maxn);
return 0;
}
T2: small biu herding cattle
analysis:
Two points of greed to consider cattle herding,
calculate the head of the cow by inputhead t a i l tail t a i l then judge the out-of-bounds situation
CODE:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=1e6+5;
int n,m,x,a[N];
bool check(int p)
{
int head=0,tail=0;
for(int i=1;i<=n;i++)
{
head=max(tail,a[i]-x-p); //计算head位置
if(abs(head-a[i]+x)>p) return 0; //判越界
tail=head+2*x; //计算tail
if(tail>m) return 0; //判越界
}
return true;
}
int main(){
scanf("%d%d%d",&n,&x,&m);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
int l=0,r=m;
while(l<=r) //二分答案
{
int mid=(l+r)>>1;
if(check(mid)) r=mid-1;
else l=mid+1;
}
if(l==(m|1)) printf("-1"); //m+1
else printf("%d",l);
return 0;
}
T3: Little A's game
analysis:
If you can’t tell, there must be repeated letters.
We can find a property : when the distance between the first pair of repeated letters <= k <= k<=It cannot be judged when k is
such asS = "SASS" S="SASS"S="SASS" k = 2 k=2 k=2 o'clock ifAS ASis leftA S can be deleted1, 3 1, 31,3 or1, 4 1, 41,4 So it is impossible to judge
, the first pair is1, 3 1, 31,3 distance is2 22 It meets the nature and cannot be judged
CODE:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,k,flag;
string s;
int main(){
scanf("%d",&n);
while(n--)
{
flag=0;
cin>>s;
scanf("%d",&k);
if(k==s.length()){
printf("Certain\n"); //特判
continue;
}
for(int i=0;i<s.length();i++)
{
for(int j=i+1;j<s.length();j++)
if(s[i]==s[j]) //重复字母
{
int dis=j-i; //距离
if(dis<=k)
{
flag=1;
printf("Uncertain\n");
break;
}
}
if(flag) break;
}
if(!flag)
printf("Certain\n");
}
return 0;
}
T4: Little biu breaks through
Write an article specifically about
Ababa
to sum up:
Generally not playing T 2 T 4 T2T4Part of T 2 T 4