A. Red or Not

模拟

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <bits/stdc++.h>
using namespace std;



int main(int argc, char const *argv[])
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int a;
string s;
cin >> a >> s;
if(a >= 3200) cout << s << endl;
else cout << "red" << endl;
return 0;
}

B. Resistors in Parallel

模拟

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <bits/stdc++.h>
using namespace std;

int main(int argc, char const *argv[])
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
double res = 0;
int n;
cin >> n;
for(int i = 0; i < n; i++)
{
double x;
cin >> x;
res += 1 / x;
}
printf("%.6f\n", 1 / res);
return 0;
}

C. Alchemist

模拟

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <bits/stdc++.h>
using namespace std;

int main(int argc, char const *argv[])
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n; cin >> n;
vector<int> a(n); for(int i = 0; i < n; i++) cin >> a[i];
sort(a.begin(), a.end());
double ans = a[0];
for(int i = 0; i < n - 1; i++)
ans = (ans + a[i + 1]) / 2;
printf("%.9f", ans);
return 0;
}

D. Ki

一开始打算直接复制树剖板(肯定能过$O((n + q)logn)$)
然后想想不用修改,直接dfs就行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 10, M = N << 2;
#define int long long
int h[N], e[M], ne[M], idx;
int n, m;
int w[N];
void add(int a, int b)
{
e[idx] = b, ne[idx] = h[a], h[a] = idx++;
}

void dfs(int u, int f)
{
for(int i = h[u]; ~i; i = ne[i])
{
int j = e[i];
if(j == f) continue;
w[j] += w[u];
dfs(j, u);
}
}

signed main(int argc, char const *argv[])
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> m;
memset(h, -1, sizeof h);
for(int i = 1; i < n; i++)
{
int x, y;
cin >> x >> y;
add(x, y);
add(y, x);
}
for(int i = 0; i < m; i++)
{
int x, y;
cin >> x >> y;
w[x] += y;
}
dfs(1, -1);
for(int i = 1; i <= n; i++) cout << w[i] << " \n"[i == n];
return 0;
}

E,F后面寄了,今天大失败