POJ 3905 Perfect Election(2-sat),poj2-sat
POJ 3905 Perfect Election
題目連結
思路:很裸的2-sat,就根據題意建邊即可
代碼:
#include <cstdio>#include <cstring>#include <cstdlib>#include <vector>#include <algorithm>using namespace std;const int MAXNODE = 2005;struct TwoSet {int n;vector<int> g[MAXNODE * 2];bool mark[MAXNODE * 2];int S[MAXNODE * 2], sn;void init(int tot) {n = tot * 2;for (int i = 0; i < n; i += 2) {g[i].clear();g[i^1].clear();}memset(mark, false, sizeof(mark));}void add_Edge(int u, int uval, int v, int vval) {u = u * 2 + uval;v = v * 2 + vval;g[u^1].push_back(v);g[v^1].push_back(u);}void delete_Edge(int u, int uval, int v, int vval) {u = u * 2 + uval;v = v * 2 + vval;g[u^1].pop_back();g[v^1].pop_back();}bool dfs(int u) {if (mark[u^1]) return false;if (mark[u]) return true;mark[u] = true;S[sn++] = u;for (int i = 0; i < g[u].size(); i++) {int v = g[u][i];if (!dfs(v)) return false;}return true;}bool solve() {for (int i = 0; i < n; i += 2) {if (!mark[i] && !mark[i + 1]) {sn = 0;if (!dfs(i)){for (int j = 0; j < sn; j++)mark[S[j]] = false;sn = 0;if (!dfs(i + 1)) return false;}}}return true;}} gao;int n, m;int main() {while (~scanf("%d%d", &n, &m)) {gao.init(n);int u, v;while (m--) {scanf("%d%d", &u, &v);if (u > 0 && v > 0) {u--; v--;gao.add_Edge(u, 1, v, 1);} else if (u > 0 && v < 0) {v = -v;u--; v--;gao.add_Edge(u, 1, v, 0);} else if (u < 0 && v > 0) {u = -u;u--; v--;gao.add_Edge(u, 0, v, 1);} else if (u < 0 && v < 0) {u = -u; v = -v;u--; v--;gao.add_Edge(u, 0, v, 0);}}printf("%d\n", gao.solve());}return 0;}
The Perfect Crime #2 (Best Buy Rhapsody Exclusive) (Album Demo) 歌詞
歌曲名:The Perfect Crime #2 (Best Buy Rhapsody Exclusive) (Album Demo)
歌手:The Decemberists
專輯:The Perfect Crime #2 (Album Demo)
The Perfect Crime #2
The Decemberists
Sing, Muse, of the passion of the pistol
Sing, Muse, of the warning by the whistle
A night so dark in the waning
A dawn obscured by a slate sky raining
Five and twenty burglars by the reservoir
A teenage lookout on the signal tower
The mogul's daughter in hog-tie
The mogul fingers the wrong guy, all right
It was a perfect, a perfect, a perfect, a perfect
A perfect, a perfect, a perfect, a perfect crime
It was a perfect, a perfect, a perfect, a perfect
A perfect, a perfect, a perfect, the perfect crime
It was a perfect crime
The bagman's quaking at the fingers
The hand-off, glance a little lingers
A well-dressed man in the cross-hairs
A shot rings out from somewhere upstairs
It was a perfect, a perfect, a perfect, a perfect
A perfect, a perfect, a perfect, a perfect crime
It was a perfect, a perfect, a perfect, a perfect
A perfect, a perfect, a perfect, the perfect crime
It was a perfect crime
It was like a ticker tape parade
When the plastique on the safe was blown away
And we all gazed from eye to eye
As we mouthed our silent goodbyes
The valley's sleeping like a bastard
It stinks of slumber and disaster
Two words are spoke on the tap wire
The agent's ploy finds a surefire backfire
It was a perfect, a perfect, a perfect, a perfect
A perfect, a perfect, a perfect, a perfect crime
It was a perfect, a......餘下全文>>
-(-3)-2+(-9)
3-2-9=-8