B. Putting Bricks in the Wall(思维)Codeforces Round - 新闻资讯 - 云南小程序开发|云南软件开发|云南网站建设-昆明葵宇信息科技有限公司

159-8711-8523

云南网建设/小程序开发/软件开发

知识

不管是网站,软件还是小程序,都要直接或间接能为您产生价值,我们在追求其视觉表现的同时,更侧重于功能的便捷,营销的便利,运营的高效,让网站成为营销工具,让软件能切实提升企业内部管理水平和效率。优秀的程序为后期升级提供便捷的支持!

您当前位置>首页 » 新闻资讯 » 技术分享 >

B. Putting Bricks in the Wall(思维)Codeforces Round

发表时间:2020-10-19

发布人:葵宇科技

浏览次数:77

原题链接:https://codeforces.com/contest/1421/problem/B

在这里插入图片描述
测试样例

input
3
4
S010
0001
1000
111F
3
S10
101
01F
5
S0101
00000
01111
11111
0001F
output
1
3 4
2
1 2
2 1
0

题意: 给定一个 n × n n\times n n×n的迷宫,现在 P i n k Pink Pink在起点 ( 1 , 1 ) (1,1) (1,1)处,终点在 ( n , n ) (n,n) (n,n)处, P i n k Pink Pink在开始游戏之前会选择一个数 0 0 0 1 1 1,迷宫的每个格子会存在一个 0 0 0 1 1 1的数字,游戏规则为 P i n k Pink Pink只能走相邻的且格子数为开始游戏前选择的数的格子。现在你最多有两次机会可以改变元素值,问你怎样才使得 P i n k Pink Pink不能走到终点。

解题思路: 这是一道思维题,不用想得很深,我们只需要知道 P i n k Pink Pink一开始走出起点的限制有两个格子 ( 1 , 2 ) (1,2) (1,2)和(2,1),走到终点也有两个格子限制 ( n ? 1 , n ) (n-1,n) (n?1,n) ( n , n ? 1 ) (n,n-1) (n,n?1)。那么只要使得这起点格子和终点格子起冲突即可。让这两组的格子元素值相反即可。 我们利用if判断即可得出答案。注意所有情况的考虑。

AC代码

/*
*邮箱:unique_powerhouse@qq.com
*blog:https://me.csdn.net/hzf0701
*注:文章若有任何问题请私信我或评论区留言,谢谢支持。
*
*/
#include<bits/stdc++.h>	//POJ不支持

#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pair

using namespace std;

const int inf = 0x3f3f3f3f;//无穷大
const int maxn = 205;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll>  pll;
typedef pair<int, int> pii;
//*******************************分割线,以上为自定义代码模板***************************************//

int t,n;
char graph[maxn][maxn];
int main(){
	//freopen("in.txt", "r", stdin);//提交的时候要注释掉
	IOS;
	while(cin>>t){
		while(t--){
			cin>>n;
			rep(i,0,n-1){
				cin>>graph[i];
			}
			char a1=graph[1][0],a2=graph[0][1],b1=graph[n-2][n-1],b2=graph[n-1][n-2];
			if(a1!=a2){
				if(b1!=b2){
					cout<<2<<endl;
					if(a1==b1){
						cout<<"2 1"<<endl;
						cout<<n<<" "<<n-1<<endl;
					}
					else{
						cout<<"2 1"<<endl;
						cout<<n-1<<" "<<n<<endl;
					}
				}
				else{
					if(a1==b1){
						cout<<1<<endl;
						cout<<"2 1"<<endl;
					}
					else{
						cout<<1<<endl;
						cout<<"1 2"<<endl;
					}
				}
			}
			else{
				if(b1==b2){
					if(b1==a1){
						cout<<2<<endl;
						cout<<"1 2"<<endl;
						cout<<"2 1"<<endl;
					}
					else{
						cout<<0<<endl;
					}
					continue;
				}
				if(b1==a1){
					cout<<1<<endl;
					cout<<n-1<<" "<<n<<endl;
				}
				else{
					cout<<1<<endl;
					cout<<n<<" "<<n-1<<endl;
				}
			}
		}
	}
	return 0;
}

相关案例查看更多