AtCoder Beginner Contest 203 (A~D,玄学二分场)
补题链接:Here
A - Chinchirorin
给出 \(a,b,c\) 三个正整数,现请打印各种情况的答案:
- \(a=b=c\) ,输出一个即可
- \(a = b\ and\ a != c\) 或者 \(a = c\ and\ a != b\) 或者 \(b = c\ and\ a != b\) 输出不一样的值即可
- 三个数均不同,输出 \(0\)
水题(RioTian是个连水题的都WA2发的FW....)
void solve() {
int a, b, c;
cin >> a >> b >> c;
if (a == b) cout << c << "\n";
else if (b == c) cout << a << "\n";
else if (a == c) cout << b << "\n";
else cout << "0\n";
}
B - AtCoder Condominium
包租婆有一个 \(n\) 层,每层 \(m\) 个房间的出租房,每个房间的房号:\(i0j(i\in[1,n],j\in[1,j])\)
求房号累计和
模拟题意即可
void solve() {
int n, k;
cin >> n >> k;
int sum = 0;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= k; ++j)
sum += (i * 100 + j);
cout << sum ;
}
C - Friends and Travel costs
太郎决定去旅行,但他只有 \(k\) 元钱,每走过一个村庄要给 \(1\) 块钱,但太郎有 \(k\) 个朋友,如果太郎经过他朋友居住的村子的话会得到 \(B_i\) 元钱作为旅费的补充
请问太郎最远能到达多远的村子(输出村子号),
注意太郎从 \(0\) 号村子出发
模拟,如果 \(k > a_i\) 则累加 \(b_i\)
写法上用 STL 优化
using ll = long long;
void solve() {
ll n, k; cin >> n >> k;
vector<pair<ll, ll>>v(n);
for (ll i = 0; i < n; ++i)
cin >> v[i].first >> v[i].second;
sort(v.begin(), v.end());
for (auto x : v) {
if (x.first > k)break;
k += x.second;
}
cout << k;
}
D - Pond
【题意待补充】
玄学二分+玄学前缀和
const int N = 1000;
int A[800][800];
int S[801][801];
void solve() {
int N, K;
cin >> N >> K;
for (int i = 0; i < N; i++)for (int j = 0; j < N; j++)cin >> A[i][j];
int L = 0, R = 1e9 + 1;
while (R - L > 1) {
int mid = (L + R) / 2;
for (int i = 0; i < N; i++)for (int j = 0; j < N; j++)S[i + 1][j + 1] = mid <= A[i][j];
for (int i = 1; i <= N; i++)for (int j = 1; j <= N; j++) {
S[i][j] += S[i - 1][j] + S[i][j - 1] - S[i - 1][j - 1];
}
bool fn = false;
for (int i = K; i <= N; i++)for (int j = K; j <= N; j++) {
if (S[i][j] - S[i - K][j] - S[i][j - K] + S[i - K][j - K] <= K * K / 2)fn = true;
}
if (fn)R = mid;
else L = mid;
}
cout << L << endl;
}
E,F 由于蓝桥杯暂不填坑