传送门

题意:

给出一个圆,圆上有\(n\)个点,依次为\(0,1,\cdots,n-1\)。

现在要连接\(m\)对点,每次连接时可以直接从里面连,也可以从外面连。

最后问,连完这\(m\)对点后,是否有线相交。

思路:

每次连接时可以直接从里面连,也可以从外面连,那么可以考虑这个问题是一个\(2-sat\)模型。\(2-sat\)模型一般可以表示为:\((x_1\bigvee x_2)\bigwedge (x_3\bigvee x_4)\bigwedge \cdots\)。大概就是这样,每个括号里面有两个变量。

那么我们现在将矛盾找出来,这个在纸上画一下就比较好找了。

最后的二元关系是:两个变量\(x_i,x_j\)只能选一个,也就是说一个往里面连,另一个往外面连。

所以我们连边\(x_i'\rightarrow x_j,x_j'\rightarrow x_i,x_i\rightarrow x_j',x_j\rightarrow x_i'\)即可,表示两者选择一个。

感觉这个题数据好水,后面做一个类似的题的时候代码被hack了。

/*
* Author: heyuhhh
* Created Time: 2019/11/29 15:38:08
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <cstring>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
#define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
void err() { std::cout << '\n'; }
template<typename T, typename...Args>
void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
#else
#define dbg(...)
#endif
void pt() {std::cout << '\n'; }
template<typename T, typename...Args>
void pt(T a, Args...args) {std::cout << a << ' '; pt(args...); }
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 2005; int n, m;
int a[N], b[N]; vector<int> G[N], rG[N], vs;
int used[N], bel[N]; void adde(int from, int to) {
G[from].push_back(to);
rG[to].push_back(from);
} void dfs(int v) {
used[v] = true;
for(int i = 0; i < sz(G[v]); i++) {
int u = G[v][i];
if(!used[u])
dfs(u);
}
vs.push_back(v);
} void rdfs(int v, int k) {
used[v] = true;
bel[v] = k;
for(int i = 0; i < sz(G[v]); i++) {
int u = G[v][i];
if(!used[u])
rdfs(u, k);
}
} int scc() {
memset(used, 0, sizeof(used));
vs.clear();
for(int v = 1; v <= 2 * m; ++v)
if(!used[v]) dfs(v);
memset(used, 0, sizeof(used));
int k = 0;
for(int i = (int) vs.size() - 1; i >= 0; --i)
if(!used[vs[i]]) rdfs(vs[i], k++);
return k;
} bool cross(int x, int y) {
if(a[x] < a[y] && b[x] > a[y] && b[x] < b[y]) return true;
if(a[x] < b[y] && a[x] > a[y] && b[x] > b[y]) return true;
return false;
} void run(){
for(int i = 1; i <= m; i++) {
cin >> a[i] >> b[i];
if(a[i] > b[i]) swap(a[i], b[i]);
}
for(int i = 1; i <= m; i++) {
for(int j = i + 1; j <= m; j++) {
if(cross(i, j)) {
adde(2 * i - 1, 2 * j);
adde(2 * i, 2 * j - 1);
adde(2 * j - 1, 2 * i);
adde(2 * j, 2 * i - 1);
}
}
}
scc();
for(int i = 1; i <= m; i++) {
if(bel[2 * i] == bel[2 * i - 1]) {
cout << "the evil panda is lying again" << '\n';
return;
}
}
cout << "panda is telling the truth..." << '\n';
} int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(20);
while(cin >> n >> m) run();
return 0;
}

【poj3207】Ikki's Story IV - Panda's Trick(2-sat)的更多相关文章

  1. 【POJ3207】Ikki's Story IV - Panda's Trick

    POJ 3207 Ikki's Story IV - Panda's Trick liympanda, one of Ikki's friend, likes playing games with I ...

  2. POJ 3207 Ikki's Story IV - Panda's Trick(2-sat问题)

    POJ 3207 Ikki's Story IV - Panda's Trick(2-sat问题) Description liympanda, one of Ikki's friend, likes ...

  3. POJ 3207 Ikki's Story IV - Panda's Trick (2-sat)

    Ikki's Story IV - Panda's Trick Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 6691   ...

  4. poj 3207 Ikki's Story IV - Panda's Trick (2-SAT)

    http://poj.org/problem?id=3207 Ikki's Story IV - Panda's Trick Time Limit: 1000MS   Memory Limit: 13 ...

  5. POJ 3207 Ikki's Story IV - Panda's Trick

    Ikki's Story IV - Panda's Trick Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 7296   ...

  6. poj--3207--Ikki's Story IV - Panda's Trick(2-sat)

    Ikki's Story IV - Panda's Trick Time Limit: 1000MS   Memory Limit: 131072KB   64bit IO Format: %I64d ...

  7. 【Luogu4921】情侣?给我烧了!(组合计数)

    [Luogu4921]情侣?给我烧了!(组合计数) 题面 洛谷 题解 很有意思的一道题目. 直接容斥?怎么样都要一个平方复杂度了. 既然是恰好\(k\)对,那么我们直接来做: 首先枚举\(k\)对人出 ...

  8. 【BZOJ4991】我也不知道题目名字是什么(线段树)

    [BZOJ4991]我也不知道题目名字是什么(线段树) 题面 BZOJ 题解 对于线段树维护的区间维护以下东西: 区间左(右)端开始(结束)的最长(短)子串的长度 左端右端的值,以及当前区间内的答案 ...

  9. 【python】Leetcode每日一题-直方图的水量(接雨水)

    [python]Leetcode每日一题-直方图的水量(接雨水) [题目描述] 给定一个直方图(也称柱状图),假设有人从上面源源不断地倒水,最后直方图能存多少水量?直方图的宽度为 1. 上面是由数组 ...

随机推荐

  1. How To Restore Rman Backups On A Different Node When The Directory Structures Are Different (Doc ID 419137.1)

    How To Restore Rman Backups On A Different Node When The Directory Structures Are Different (Doc ID ...

  2. iozone - a filesystem benchmark tool 主要是用来测试文件系统 性能

    简介:    磁盘设备之上是文件系统,测试磁盘的工具往往就是调用块设备驱动的接口进行读写测试.而文件系统的测试软件就是针对文件系统层提供的功能进行测试,包括文件的打开关闭速度以及顺序读写随机位置读写的 ...

  3. gcc 4.9 编译安装 in Ubuntu 18.04(主要用于在无root权限下,进行更新系统 gcc 版本)

    gcc 4.9 编译安装教程,因为项目编译过程中,需要采用特定的gcc版本来进行编译,所以进行简要记录,进行备忘: 下载:curl -O -L https://mirrors.tuna.tsinghu ...

  4. platform平台device和driver如何匹配【转】

    转自:https://www.cnblogs.com/sky-heaven/p/6869591.html 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接 ...

  5. acwing 835. Trie字符串统计

    地址  https://www.acwing.com/problem/content/description/837/ 维护一个字符串集合,支持两种操作: “I x”向集合中插入一个字符串x: “Q ...

  6. C++(OI竞赛入门)学习指南一

    #include<cstdio>   头文件#include包含  <头文件名称> #include<iostream>     需要头文件里面的功能    cst ...

  7. ImportError: unable to find Qt5Core.dll on PATH

    一.实验环境 1.Windows7x32_SP1 2.python3.7.4 3.pyinstaller3.5 二.问题描述 1.一直都是在Windows10x64上使用pyinstaller打包ex ...

  8. ES5提取公共变量

    在ES5中,请求地址前缀等需要作为公共变量提出. 则需在common.js写上 Object.defineProperty(window,'base',{ value:"http://xx. ...

  9. 《细说PHP》第四版 样章 第23章 自定义PHP接口规范 11

    23.6  使用第三方接口服务实例 接供服务的第三方接口平台有很多,现在的项目中也经常用到一些第三方接口,如支付宝.微信.短信.邮件接口等,我们需要借助第三方的能力来实现产品的某些功能.如果自己已经掌 ...

  10. VSCode 开发插件 推荐

    VSCode 必装的 10 个高效开发插件  本文介绍了目前前端开发最受欢迎的开发工具 VSCode 必装的 10 个开发插件,用于大大提高软件开发的效率. VSCode 的基本使用可以参考我的原创视 ...