我是靠谱客的博主 孤独香水,最近开发中收集的这篇文章主要介绍Codeforces Round #644 (Div. 3)比赛链接 :Codeforces Round #644 (Div. 3),觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

Codeforces Round #644 (Div. 3)

比赛链接 :Codeforces Round #644 (Div. 3)

A. Minimal Square

题意:找出 a*b 正方形最小的面积

题解:比较边的(a2,b)或(a,b2)的长短

代码:

#include <iostream>
using namespace std;

int main() {
	int t, n, m;
	cin >> t;
	while(t--) {
		cin >> n >> m;
		if(n >= 2*m)
		cout << n*n << endl;
		else if(m >= n*2)
		cout << m*m << endl;
		else if (m >= n)
		cout << n*n*4 << endl;
		else if (n >= m)
		cout << m*m*4 << endl;
	}
	return 0;
}

B. Honest Coach

题意:把n个数分为两组,求出一组最大值与另一组最小值的相差最小

题解:把n个数排序,求出最小的差值

代码:

#include <iostream>
#include <algorithm>
using namespace std;

int a[100];
int b[100];

int main() {
	int t, n;
	cin >> t;
	while(t--) {
		int ans = 1000000;
		cin >> n;
		for(int i = 0; i < n; i++)
		cin >> a[i];
		sort(a,a+n);
		for(int i = 1; i < n; i++) {
			b[i] = a[i] - a[i-1];
			if(b[i] < ans)
			ans = b[i];
		}
		cout << ans << endl;
	}
	return 0;
}

C. Similar Pairs

题意:将奇数和偶数配对,如果没有配对这找相差为一的

题解:算出奇数和偶数的个数,如果是偶数就配对成功,如果不是,就找出一组相差为一的组合

代码

#include <iostream>
#include <algorithm>
using namespace std;

int a[100];
int b[100];

int main() {
	int t, n;
	cin >> t;
	while(t--) {
		bool K = false;
		int k1 = 0;
		int k2 = 0;
		cin >> n;
		for(int i = 0; i < n; i++) {
			cin >> a[i];
			if(a[i]%2 == 0)
			k2++;
			else
			k1++;
		}
		if(k1%2 == 0 && k2 % 2 == 0) {
			cout << "YES" << endl;
			continue;
		} 
		sort(a,a+n);
		for(int i = 1; i < n; i++) {
			b[i] = a[i] - a[i-1];
			if(b[i] == 1) {
				K = true;
			}
		}
		if(K == true) 
		cout << "YES" << endl;
		else
		cout << "NO" << endl;
	}
	return 0;
}

D. Buying Shovels

题意:要n把铲子,有k种包装,包装内分别是1~k把铲子,选一种包装,求最少要买多少个

题解:在n的因子中找小于等于k的最大因子,n除以因子为结果

#include<iostream>
#include<cmath>
 
using namespace std;
 
int t,n,k;
int main() {
	cin >> t;
	while(t--) {
		cin >> n >> k;
		if(n <= k) {
			cout << 1 << endl;
			continue;
		}
		int ans = n;
		for(int i = 1; i <= (int)sqrt(n); ++i) {
			if(n%i == 0) {
				if(n/i <= k) {
					ans = min(ans,n/(n/i));
				}
				if(i <= k) {
					ans = min(ans,n/i);
				}
			}
		} 
		cout << ans << endl;
	}
	
	return 0;
} 

E. Polygon

题意:n*n网格中最左和最上方有n门大炮,大炮个发射1,1遇到边缘或1可以停下来,判断给出的数据能否达到。

题解:遍历n-1*n-1只要右边或下面有个1即可

代码

#include <iostream>
using namespace std;

char a[55][55];

int main() {
	int t, n;
	cin >> t;
	while(t--) {
		bool True = true;
		cin >> n;
		for(int i = 1; i <= n; i++) {
			for(int j = 1; j <= n; j++) {
				cin >> a[i][j];
			}
		}
		for(int i = 1; i <= n-1; i++) {
			for(int j = 1; j <= n-1; j++) {
				if(a[i][j] == '1') {
					if(a[i+1][j] != '1' && a[i][j+1] != '1')
					True = false;
			}
		}
	}
		if(True == true) 
		cout << "YES" << endl;
		else
		cout << "NO" << endl;
	}
	return 0;
}

F. Spy-string

题意:给出n个字符串,找出一个字符串s,使得s与每个字符串最多差一个字母。

题解:暴力,数据比较小,创建一个新的字符串一个个比对过去

代码

#include <iostream>
#include <cstring>
using namespace std;

char a[15][15];

int main() {
	int n, m ,t;
	cin >> t;
	while(t--) {
		cin >> n >> m;
		for(int i = 1; i <= n; i++) {
			for(int j = 1; j <= m; j++)
			cin >> a[i][j];
		}
		string ss = "";
		for(int i = 1; i <= m; i++) {
			int ans = 1;
			string s = a[1];
			for(char j = 'a'; j <= 'z'; j++) {
				s[i] = j;
				for(int k = 1; k <= n; k++) {
					int sum = 0;
					for(int q = 1; q <= m; q++) 
						if(s[q] != a[k][q])
						sum++;
						if(sum >= 2)
						ans = 0;
				}
					if(ans) 
					ss = s;
			}
		}
		if(ss == "")
			cout << "-1" << endl;
			else
			cout << ss << endl;
	}
}

G. A/B Matrix

题意:构建一个n*m的矩阵,使每行有a个1,b个1.

题解:矩阵中必须有=na=mb个1,否则不能满足题意。考虑每一行,每一行我们都要输出a个1,以及这一行剩下的0,让输出的1连续,下一行首个1的列位置接在上一行最后一个1的那一列之后。

代码:

#include <iostream>
#include <cstring>
using namespace std;

int a[55][55];
int b[55];

int main() {
	int n, m, A, B, t;
	cin >> t;
	while(t--) {
		memset(a,0,sizeof(b));
		memset(a,0,sizeof(b));
		int sum = 1;
		cin >> n >> m >> A >> B;
		if(n*A != m*B) {
			cout << "NO" << endl;
			continue;
		}
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				if(j < A) {
					a[i][(j+sum)%m] = 1;
				} else {
					a[i][(j+sum)%m] = 0;
				}
			}
		sum = (sum+A)%m;
		}
		cout << "YES" << endl;
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				cout << a[i][j];
			}
			cout << endl;
		}
	}
	return 0;
} 

H. Binary Median

最后

以上就是孤独香水为你收集整理的Codeforces Round #644 (Div. 3)比赛链接 :Codeforces Round #644 (Div. 3)的全部内容,希望文章能够帮你解决Codeforces Round #644 (Div. 3)比赛链接 :Codeforces Round #644 (Div. 3)所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(66)

评论列表共有 0 条评论

立即
投稿
返回
顶部