AtCoder Beginner Contest 133
https://atcoder.jp/contests/abc133
A - T or T
#include <bits/stdc++.h>
using namespace std;
int main (){
int a, b, n;
cin >> n >> a >> b;
cout << min (a * n, b);
}#include <bits/stdc++.h>
using namespace std;
int main (){
int a, b, n;
cin >> n >> a >> b;
cout << min (a * n, b);
}
B - Good Distance
#include <bits/stdc++.h>
using namespace std;
const int N = 15;
int a[N][N], n, m, ans;
int main (){
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
}
}
for (int i = 1; i < n; i++) {
for (int ii = i + 1; ii <= n; ii++) {
int sum = 0;
for (int j = 1; j <= m; j++) {
sum += (a[ii][j] - a[i][j]) * (a[ii][j] - a[i][j]);
}
if ((int)sqrt (sum) == sqrt(sum)) ans ++;
}
}
cout << ans;
}
C - Remainder Minimization 2019
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 15;
vector<int> v;
int ans = 2018 * 2018;
signed main (){
int l, r;
cin >> l >> r;
for (int i = l; i < r; i++) {
for (int j = i + 1; j <= r; j++) {
ans = min (ans, (i * j) % 2019);
if (!ans) break;
}
if (!ans) break;
}
cout << ans;
}
//找到离2019的倍数最近的几个
D - Rain Flows into Dams
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 5;
int a[N], b[N], n;
signed main (){
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = n - 1; i >= 0; i -= 2) b[0] +=a[i];
for (int i = n - 2; i >= 0; i -= 2) b[0] -=a[i];
for (int i = 1; i < n; i++) b[i] = 2 * a[i-1] - b[i-1];
for (int i = 0; i < n; i++) cout << b[i] << ' ';
}
//解方程
E - Virus Tree 2
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 5, M = N * 2, mod = 1000000007;
int n, k, dep[N], cnt[N]; //深度, 深度为i的时候有多少个
int h[N], e[M], ne[M], idx;
int ans = 1, val[N];
void add (int a, int b) {
e[idx] = b, ne[idx] = h[a], h[a] = idx++;
}
void dfs (int u, int fa) {
dep[u] = dep[fa] + 1;
for (int i = h[u]; ~i; i = ne[i]) {
int j = e[i];
if (j == fa) continue;
dfs (j, u);
}
}
void count (int u, int fa) {
if (dep[u] == 2) val[u] --;
if (dep[u] >= 3) val[u] -= 2;
int flag = false, sum = 0;
for (int i = h[u]; ~i; i = ne[i]) {
int j = e[i];
if (j == fa) continue;
if (!flag) {
flag = true;
sum = val[j];
}
else {
val[j] = sum - 1;
sum = val[j];
}
}
for (int i = h[u]; ~i; i = ne[i]) {
int j = e[i];
if (j == fa) continue;
count (j, u);
}
}
signed main () {
memset (h, -1, sizeof h);
cin >> n >> k;
for (int i = 1; i < n; i++) {
int a, b;
cin >> a >> b;
add (a, b), add (b, a);
}
dfs (1, 0);
for (int i = 1; i <= n; i++) val[i] = k;
count (1, 0);
for (int i = 1; i <= n; i++) {
ans = (ans * max (0ll, val[i])) % mod;
if (!ans) break;
}
cout << ans << endl;
}
//注意对0取max