'commit'
This commit is contained in:
36
TangDou/AcWing/Test/796.cpp
Normal file
36
TangDou/AcWing/Test/796.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 1010;
|
||||
int a[N][N];
|
||||
int s[N][N];
|
||||
|
||||
int main() {
|
||||
int n, m, q;
|
||||
cin >> n >> m >> q;
|
||||
for (int i = 1; i <= n; i++)
|
||||
for (int j = 1; j <= m; j++) {
|
||||
cin >> a[i][j];
|
||||
s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j];
|
||||
}
|
||||
|
||||
while (q--) {
|
||||
int x1, y1, x2, y2;
|
||||
cin >> x1 >> y1 >> x2 >> y2;
|
||||
printf("%d\n", s[x2][y2] - s[x1 - 1][y2] - s[x2][y1 - 1] + s[x1 - 1][y1 - 1]);
|
||||
}
|
||||
return 0;
|
||||
/*
|
||||
输入样例:
|
||||
3 4 3
|
||||
1 7 2 4
|
||||
3 6 2 8
|
||||
2 1 2 3
|
||||
1 1 2 2
|
||||
2 1 3 4
|
||||
1 3 3 4
|
||||
输出样例:
|
||||
17
|
||||
27
|
||||
21
|
||||
*/
|
||||
}
|
||||
85
TangDou/AcWing/Test/TD.cpp
Normal file
85
TangDou/AcWing/Test/TD.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 100010, M = 200010;
|
||||
int depth[N], f[N][25];
|
||||
int n, m;
|
||||
int d[N];
|
||||
int ans;
|
||||
const int T = 17;
|
||||
|
||||
int e[M], h[N], idx, ne[M];
|
||||
void add(int a, int b) {
|
||||
e[idx] = b, ne[idx] = h[a], h[a] = idx++;
|
||||
}
|
||||
int start = 1;
|
||||
|
||||
void bfs() {
|
||||
queue<int> q;
|
||||
q.push(start);
|
||||
depth[start] = 1;
|
||||
while (q.size()) {
|
||||
int u = q.front();
|
||||
q.pop();
|
||||
for (int i = h[u]; ~i; i = ne[i]) {
|
||||
int v = e[i];
|
||||
if (!depth[v]) {
|
||||
depth[v] = depth[u] + 1;
|
||||
q.push(v);
|
||||
f[v][0] = u;
|
||||
for (int k = 1; k <= T; k++) f[v][k] = f[f[v][k - 1]][k - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int lca(int a, int b) {
|
||||
if (depth[a] < depth[b]) swap(a, b);
|
||||
for (int i = T; i >= 0; i--)
|
||||
if (depth[f[a][i]] >= depth[b]) a = f[a][i];
|
||||
if (a == b) return a;
|
||||
for (int i = T; i >= 0; i--)
|
||||
if (f[a][i] != f[b][i])
|
||||
a = f[a][i], b = f[b][i];
|
||||
return f[a][0];
|
||||
}
|
||||
|
||||
void dfs(int u, int fa) {
|
||||
for (int i = h[u]; ~i; i = ne[i]) {
|
||||
int v = e[i];
|
||||
if (v == fa) continue;
|
||||
dfs(v, u);
|
||||
d[u] += d[v];
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int a, b;
|
||||
scanf("%d %d", &n, &m);
|
||||
memset(h, -1, sizeof h);
|
||||
for (int i = 1; i < n; i++) {
|
||||
scanf("%d %d", &a, &b);
|
||||
add(a, b), add(b, a);
|
||||
}
|
||||
|
||||
bfs();
|
||||
|
||||
for (int i = 0; i < m; i++) {
|
||||
scanf("%d %d", &a, &b);
|
||||
|
||||
d[a]++, d[b]++;
|
||||
int p = lca(a, b);
|
||||
|
||||
d[p] -= 2;
|
||||
}
|
||||
|
||||
dfs(start, 0);
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
if (i == start) continue;
|
||||
if (d[i] == 0) ans += m;
|
||||
if (d[i] == 1) ans += 1;
|
||||
}
|
||||
|
||||
printf("%d\n", ans);
|
||||
return 0;
|
||||
}
|
||||
5
TangDou/AcWing/Test/TD.in
Normal file
5
TangDou/AcWing/Test/TD.in
Normal file
@@ -0,0 +1,5 @@
|
||||
4 1
|
||||
1 2
|
||||
3 2
|
||||
1 4
|
||||
3 4
|
||||
36
TangDou/AcWing/Test/Test.cpp
Normal file
36
TangDou/AcWing/Test/Test.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
const int N = 100010;
|
||||
int b[N], in[N];
|
||||
|
||||
int main() {
|
||||
int n, m;
|
||||
cin >> n >> m;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
int x, y;
|
||||
cin >> x >> y;
|
||||
in[y]++;
|
||||
b[x] = y;
|
||||
}
|
||||
int head = 0;
|
||||
for (int i = 1; i <= n; i++)
|
||||
if (in[i] == 0) {
|
||||
head = i;
|
||||
break;
|
||||
}
|
||||
for (int i = 1; i <= m; i++) {
|
||||
int x, y;
|
||||
cin >> x >> y;
|
||||
int t = b[x];
|
||||
b[x] = y;
|
||||
b[y] = t;
|
||||
}
|
||||
cout << head << endl;
|
||||
int x = b[head];
|
||||
while(x){
|
||||
cout << x << endl;
|
||||
x = b[x];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
5
TangDou/AcWing/Test/Test.in
Normal file
5
TangDou/AcWing/Test/Test.in
Normal file
@@ -0,0 +1,5 @@
|
||||
4 4
|
||||
B A A A
|
||||
A B A B
|
||||
B A B B
|
||||
A B A A
|
||||
Reference in New Issue
Block a user