UVALive
来源:互联网 发布:淘宝美工零基础课程 编辑:程序博客网 时间:2024/06/16 08:08
题目链接:https://cn.vjudge.net/problem/UVALive-3211
【AC代码】
#include<cstdlib>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<vector>#include<map>#include<stack>#include<set>using namespace std;#define LL long longconst int maxn = 50000 + 5;struct TwoSAT{ int n; vector<int>G[maxn*2]; bool mark[maxn*2]; int s[maxn*2], c; bool dfs(int x) { if(mark[x^1])return false; if(mark[x])return true; mark[x] = true; s[c++] = x; for(int i = 0; i < G[x].size(); i++) { if(!dfs(G[x][i]))return false; } return true; } void init(int n) { this->n = n; for(int i = 0; i < n*2; i++) { G[i].clear(); } memset(mark, 0, sizeof(mark)); } void add_caluse(int x, int xval, int y, int yval) { x = x*2 + xval; y = y*2 + yval; G[x^1].push_back(y); G[y^1].push_back(x); } bool solve() { for(int i = 0; i < n*2; i+=2) { if(!mark[i]&&!mark[i+1]) { c = 0; if(!dfs(i)) { while(c > 0) { mark[s[--c]] = false; } if(!dfs(i+1)) { return false; } } } } return true; }};TwoSAT solver;int n,T[maxn][2];bool test(int diff){ solver.init(n); for(int i = 0; i < n; i++) { for(int a = 0; a < 2; a++) { for(int j = i+1; j < n; j++) { for(int b = 0; b < 2; b++) { if(abs(T[i][a]-T[j][b]) < diff) { solver.add_caluse(i, a^1, j, b^1); } } } } } return solver.solve();}int main(){ while(~scanf("%d", &n)) { if(n == 0)break; int L = 0, R = 0; for(int i = 0; i < n; i++)for(int a = 0; a < 2; a++) { scanf("%d",&T[i][a]); R = max(R, T[i][a]); } while(L < R) { int M = L + (R - L + 1)/2; if(test(M))L = M; else R = M - 1; } printf("%d\n",L); } return 0;}
阅读全文
1 0
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- HihoCoder
- 【HPUOJ 1415】小ho的0 【字符串】
- poj1458-LCS&回溯-Common Subsequence
- (转)比特币挖矿原理与过程
- 青年歌手大奖赛_评委会打分
- UVALive
- N皇后问题,java实现
- ios-URL和HTTP浅析
- 算法学习之旅,初级篇(14)--素数的个数
- HBase关键算法/流程
- 【HPUOJ 1416】Kick Ass Biu 【几何】
- 网易2018秋招笔试(彩色砖块)
- Show and Tell Lessons learned from the 2015 MSCOCO Image Captioning Challenge论文及tensorflow源码解读(2)
- JAVA学习笔记_使用Servlet3.0上传图片,无法使用part.getSubmittedFileName()方法解决