打的好烂的一场啊,,, B竟然还FST了,,, 被C卡的不要不要的 ,,
A. If at first you don’t succeed…
忘记题意了,,, 特判一下就好了,,
#include <bits/stdc++.h>
using namespace std;
#define LL long long
const int MAXN = (int)2e5+10;
const int INF = 0x3f3f3f3f;
int arr[MAXN];
bool vis[MAXN];
int main() {
ios::sync_with_stdio(false);
int a, b, c, n;
cin >> a >> b >> c >> n;
if(a-c<0 || b-c<0 || n-c<=0) {
cout << "-1\n";
return 0;
}
a-=c;
if(a+b>=n) {
cout << "-1\n";
return 0;
}
cout << n-a-b << endl;
return 0;
}
B. Getting an A
给n个小于等于五的数字,每次修改一个数字 变成5 问最小修改几次四舍五入平均值为5?
注意一下精度问题就行了
#include <bits/stdc++.h>
using namespace std;
#define LL long long
const int MAXN = (int)2e5+10;
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
int arr[MAXN];
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
double sum = 0;
for (int i = 0; i < n; ++i) {
cin >> arr[i];
sum += arr[i];
}
double x = sum/n;
if(x >= 4.5) {
cout << 0 << endl;
return 0;
}
sort(arr, arr+n);
int k = 0;
for (int i = 0; i < n; ++i) {
sum -= arr[i];
sum += 5;
if (sum/n >= 4.5) {
cout << ++k << endl;
return 0;
} else {
k++;
}
}
return 0;
}
C. Candies
裸的二分 注意二分的上届是LL ,,,
TLE9 T的爆炸mmp
#include <bits/stdc++.h>
using namespace std;
#define LL long long
const int MAXN = (int)2e5+10;
const int INF = 0x3f3f3f3f;
LL n;
bool check(LL x) {
LL ans = n;
LL sum = 0;
while(ans > 0) {
if(ans >= x) {
ans -= x;
sum += x;
}
else {
sum += ans;
ans = 0;
}
if(ans >= 10) {
LL zz = ans/10;
ans -= zz;
}
}
if(n <= sum*2) return true;
return false;
}
int main() {
ios::sync_with_stdio(false);
cin >> n;
LL l = 1, r = 2e10;
LL mid;
LL ans = -1;
while(r >= l) {
mid = l+(r-l)/2;
if(check(mid))
ans = mid,r = mid-1;
else
l = mid+1;
}
cout << ans << endl;
return 0;
}
D.Bishwock
大力从左向右贪心竟然过了,,,,
#include <bits/stdc++.h>
using namespace std;
#define LL long long
const int MAXN = (int)2e5+10;
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
string s[2];
int dx[] = {0, 0, 1, 1};
int dy[] = {0, 1, 0, 1};
int main() {
cin >> s[0] >> s[1];
int ans = 0;
char cc = 'X', ch = '0';
for (int i = 0; i < (int)s[0].size()-1; ++i) {
int k = 0;
for (int j = 0; j < 4; ++j) {
if(s[dx[j]][dy[j]+i] == ch)
k++;
}
if(k == 3) {
for (int j = 0; j < 4; ++j) {
s[dx[j]][dy[j]+i] = cc;
}
ans++;
}
else if(k == 4) {
for (int j = 0; j < 3; ++j) {
//if(j != 1)
s[dx[j]][dy[j]+i] = cc;
}
ans++;
}
}
cout << ans << endl;
return 0;
}