第二个测试点疑似有误
  • 板块P2628 冒险岛
  • 楼主萝卜
  • 当前回复2
  • 已保存回复2
  • 发布时间2021/10/9 16:10
  • 上次更新2023/11/4 04:16:33
查看原帖
第二个测试点疑似有误
7836
萝卜楼主2021/10/9 16:10
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;

int l,p,n,a,fd[1000005],bk[1000005];
char c;
string s;

int main(){
	cin>>s;
	l=s.length();
	while(--l>=0)
	{
		c=s[l];
		if(c=='>')fd[l+1]=fd[l+2]+1;
		if(c=='*')bk[l+1]=bk[l+2]+1;
	}
	l=s.length();
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a);
		p+=a;
		if     (fd[p]>2)p+=fd[p];
		else if(bk[p]>2)p-=bk[p];
		if(p<0)p=0;
		if(p>l)p=l;
	}
	if(p==0){printf("2 999998");exit(0);}
	printf("%d %d",p,l-p);
	return 0;
}

其中:p表示当前位置,从0出发,第一个有字符的位置是1。以上代码对于p<0的处理显然是错误,但是能AC,说明只有最后特判的第二个数据点出现了p<0的情况。 改正上述错误并去掉特判后的代码如下:

#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;

const int N = 1000005;
int n,a,fd[N],bk[N];
string s;

int main(){
	cin>>s;
	int l=s.length();
	while(--l>=0)
	{
		if(s[l]=='>')fd[l+1]=fd[l+2]+1;
		if(s[l]=='*')bk[l+1]=bk[l+2]+1;
	}
	l=s.length();
	scanf("%d",&n);
	int p=0;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a);
		p+=a;
		if(fd[p]>2)p+=fd[p];
		else if(bk[p]>2)p-=bk[p];
		if(p<1)p=1;
		else if(p>l)p=l;
	}
	if(p==0)printf("%d ",n);
	printf("%d %d",p,l-p);
	return 0;
} 

第二个点WA,显示信息:“Wrong Answer. wrong answer On line 1 column 1, read 0, expected 2. ”。已知该点答案是"2 999998",以上代码会出现p==0的情况仅限于没扔骰子,否则p至少是1。我在p==0时输出n的值,结果也是0。这说明这个测试点在n==0的情况下往前走了两格?

2021/10/9 16:10
加载中...