Codeforces-Round-886-(Div
[[Dashboard - Codeforces Round 886 (Div. 4) - Codeforces)](比赛链接)
新年快乐! 做个简单的
A. To My Critics
#include <bits/stdc++.h>
using namespace std;
void solve() {
int a, b, c;
cin >> a >> b >> c;
if(a + b >= 10 || b + c >= 10 || a + c >= 10) {
cout << "YES\n";
}else{
cout << "NO\n";
}
}
int main() {
int t;
cin >> t;
while(t--) solve();
return 0;
}
B. Ten Words of Wisdom
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
int ans = 0, t = 0;
for(int i = 1; i <= n; i++) {
int a, b;
cin >> a >> b;
if(a <= 10 && b > ans) {
ans = b;
t = i;
}
}
cout << t << endl;
}
int main() {
int t;
cin >> t;
while(t--) solve();
return 0;
}
C. Word on the Paper
#include <bits/stdc++.h>
using namespace std;
void solve() {
string s, ans;
for(int i = 0; i < 8; i++) {
cin >> s;
for(auto ch : s) {
if(ch != '.') ans += ch;
}
}
cout << ans << endl;
}
int main() {
int t;
cin >> t;
while(t--) solve();
return 0;
}
D. Balanced Round
思路:排序,遍历记录最大值即可,见代码:
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, k;
cin >> n >> k;
vector<int> a(n);
for(int i = 0; i < n; i++) cin >> a[i];
int ans = 1, b = 1;
sort(a.begin(), a.end());
for(int i = 1; i < n; i++) {
if(a[i] - a[i - 1] <= k) {
b++;
ans = max(ans, b);
}else{
b = 1;
}
}
cout << n - ans << endl;
}
int main() {
int t;
cin >> t;
while(t--) solve();
return 0;
}
E. Cardboard for Pictures
思路:解一下二次函数, 注意开long double
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve() {
long double n, c, b = 0;
cin >> n >> c;
vector<long double> a(n);
for(int i = 0; i < n; i++) {
cin >> a[i];
c -= a[i] * a[i];
b += a[i];
}
b *= 4;
long double ta = 4 * n;
// cout << ta << ' ' << b << ' ' << c << endl;
long double ans = (sqrt(b * b + 4 * ta * c) - b) / (2 * ta);
cout << (ll)ans << endl;
}
int main() {
int t;
cin >> t;
while(t--) solve();
return 0;
}
F. We Were Both Children
思路:把出现过的数的小于n的倍数出现的次数用一个数组 cnt 记录下来, 输出max(cnt[i])即可。 先用map记录一下,去一下重,防止复杂度过大。 复杂度是n * ln(n) (shi调和级数
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> cnt(n + 1);
map<int, int> mp;
int x, ans = 0;
for(int i = 0; i < n; i++) cin >> x, mp[x]++;
for(auto [k, v] : mp) {
x = k;
int b = x;
while(x <= n) {
cnt[x] += v;
x += b;
ans = max(ans, cnt[x - b]);
}
}
cout << ans << endl;
}
int main() {
int t;
cin >> t;
while(t--) solve();
return 0;
}
G. The Morning Star
思路:组合数学,哈希记录一下即可
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
int n;
cin >> n;
ll ans = 0;
map<ll, ll> mp1, mp2, mpx, mpy;
for(int i = 0; i < n; i++) {
ll a, b;
cin >> a >> b;
ans += mp1[b - a] + mp2[a + b] + mpx[a] + mpy[b];
mp1[b - a] ++;
mp2[a + b] ++;
mpx[a] ++;
mpy[b] ++;
}
cout << ans * 2 << endl;
}
int main() {
int t;
cin >> t;
while(t--) solve();
return 0;
}
浙公网安备 33010602011771号