QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#505183#2833. HamiltonxiaohuzaiCompile Error//C++142.7kb2024-08-04 21:30:492024-08-04 21:30:49

Judging History

你现在查看的是最新测评结果

  • [2024-08-04 21:30:49]
  • 评测
  • [2024-08-04 21:30:49]
  • 提交

answer

#include<bits/stdc++.h>
#define gt getchar
#define pt putchar
#define fst first
#define scd second
typedef long long ll;
using namespace std;
const int N=2005;
typedef pair<int,int> pii;
inline bool __(char ch){return ch>=48&&ch<=57;}
template<class T> inline void read(T &x){
	x=0;bool sgn=0;char ch=gt();
	while(!__(ch)&&ch!=EOF) sgn|=(ch=='-'),ch=gt();
	while(__(ch)) x=(x<<1)+(x<<3)+(ch&15),ch=gt();
	if(sgn) x=-x;
}
template<class T,class ...T1> inline void read(T &x,T1 &...x1){
	read(x);
	read(x1...);
}
template<class T> inline void print(T x){
	static char st[70];short top=0;
	if(x<0) pt('-');
 	do{st[++top]=x>=0?(x%10+48):(-(x%10)+48),x/=10;}while(x);
    while(top) pt(st[top--]);
}
template<class T> inline void printsp(T x){
	print(x);
	putchar(' ');
}
template<class T> inline void println(T x){
	print(x);
	putchar('\n');
}
bool a[N][N];
int nxt[N],st,pre[N];
map<int,int>M; 
void solve(int n){
	M.clear();
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			char ch;cin>>ch;
			a[i][j]=ch-'0';
		}
	}
	for(int i=0;i<=n;i++)nxt[i]=0,pre[i]=0;
	int nn=1,st=1;
	nxt[1]=2,nxt[2]=1;
	pre[2]=1;pre[1]=2; 
	for(int i=3;i<=n;i++){
		if(nn==1){ 
			nxt[i]=nxt[st];pre[nxt[st]]=i;
			nxt[st]=i;pre[i]=st;
		//	for(int j=1;j<=n;j++)cout<<nxt[j]<<" "<<a[j][nxt[j]]<<endl;
			if(a[i][nxt[i]]!=a[st][i]||a[st][i]!=a[pre[st]][st]||a[i][nxt[i]]!=a[nxt[i]][nxt[nxt[i]]])nn=2; 
		}
		else{
			int nw=st,ck=0,ckk=0; 
			while(nw!=st||ckk==0){ 
				ckk=1;
				if(a[pre[nw]][nw]==0&&a[nw][nxt[nw]]==1){
					if(a[i][nw]==1){
						nxt[pre[nw]]=i,pre[i]=pre[nw];
						nxt[i]=nw,pre[nw]=i;
					}
					else{
						pre[nxt[nw]]=i,nxt[i]=nxt[nw];
						nxt[nw]=i,pre[i]=nw;	
					}
					ck=1;
					break;
				}
				if(a[pre[nw]][nw]==1&&a[nw][nxt[nw]]==0){
					//puts("!");
					if(a[i][nw]==1){
						pre[nxt[nw]]=i,nxt[i]=nxt[nw];
						nxt[nw]=i,pre[i]=nw;
					}
					else{
						nxt[pre[nw]]=i,pre[i]=pre[nw];
						nxt[i]=nw,pre[nw]=i;	
					}
					ck=1;
					break;
				}
				nw=nxt[nw];
			} 
			int nw=st,ck=0,ckk=0; 
			while(nw!=st||ckk==0){ 
				ckk=1;
				M[a[nw][nxt[nw]]]=1;
				nw=nxt[nw];
			} 
			if(M[0]&&M[1])puts("-1");
			//assert(ck!=0);
		}
	}
//	for(int i=1;i<=n;i++)cout<<nxt[i]<<" "<<a[i][nxt[i]]<<endl;
	for(int i=1;i<=n;i++){	
		int ck=0,ck1=0,nw=-1;
		st=i; 
		while(st!=i||nw==-1){
			nw=0;
			if(ck&&a[st][nxt[st]]==0){ck1=-1;break;}
			if(a[st][nxt[st]]==1)ck=1;
			st=nxt[st]; 
		} 
		if(ck1==0){
			st=i;nw=-1;
			while(st!=i||nw==-1){
				nw=0;
				printsp(st);
				st=nxt[st];
			}
			cout<<endl;
			return;
		}
	}
	puts("-1");
	//assert(0);
} 
int main(){
	int n;
	while(scanf("%d",&n)!=EOF){
	//cin>>n;
		solve(n);
	}
	return 0;
}

详细

answer.code: In function ‘void solve(int)’:
answer.code:88:29: error: redeclaration of ‘int nw’
   88 |                         int nw=st,ck=0,ckk=0;
      |                             ^~
answer.code:58:29: note: ‘int nw’ previously declared here
   58 |                         int nw=st,ck=0,ckk=0;
      |                             ^~
answer.code:88:35: error: redeclaration of ‘int ck’
   88 |                         int nw=st,ck=0,ckk=0;
      |                                   ^~
answer.code:58:35: note: ‘int ck’ previously declared here
   58 |                         int nw=st,ck=0,ckk=0;
      |                                   ^~
answer.code:88:40: error: redeclaration of ‘int ckk’
   88 |                         int nw=st,ck=0,ckk=0;
      |                                        ^~~
answer.code:58:40: note: ‘int ckk’ previously declared here
   58 |                         int nw=st,ck=0,ckk=0;
      |                                        ^~~