日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

UVa 1624 打结(Knots)

發(fā)布時間:2023/12/14 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UVa 1624 打结(Knots) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.


代碼:

#include<bits/stdc++.h> #define LL long long #define ms(s) memset(s, 0, sizeof(s)) #define REP(i, a, b) for(int i = (a); i < (b); i++) #define INF 0X7fffffff using namespace std; const int LMAX = 1e6 + 10; const int PMAX = 5e3 + 10;int _left[LMAX]; int _right[LMAX]; int level[LMAX]; int opos[LMAX]; bool vis[LMAX];void del(int i) {vis[i] = true;_left[_right[i]] = _left[i];_right[_left[i]] = _right[i]; }int main() {// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);ios::sync_with_stdio(false);cin.tie(0);int T;cin >> T;for(int i = 1; i <= T; i++) {ms(vis);ms(level);int l, p;cin >> l >> p;for(int j = 0; j < l; j++) {_left[j] = j - 1;_right[j] = j + 1;}_left[0] = l - 1;_right[l - 1] = 0;int _top, _bot;for(int j = 0; j < p; j++) {cin >> _top >> _bot;level[_top] = 1;level[_bot] = -1;opos[_top] = _bot;opos[_bot] = _top;}for(int j = 0; j < l; j++) {if(!level[j]) del(j);}int num = 2 * p;int k = 0;while(num) {bool ok = true;while(vis[k]) k++;for(int j = _right[k]; ok && j != k; j = _right[j]) {//passingint w1 = j;int w2 = _right[j];if(level[w1] == level[w2] && (_right[opos[w1]] == opos[w2] ||_right[opos[w2]] == opos[w1])) {ok = 0;num -= 4;del(w1); del(w2);del(opos[w1]);del(opos[w2]);} else {if(opos[w1] == w2) {ok = 0;num -= 2;del(w1); del(w2);}}}if(ok) break;}cout << "Case #" << i << ": ";cout << (num ? "NO" : "YES") << endl;}return 0; }

總結

以上是生活随笔為你收集整理的UVa 1624 打结(Knots)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。