POJ 3683 Priest John's Busiest Day(2-sat),poj3683

來源:互聯網
上載者:User

POJ 3683 Priest John's Busiest Day(2-sat),poj3683
POJ 3683 Priest John's Busiest Day

題目連結

題意:給定幾個時間,si, ti, di每個時間要選[si, si + di]或[ti - di, ti],問能否選出所有時間不相交的方案

思路:顯然的2-sat,注意判斷相交的方法

代碼:

#include <cstdio>#include <cstring>#include <vector>using namespace std;const int N = 1005;int n;vector<int> g[2 * N];bool mark[2 * N];void init() {memset(mark, false, sizeof(mark));for (int i = 0; i < 2 * n; i++) g[i].clear();}void add_edge(int u, int x, int v, int y) {g[(2 * u + x)^1].push_back(2 * v + y);g[(2 * v + y)^1].push_back(2 * u + x);}int s[N], e[N], d[N];int S[2 * N], sn;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 judge(int s1, int e1, int s2, int e2) {if (s1 >= s2 && s1 < e2) return true;if (s2 >= s1 && s2 < e1) return true;return false;}bool solve() {init();for (int i = 0; i < n; i++) {for (int j = 0; j < i; j++) {for (int x = 0; x < 2; x++) {for (int y = 0; y < 2; y++) {int s1, e1, s2, e2;if (x == 0) {s1 = s[i];e1 = s[i] + d[i];} else {s1 = e[i] - d[i];e1 = e[i];}if (y == 0) {s2 = s[j];e2 = s[j] + d[j];} else {s2 = e[j] - d[j];e2 = e[j];}if (s1 > e1 || s2 > e2) return false;if (judge(s1, e1, s2, e2))add_edge(i, !x, j, !y);}}}}for (int i = 0; i < n * 2; i += 2) {if (!mark[i] && !mark[i + 1]) {sn = 0;if (!dfs(i + 1)) {for (int j = 0; j < sn; j++) mark[S[j]] = false;sn = 0;if (!dfs(i)) return false;}}}return true;}int main() {while (~scanf("%d", &n)) {int h1, m1, h2, m2;for (int i = 0; i < n; i++) {scanf("%d:%d%d:%d%d", &h1, &m1, &h2, &m2, &d[i]);s[i] = h1 * 60 + m1; e[i] = h2 * 60 + m2;}if (!solve()) printf("NO\n");else {printf("YES\n");for (int i = 0; i < n; i++) {int st, et;if (mark[i * 2]) {st = s[i];et = s[i] + d[i];} else {st = e[i] - d[i];et = e[i];}printf("%02d:%02d %02d:%02d\n", st / 60, st % 60, et / 60, et % 60);}}}return 0;}



饑餓鯊(OCZ)Vertex4 128G 25英寸 SATA-3固態硬碟(VTX4-25SAT3-128G)可以裝Windows7

沒問題,WIN7也就是不到20G
 
饑餓鯊(OCZ)Agility3 120G 25英寸 SATA-3固態硬碟(AGT3-25SAT3-120G) 這個硬碟可以裝台式機?

能
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.