Codeforces Round #644 (Div. 3)
Posted wstong
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #644 (Div. 3)相关的知识,希望对你有一定的参考价值。
目录
A - Minimal Square
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e4+5;
int main() {
int t; cin >> t;
while (t--) {
int a, b; cin >> a >> b;
if (a > b) swap(a,b);
a <<= 1;
int ans = max(a,b)*max(a,b);
cout << ans << endl;
}
return 0;
}
B - Honest Coach
#include <bits/stdc++.h>
using namespace std;
const int maxn = 55;
int a[maxn];
int main() {
int t; cin >> t;
while (t--) {
int n; cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
sort(a+1,a+1+n);
int ans = 1e9;
for (int i = 2; i <= n; ++i) {
ans = min(ans,a[i]-a[i-1]);
}
cout << ans << endl;
}
return 0;
}
C - Similar Pairs
#include <bits/stdc++.h>
using namespace std;
const int maxn = 55;
int a[maxn];
int main() {
int t; cin >> t;
while (t--) {
int n; cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
int x = 0, y = 0;
for (int i = 1; i <= n; ++i) {
if (a[i] & 1) x++;
else y++;
}
if (x % 2 == 0 && y % 2 == 0) cout << "YES" << endl;
else {
sort(a+1,a+1+n);
bool flag = false;
for (int i = 2; i <= n; ++i) {
if (a[i] - a[i-1] == 1) {
flag = true;
break;
}
}
if (flag) cout << "YES" << endl;
else cout << "NO" << endl;
}
}
return 0;
}
D - Buying Shovels
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int t; cin >> t;
while (t--) {
int n, k; cin >> n >> k;
if (k >= n) cout << 1 << endl;
else {
int x = sqrt(n);
int ans = n;
for (int i = 2; i <= x; ++i) {
if (n % i == 0) {
if (k >= i) ans = min(ans,n/i);
if (k >= n/i) ans = min(ans,i);
}
}
cout << ans << endl;
}
}
return 0;
}
E - Polygon
#include <bits/stdc++.h>
using namespace std;
const int maxn = 55;
int a[maxn][maxn];
int main() {
int t; cin >> t;
while (t--) {
int n; cin >> n;
for (int i = 1; i <= n; ++i) {
string s; cin >> s;
for (int j = 1; j <= n; ++j) {
a[i][j] = s[j-1]-‘0‘;
}
}
bool flag = true;
for (int i = n-1; i >= 1; --i) {
for (int j = 1; j <= i; ++j) {
if (a[i][j] == 1 && a[i+1][j] == 0 && a[i][j+1] == 0) {
flag = false;
break;
}
}
for (int j = 1; j <= i; ++j) {
if (a[j][i] == 1 && a[j][i+1] == 0 && a[j+1][i] == 0) {
flag = false;
break;
}
}
if (flag == false) break;
}
if (flag) cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}
F - Spy-string
#include <bits/stdc++.h>
using namespace std;
const int maxn = 15;
string s[maxn];
int n, m;
bool check(int x) {
int cnt = 0;
for (int i = 0; i < m; ++i) {
if (s[0][i] != s[x][i]) cnt++;
if (cnt > 1) return false;
}
return true;
}
int main() {
int t; cin >> t;
while (t--) {
cin >> n >> m;
for (int i = 1; i <= n; ++i) cin >> s[i];
for (int j = 0; j < m; ++j) {
s[0] = s[1];
for (char k = ‘a‘; k <= ‘z‘; ++k) {
s[0][j] = k;
bool flag = true;
for (int i = 2; i <= n; ++i) {
if (check(i) == false) {
flag = false;
break;
}
}
if (flag) {
cout << s[0] << endl;
s[0] = "";
break;
}
}
if (s[0] == "") break;
}
if (s[0] != "") cout << -1 << endl;
}
return 0;
}
G - A/B Matrix
#include <bits/stdc++.h>
using namespace std;
const int maxn = 55;
int mat[maxn][maxn];
int main() {
int t; cin >> t;
while (t--) {
int n, m, a, b; cin >> n >> m >> a >> b;
if (n*a != m*b) cout << "NO" << endl;
else {
memset(mat,0,sizeof(mat));
cout << "YES" << endl;
int x = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < a; ++j) {
mat[i][x] = 1;
x++;
x %= m;
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cout << mat[i][j];
}
cout << endl;
}
}
}
return 0;
}
H - Binary Median
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll bin2dec(string s) {
ll res = 0;
int len = s.size();
for (int i = 0; i < len; ++i) {
res += (s[i]-‘0‘) * pow(2, len-i-1);
}
return res;
}
int main() {
int t; cin >> t;
while (t--) {
ll n, m; cin >> n >> m;
ll mid = (1ll << (m-1)); // 一开始的中位数
vector<ll> ve;
for (ll i = -100; i < 100; ++i) {
ve.push_back(mid+i);
}
for (int i = 1; i <= n; ++i) {
string s; cin >> s;
ll x = bin2dec(s);
if (x <= ve.front()) ve.erase(ve.begin());
else if (x >= ve.back()) ve.erase(ve.end()-1);
else ve.erase(lower_bound(ve.begin(),ve.end(),x));
}
ll x = ve[(ve.size()-1)/2];
for (ll i = m-1; i >= 0; --i) {
if ((1ll << i) & x) cout << 1;
else cout << 0;
}
cout << endl;
}
return 0;
}
以上是关于Codeforces Round #644 (Div. 3)的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #644 (Div. 3) A-F
Codeforces Round #644 (Div. 3) H. Binary Median
Codeforces Round #644(Div.3) 题解
Codeforces Round #644 (Div. 3) H. Binary Median