Codeforces Round #777 (Div. 2) 补题题解 (未完成)

11 篇文章 0 订阅

目录


过了两道题,继续加油

A Madoka and Math Dad

#include<bits/stdc++.h>

using namespace std;

int T;

int get1(int x){
	return x % 3;
}

int get2(int x){
	return x / 3;
}

int main()
{
	cin>>T;
	while(T -- ){
		int n;
		cin>>n;
		int x = get1(n);
		int y = get2(n);
		if(x == 1){
			cout<<"1";
			for(int i = 0; i < 2 * y; i ++ ){
				if(i % 2 == 0){
					cout<<"2";
				}
				else if(i % 2 == 1){
					cout<<"1";
				}
			}
		}
		else if(x == 2){
			for(int i = 0; i < 2 * y; i ++ ){
				if(i % 2 == 0){
					cout<<"2";
				}
				else if(i % 2 == 1){
					cout<<"1";
				}
			}
			cout<<"2";			
		}
		else if(x == 0){
			for(int i = 0; i < 2 * y; i ++ ){
				if(i % 2 == 0){
					cout<<"2";
				}
				else if(i % 2 == 1){
					cout<<"1";
				}
			}			
		}
		cout<<endl;
	}
	return 0;
}

B Madoka and the Elegant Gift

注意对题中条件进行转化,不要一味的跟着题走,例如这道题让你判断是否有相交的矩形,其实就是判断是否有0附近存在拐角三角形

#include<bits/stdc++.h>

using namespace std;

const int N = 105;

typedef pair<int, int>PII;

char r1[N][N];
int T;
int n, m;
int dx1[3] = {0, -1, -1};
int dy1[3] = {-1, -1, 0};
int dx2[3] = {-1, -1, 0};
int dy2[3] = {0, 1, 1};
int dx3[3] = {0, 1, 1};
int dy3[3] = {1, 1, 0};
int dx4[3] = {1, 1, 0};
int dy4[3] = {0, -1, -1};

bool check(int x, int y){
	int x1 = 0, x2 = 0, x3 = 0, x4 = 0;
	for(int i = 0; i < 3; i ++ ){
		int a = x + dx1[i], b = y + dy1[i];
		if(a <= n && a >= 1 && b >= 1 && b <= m){
			if(r1[a][b] == '1'){
				x1 ++ ;
			}
		}
	}
	
	for(int i = 0; i < 3; i ++ ){
		int a = x + dx2[i], b = y + dy2[i];
		if(a <= n && a >= 1 && b >= 1 && b <= m){
			if(r1[a][b] == '1'){
				x2 ++ ;
			}
		}
	}
	
	for(int i = 0; i < 3; i ++ ){
		int a = x + dx3[i], b = y + dy3[i];
		if(a <= n && a >= 1 && b >= 1 && b <= m){
			if(r1[a][b] == '1'){
				x3 ++ ;
			}
		}
	}
	
	for(int i = 0; i < 3; i ++ ){
		int a = x + dx4[i], b = y + dy4[i];
		if(a <= n && a >= 1 && b >= 1 && b <= m){
			if(r1[a][b] == '1'){
				x4 ++ ;
			}
		}
	}	
	if(x1 == 3 || x2 == 3 || x3 == 3 || x4 == 3) return false;
	else return true;		
} 

vector<PII>res;

int main()
{
	cin>>T;
	while(T -- ){
		cin>>n>>m;
		for(int i = 1; i <= n; i ++ ){
			for(int j = 1; j <= m; j ++ ){
				cin>>r1[i][j];
				if(r1[i][j] == '0'){
					res.push_back({i, j});
				}
				
			}
		}
		bool flag = true;
		
		for(auto ve : res){
			if(!check(ve.first, ve.second)){
				flag = false;
				break;
			}			
		}
		res.clear();
		if(!flag) cout<<"NO"<<endl;
		else if(flag) cout<<"YES"<<endl;
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值