改成%c即AC……
这道题的意思是在10序列中看1的位置是否等距,所以使用flag记录第一个和第二个出现的1,获得步长pace,然后如果之后1不是按照pace的步长出现,即为NO,读完即为YES
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int n,pace=0,p=0;
int first=0,flag=0;
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
cin>>n;
char c;
scanf("%c",&c);
for(int i=1;i<=n;i++)
{
scanf("%c",&c);
if(flag==0)
{
if(c=='1')flag=1;
else;
}
else if(flag==1)
{
if(c=='1')flag=2;
else pace++;
}
else
{
if(c=='1')
{
if(p!=pace)
{
puts("NO");
return 0;
}
else p=0;
}
else p++;
}
}
puts("YES");
return 0;
}

本文介绍了一种检测外星信号规律性的算法实现。通过记录连续信号间的等间距判断是否有智慧生命迹象。

1331

被折叠的 条评论
为什么被折叠?



