20161111练习总结

T1

此题同codeforces460D
注意各种边界+判断…

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
47
48
49
50
51
52
53
54
55
56
#include <bits/stdc++.h>
using namespace std;
int main() {
long long l, r;
int k;
while (cin >> l >> r >> k) {
if (k >= 4) {
if (l % 2 && r - l + 1 >= 5) {
cout << 0 << "\n" << 4 << "\n" << l + 1 << " " << l + 2 << " " << l + 3 << " " << l + 4 << "\n";
continue;
}
else if (l % 2 == 0 && r - l + 1 >= 4) {
cout << "0\n4\n" << l << " " << l + 1 << " " << l + 2 << " " << l + 3 << "\n";
continue;
}
k = 3;
}
if (k == 3) {
long long c = 3LL, b = 2LL, a = 1LL;
int flag = 0;
while (1) {
if (c <= r && a >= l) {
flag = 1;
break;
}
if (c > r) break;
a = a << 1 | 1;
b = b << 1 | 1;
c = c << 1;
}
if (flag) {
cout << "0\n3\n" << a << " " << b << " " << c << "\n";
continue;
}
k = 2;
}
if (k == 2) {
int flag = 0;
for (long long i = l; i <= l + 1; i++) {
if (i % 2LL == 0 && i + 1LL <= r) {
flag = 1;
cout << "1\n2\n" << i << " " << i + 1LL << "\n";
}
}
if (!flag) {
if ((l ^ r) < l) cout << (l ^ r) << "\n" << 2 << "\n" << l << " " << r << "\n";
else cout << l << "\n1\n" << l << "\n";
}
}
if (k == 1) {
cout << l << "\n" << 1 << "\n" << l << "\n";;
continue;
}
}
return 0;
}

T2

统计每条边对答案的贡献,直接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
47
48
49
50
51
52
53
54
55
56
57
#include <bits/stdc++.h>
using namespace std;
struct Node {
int v, w;
Node(int v, int w) : v(v), w(w) {}
};
const int MAXN = 600010;
const int mod = 100000007;
vector<Node> edge[MAXN];
inline void addEdge(int u, int v, int w) {
edge[u].push_back(Node(v, w));
edge[v].push_back(Node(u, w));
}
char ch;
bool iosig;
template<class T>
inline void read(T &x) {
iosig = 0, x = 0;
do {
ch = getchar();
if (ch == '-') iosig = 1;
} while (!isdigit(ch));
while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ '0'), ch = getchar();
}
int size[MAXN], vis[MAXN], dep[MAXN];
typedef long long ll;
long long ans;
void dfs(int u) {
size[u] = 1, vis[u] = true;
for (int i = 0; i < edge[u].size(); i++) {
Node *x = &edge[u][i];
if (!vis[x->v]) {
dep[x->v] = dep[u] + 1;
dfs(x->v);
size[u] += size[x->v];
}
}
}
int n;
int main() {
read(n);
for (int i = 1, u, v, w; i < n; i++) {
read(u), read(v), read(w);
addEdge(u, v, w);
}
dep[1] = 1;
dfs(1);
for (int u = 1; u <= n; u++) {
for (int i = 0; i < edge[u].size(); i++) {
if (dep[u] + 1 == dep[edge[u][i].v])
ans += (ll)size[edge[u][i].v] * (n - size[edge[u][i].v]) % mod * edge[u][i].w % mod;
ans %= mod;
}
}
cout << 2 * ans % mod;
return 0;
}

T3

此题不是应该和T1放反了吗?
直接暴力排序…

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
#include <bits/stdc++.h>
using namespace std;
struct Node {
int x1, y1, x2, y2, x3, x4, y3, y4;
} a[3000];
int main() {
int t;
cin >> t;
while (t--) {
int i, j, n, w;
bool flag = 0;
cin >> n >> w;
for (i = 1; i <= n; ++i)
cin >> a[i].x1 >> a[i].y1 >> a[i].x2 >> a[i].y2;
for (i = 1; i <= n; ++i)
cin >> a[i].x3 >> a[i].y3 >> a[i].x4 >> a[i].y4;
for (i = 1; i < n; ++i) {
for (j = i + 1; j <= n; ++j) {
if ((long long)(a[i].x1 - a[j].x1) * (a[i].x3 - a[j].x3) < 0) {
if (a[i].y2 - a[i].y1 + a[j].y2 - a[j].y1 > w) {
flag = true;
break;
}
}
}
if (flag) break;
}
if (flag) cout << "No\n";
else cout << "Yes\n";
}
return 0;
}

Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×