1637: Yet Satisfiability Again!

Time Limit: 5 Sec  Memory Limit: 128 MB

Description

Alice recently started to work for a hardware design company and as a part of her job, she needs to identify defects in fabricated ntegrated circuits. An approach for identifying these defects boils down to solving a satisfiability instance. She needs your help to write a program to do this task.

Input

The first line of input contains a single integer, not more than 5, indicating the number of test cases to follow. The first line of each test case contains two integers n and m where 1 ≤ n ≤ 20 indicates he number of variables and 1 ≤ m ≤ 100 indicates the number of clauses. Then, m lines follow corresponding to each clause. Each clause is a disjunction of literals in the form Xi or ~Xi for some 1 ≤ i ≤ n, where Xi indicates the negation of the literal Xi. The “or” operator is denoted by a ‘v’ character and is seperated from literals with a single pace.

Output

For each test case, display satisfiable on a single line if there is a satisfiable assignment; otherwise
display unsatisfiable.

Sample Input

2
3 3
X1 v X2
~X1
~X2 v X3
3 5
X1 v X2 v X3
X1 v ~X2
X2 v ~X3
X3 v ~X1
~X1 v ~X2 v ~X3

Sample Output

satisfiable
unsatisfiable

HINT

 

Source

解题:以为可以用位运算优化,结果,却发现,错了!好吧,还是上暴力的吧

 #include <bits/stdc++.h>
#define pii pair<int,int>
using namespace std;
const int maxn = ;
char str[maxn];
vector< pii >s[maxn];
int n,m;
void exp2num(int idx) {
bool flag = true;
for(int i = ,ret = ; str[i];) {
if(str[i] == '~') flag = false;
if(isdigit(str[i])) {
while(isdigit(str[i])) ret = ret* + (str[i++]-'');
s[idx].push_back(make_pair(ret-,flag));
ret = ;
flag = true;
} else i++;
}
}
bool check(int o){
for(int i = ; i < m; ++i){
bool flag = false;
for(int j = s[i].size()-; j >= ; --j){
if(s[i][j].second == ((o>>s[i][j].first)&)){
flag = true;
break;
}
}
if(!flag) return false;
}
return true;
}
int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%d %d",&n,&m);
getchar();
for(int i = ; i < m; ++i){
s[i].clear();
gets(str);
exp2num(i);
}
bool ok = false;
for(int i = ; i < (<<n) && !ok; ++i)
ok = check(i);
puts(ok?"satisfiable":"unsatisfiable");
}
return ;
}

CSUOJ 1637 Yet Satisfiability Again!的更多相关文章

  1. csuoj 1511: 残缺的棋盘

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1511 1511: 残缺的棋盘 时间限制: 1 Sec  内存限制: 128 MB 题目描述 输入 ...

  2. POJ 1637 Sightseeing tour (混合图欧拉路判定)

    Sightseeing tour Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6986   Accepted: 2901 ...

  3. bzoj 1637: [Usaco2007 Mar]Balanced Lineup

    1637: [Usaco2007 Mar]Balanced Lineup Time Limit: 5 Sec  Memory Limit: 64 MB Description Farmer John ...

  4. csuoj 1354: Distinct Subsequences

    这个题是计算不同子序列的和: spoj上的那个同名的题是计算不同子序列的个数: 其实都差不多: 计算不同子序列的个数使用dp的思想: 从头往后扫一遍 如果当前的元素在以前没有出现过,那么dp[i]=d ...

  5. BZOJ 1637: [Usaco2007 Mar]Balanced Lineup( sort + 前缀和 )

    将 0 变为 -1 , 则只需找区间和为 0 , 即前缀和相同的最长区间 , 记录一下每个前缀和出现的最早和最晚的位置 , 比较一下就 OK 了 --------------------------- ...

  6. POJ 1637 Sightseeing tour(最大流)

    POJ 1637 Sightseeing tour 题目链接 题意:给一些有向边一些无向边,问能否把无向边定向之后确定一个欧拉回路 思路:这题的模型很的巧妙,转一个http://blog.csdn.n ...

  7. 1637: [Usaco2007 Mar]Balanced Lineup

    1637: [Usaco2007 Mar]Balanced Lineup Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 393  Solved: 263[ ...

  8. [POJ 1637] Sightseeing tour(网络流)

    题意 (混合图的欧拉回路判定) 给你一个既存在有向边, 又存在无向边的图. 问是否存在欧拉回路. \(N ≤ 200, M ≤ 1000\) 题解 难点在于无向边. 考虑每个点的度数限制. 我们先对无 ...

  9. POJ 1637 - Sightseeing tour - [最大流解决混合图欧拉回路]

    嗯,这是我上一篇文章说的那本宝典的第二题,我只想说,真TM是本宝典……做的我又痛苦又激动……(我感觉ACM的日常尽在这张表情中了) 题目链接:http://poj.org/problem?id=163 ...

随机推荐

  1. IDEA无法启动:Failed to create JVM:error code -4

    发生该错误的原因是由于IDEA须要使用的连续内存空间没有得到满足,解决方式: 1.减小-Xmx和-XX:PermSize的值     切换到IDE_HOME\bin\文件夹下,找到<produc ...

  2. FZOJ--2214--Knapsack problem(背包)

    Problem 2214 Knapsack problem Accept: 5    Submit: 8 Time Limit: 3000 mSec    Memory Limit : 32768 K ...

  3. hdoj--1408--盐水的故事(技巧)

    盐水的故事 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  4. 7. 关于IntelliJ IDEA删除项目

    转自:https://www.cnblogs.com/zhangqian27/p/7698148.html 刚开始使用IDEA . 自己创建项目玩,结果发现IDEA无法删除,我也是醉了,Eclipse ...

  5. 在shell脚本中使用代理

    设置所有的代理走socks5 export ALL_PROXY="socks5://127.0.0.1:1080" 取消代理 unset ALL_PROXY  

  6. jqueryValidator自定义校验规则的一种方式(覆盖源码)

    1.自定义js文件:jqValid-extend.js 内容: function setDefaultValidate(){ $.extend(true, $.validator, { // 方法 m ...

  7. 使用goroutine+channel和java多线程+queue队列的方式开发各有什么优缺点?

    我感觉很多项目使用java或者c的多线程库+线程安全的queue数据结构基本上可以实现goroutine+channel开发能达到的需求,所以请问一下为什么说golang更适合并发服务端的开发呢?使用 ...

  8. 给 “rm” 命令添加个“垃圾桶”

    作者: 2daygeek 译者: LCTT amwps290 人类犯错误是因为我们不是一个可编程设备,所以,在使用 rm 命令时要额外注意,不要在任何时候使用 rm -rf *.当你使用 rm 命令时 ...

  9. d3的一些总结

    核心操作:https://blog.csdn.net/kriszhang/article/details/70174410 Update.Enter.Exit 简练详细说明:http://www.cn ...

  10. python学习---【__all__】

    python包中都会有一个__init__.py的模块,这个模块是区分该父文件是一个python包,或是一个文件目录.这个__init__.py可以是空,也可以添加内容,最常见的就是其中的__all_ ...