求助
  • 板块题目总版
  • 楼主Leo2525
  • 当前回复7
  • 已保存回复7
  • 发布时间2023/7/11 13:19
  • 上次更新2023/11/3 10:34:09
查看原帖
求助
983112
Leo2525楼主2023/7/11 13:19
#include<bits/stdc++.h>
using namespace std;
int mp[51][51];
int cowx[101],
	cowy[101];
int r,c,n,x,y;
char t[201];

bool check(int x,int y) 
{
	bool flag1=1,flag2=1;
	for(int i=x-1;i>=1;i--) if(mp[i][y]) {flag1=false;break;}
	for(int i=y+1;i<=c;i++) if(mp[x][i]) {flag2=false;break;}
	return flag1||flag2;
}

bool checkALL()
{
	bool ok=true;
	for(int i=1;i<=n;i++)
	{
		int x=cowx[i],y=cowy[i];
		if(mp[x][y]&&check(x,y)==false)
		{
			ok=false;
			break;
		}
	}
	return ok;
}

int main()
{
	cin>>r>>c>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>cowx[i]>>cowy[i];gets(t); 
		mp[cowx[i]][cowy[i]]=i;
	}
	if(checkALL()) cout<<0;
	else
	{
		for(int i=1;i<=n;i++)
		{
			mp[cowx[i]][cowy[i]]=0;
			if(checkALL())
			{
            
				if(!mp[0][0]) mp[0][0]=true;
				cout<<i<<endl;
			}
			mp[cowx[i]][cowy[i]]=i;
		}
		if(!mp[0][0]) cout<<-1;
	}
	return 0;
}

一直输出

/tmp/compiler_v6opt8kt/src: 在函数‘int main()’中:
/tmp/compiler_v6opt8kt/src:37:25: 错误:‘gets’ was not declared in this scope; did you mean ‘fgets’?
   37 |   cin>>cowx[i]>>cowy[i];gets(t);  //去除其他字符
      |                         ^~~~
      |                         fgets

求助,AC的一关注

2023/7/11 13:19
加载中...