[学习笔记]2018-2-5

oi

POJ2965

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
#include <iostream>
#include <cstdio>
#include <bitset>
#include <vector>
char c;
bitset<6> status[6];
bitset<6> origin[6];
std::vector<pair<int, int> > res;
namespace {
inline void push(int x, int y) {
status[x][y] = ! status[x][y];
for (int i = 1; i <= 4; ++i) {
status[x][i] = !status[x][i];
status[i][y] = !status[i][y];
}
}
inline void init() {
cin.tie(0);
std::ios::sync_with_stdio(false);
for (register int i = 1; i <= 4; ++i)
for (register int j = 1; j <= 4; ++j) {
cin >> c;
origin[i][j] = (c == '+');
if(origin[i][j]) push(i, j);
}
}
inline void solve() {
init();
for (int i = 1; i <= 4; ++i)
for (int j = 1; j <= 4; ++j)
if(status[i][j]) res.push_back(make_pair(i, j));
cout << res.size() << endl;
for (int i = 0; i < res.size(); ++i)
cout << res[i].first << " " << res[i].second << endl;
}
}
int main() {
using namespace std;
solve();
return 0;
}


POJ3190
区间的贪心

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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* by kririae 2018/2/5
*/
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstdlib>
#include <algorithm>
using namespace std;
inline void read(int &x)
{
x = 0;
int f = 1;
char ch = getchar();
while(ch < '0' || ch > '9') {
if(ch == '-')f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
x *= f;
}
template<typename T>
inline T maxx(T a, T b) { return a > b ? a : b; };
template<typename T>
inline T minx(T a, T b) { return a > b ? a : b; };
struct cow {
int id, l, r, basic;
cow() {}
cow(int a, int b, int c): basic(a), l(b), r(c) {}
};
inline bool comp1(cow a, cow b) {
return a.l == b.l ? a.r < b.r : a.l < b.l;
}
inline bool comp2(cow a, cow b) {
return a.basic <= b.basic;
}

struct p {
int a, b;
p() {}
p(int x, int y): a(x), b(y) {}
bool operator < (const p &val) const {
return a > val.a;
}
};

const int maxn = 5e4 + 5;
int n, cnt = 0;
int ai, bi;
int res = 0;
cow init[maxn];
priority_queue<p> stall; // end_time, id

int main() {
read(n);
for (int i = 1; i <= n; ++i) {
read(ai); read(bi);
init[i] = cow(i, ai, bi);
}
sort(init + 1, init + 1 + n, comp1);
stall.push(p(init[1].r, 1));
init[1].id = 1;
++cnt;
for (int i = 2; i <= n; ++i) {
if(stall.size() >= 1) {
p f = stall.top();
if(f.a < init[i].l) {
stall.pop();
init[i].id = f.b;
f.a = init[i].r;
stall.push(f);
}
else {
++cnt;
stall.push(p(init[i].r, cnt));
init[i].id = cnt;
res = maxx(res, cnt);
}
}
}
cout << res << endl;
sort(init + 1, init + 1 + n, comp2);
for (int i = 1; i <= n; ++i) {
cout << init[i].id << endl;
}
return 0;
}