#16734: 想請問此程式為甚麼無法通過測資2 3 4


david53133 (資三甲36大衛)

學校 : 國立臺北科技大學
編號 : 90740
來源 : [114.43.191.38]
最後登入時間 :
2021-04-12 14:57:46
c484. kevin 的西洋棋 | From: [114.137.96.89] | 發表日期 : 2019-02-03 00:12

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#define LOCAL
#define sc ss.clear()
#define sr ss.str(strLine)
#define st ss << strLine
using namespace std;

int F[40010] , N , M ;
int vis[40010];
vector<int> c[40010] ;

int DFSBG(int n){ //配對
vis[n] = 1 ;
for(int i = 0 ; i <c[n].size() ; i ++){
if(!vis[c[n][i]] & F[c[n][i]] == -1 ){
vis[c[n][i]] = 1 ;
if(F[c[n][i]] == -1 || DFSBG(F[c[n][i]])){
F[c[n][i]] = n ;
F[n] = c[n][i] ;
return 1 ;
}
}
}
return 0 ;
}

int goX[] = {0,-1,0,+1,0};
int goY[] = {0,0,+1,0,-1};

int main()
{
#ifdef LOCAL //習慣測試時會以檔案輸入 無須理會
freopen("in1.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif // LOCAL
string strLine ;
stringstream ss ;
while(getline(cin,strLine)){
if(strLine == "")
continue ;
sc; sr; st;
ss >> N >> M ;
int n2 = N * N ;
for(int i = 1 ; i <= n2 ; i++){
F[i] = -1 ;
c[i].clear();
}
int x , y , k ;
int L[N+1][N+1][5] = {} ;
int uk[] = {0,3,4,1,2};
for(int i = 0 ; i < M ; i++){ //2維陣列1維化
getline(cin ,strLine);
sc; sr; st;
ss >> x >> y >> k ;
L[x][y][k] = 1 ;
if(x + goX[k] > 0 && x + goX[k] <= N &&
y + goY[k]> 0 && y + goY[k] <= N )
L[x+goX[k]][y+goY[k]][uk[k]] = 1 ;
}
for(int i = 1 ; i <= N ; i++)
for(int j = 1 ; j <= N ; j++)
for(int i2 = 1 ; i2 < 5 ; i2++)
if(L[i][j][i2] == 0 && i + goX[i2] > 0 && i + goX[i2] <= N &&
j + goY[i2]> 0 && j + goY[i2] <= N )
c[(i-1)*N+j].push_back((i+goX[i2]-1)*N+j+goY[i2]);
int flag = 0 ;
for(int i = 1 ; i <= n2 ; i++){
if(F[i] == -1 ){
memset(vis,0,sizeof(vis));
if(!DFSBG(i)){
flag = 1 ;
break ;
}
}
}
cout << (flag ? "Kevin you cheat !" : "I win !") << "\n\n" ;
}
return 0;
}

出了甚麼Bug嗎?或是我未注意到的

 
ZeroJudge Forum