重现赛,一上来F就有人A了,,然后我就看题,果然是水题,然后直接敲,然后A了,中间j--写成j++卡了两分钟,,,
F:Friendship of Frog (水题
题意:给个字符串,输出任意相同的两字符之间的最小距离
思路:数据小,直接两重for循环就行、
代码:
#include<bits/stdc++.h>
using namespace std;
int T,ans,n,s;
char ch[1005];
int main()
{
s=0;
scanf("%d",&T);
while(T--)
{
ans=2000;
scanf("%s",ch);
n=strlen(ch);
for(int i=0;i<n;i++)
{
for(int j=(i-1);j>=0;j--)
{
if(ch[i]==ch[j])
{//cout<<i<<" "<<j<<endl;
ans=min(ans,i-j);
break;
}
}
}
if(ans==2000)
ans=-1;
printf("Case #%d: %d\n",++s,ans);
}
}
/*
2
abcecba
*/
然后队友读了K题 的题意,然后我感觉跟那场打炸的cf的C题炒鸡像!呕吼,然后就接手敲,结果,,大概是最近做matlab作业做多了,,中间求平方用了^...真是凉凉。。一直不报错,,但是就是答案不对,,,,调了半天才看出来,,,
K、Kingdom of Black and White (思维
题意:题意给定的一个01字符串,最多改变一个字符,0变1,1变0,也可不变,求所有连续的相同字符的长度的平方和的最大值
思路:从左到右记录平方和,从右到左记录平方和,再度与每个位置分析,求假若改变的价值,留最大、
代码:
#include<bits/stdc++.h>
using namespace std;
long long T,ans,n,s,l[100005],r[100005],numl[100005],numr[100005],all;
char ch[100005];
int main()
{
s=0;
scanf("%lld",&T);
while(T--)
{
scanf("%s",ch+1);
n=strlen(ch+1);
for(int i=0;i<=n;i++)
{
l[i]=r[i]=numl[i]=numr[i]=0;
}
l[1]=1;
numl[1]=1;
for(int i=2;i<=n;i++)
{
if(ch[i]==ch[i-1]) {
numl[i]=numl[i-1]+1;
l[i]=l[i-1]-numl[i-1]*numl[i-1]+numl[i]*numl[i];
}
else {
numl[i]=1;
l[i]=l[i-1]+1;
}
}
all=ans=l[n];
r[n]=1;
numr[n]=1;
for(int i=n-1;i>=1;i--)
{
if(ch[i]==ch[i+1]) {
numr[i]=numr[i+1]+1;
r[i]=r[i+1]-numr[i+1]*numr[i+1]+numr[i]*numr[i];
}
else {
numr[i]=1;
r[i]=r[i+1]+1;
}
}
if(ch[1]!=ch[2])
{
ans=max(ans,r[2]+numr[2]*2+1);
}
if(ch[n]!=ch[n-1])
{
ans=max(ans,l[n-1]+numl[n-1]*2+1);
}//cout<<ans<<"!!"<<endl;
for(int i=2;i<n;i++)
{
if(ch[i]!=ch[i-1]&&ch[i]!=ch[i+1])
{
ans=max(ans,all-numl[i-1]*numl[i-1]-numr[i+1]*numr[i+1]-1+(numl[i-1]+numr[i+1]+1)*(numl[i-1]+numr[i+1]+1));
//cout<<i<<" "<<numl[i-1]<<" "<<numr[i+1]<<" "<<(all-numl[i-1]*numl[i-1]-numr[i+1]*numr[i+1]-1)<<" ~!!"<<endl;
}
else if(ch[i]==ch[i+1]&&ch[i]==ch[i-1])
{
continue;
}
else if(ch[i-1]==ch[i])
{
ans=max(ans,all-numl[i]*numl[i]+(numl[i]-1)*(numl[i]-1)+numr[i+1]*2+1);
// cout<<i<<" "<<ans<<" !!"<<endl;
}
else
{
ans=max(ans,all-numr[i]*numr[i]+(numr[i]-1)*(numr[i]-1)+numl[i-1]*2+1);
// cout<<i<<" "<<ans<<" !!"<<endl;
}
}
printf("Case #%lld: %lld\n",++s,ans);
}
}
/*
2
000011
0101
*/
我做K做了很久,队友就在推L,敲完后,接手队友推的部分结论(主函数部分等)接着推、A题和L题的题意都出来了,队友去做A了,然后我们另两个人继续推L,过了一阵推出了,然后我敲AA函数,然后发给队友,让他接着敲主函数部分。最后因为long long WA了一发,,又因为AA函数的for循环没有考虑1.。。WA了一发,,然后才A的。。
L:LCM Walk (数学,推公式
题意:(不想敲了,,太难描述 了,,,)
思路:队友推出对于点(x,y),若x>y,只可能是从x方向过来的,y>x,则只可能是从y方向过来的、
假设y>x,从来的方向走到(x,y)最后一步走了z步,上个点是(x,y‘),
z%x==0;z%y'==0;
y'+z==y; ==> y'+k*y'==y; ==> y%y'==0;
而对于y’,
z==(y/y'-1)*y';
若:
z%x==0;
z==x*y'/gcd(x,y')
==x*(y-z)/gcd(x,y-z)
则:上一点到(x,y)点走了z步.
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x,y;
ll AA(ll X,ll Y)//X>Y
{
ll l=sqrt(X);
ll Z;
for(int i=1;i<=l;i++)
{
if(X%i==0)
{
Z=(X/i-1)*i;
if(Z%Y==0)
{
if(Z==Y*(X-Z)/__gcd(Y,X-Z))
{
return Z;
}
}
Z=(i-1)*(X/i);
if(Z%Y==0)
{
if(Z==Y*(X-Z)/__gcd(Y,X-Z))
{
return Z;
}
}
}
}
return -1;
}
int main()
{
int T,cas=1;
scanf("%d",&T);
while(T--)
{
scanf("%lld%lld",&x,&y);
printf("Case #%d: ",cas++);
ll ans=1;
ll t;
bool f1=1,f2=1;
while(1)
{
f1=1;f2=1;
while(x>y)
{
t=AA(x,y);
if(t!=-1)
{
ans++;
f1=0;
}
else
break;
x-=t;
}
while(x<y)
{
t=AA(y,x);
if(t!=-1)
{
ans++;
f2=0;
}
else
break;
y-=t;
}
if(f1&&f2)
break;
}
printf("%lld\n",ans);
}
return 0;
}
然后队友一直在做A题,我们剩下两个就在看B,,凉凉、都没有做出来、可惜了。。
A是个推数学公式,,就是细节太多了,!!!300行的代码了都,还是没有A,真是可惜了,,
B题,我们最后也没有看出来规律。。。