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. Cms WebSite 编译非常慢

    第一次编译非常慢 如果遇到错误,中途中断的话. 下一次编译的时候,上一次已经编译过的文件,会非常快的略过.很快就会到上一次遇到错误的地方,继续往下进行编译.

  2. 英语音乐---三、Cry on my shoulder

    英语音乐---三.Cry on my shoulder 一.总结 一句话总结:Cry on my shoulder 在我的肩膀上哭泣 1.If the hero never comes to you. ...

  3. 使用caffemodel模型(由mnist训练)测试单张手写数字样本

    caffe中训练和测试mnist数据集都是批处理,可以反馈识别率,但是看不到单张样本的识别效果,这里使用windows自带的画图工具手写制作0~9的测试数字,然后使用caffemodel模型识别. 1 ...

  4. java9新特性-2-安装与官网说明

    1.jdk 9的下载 http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html         下载安 ...

  5. C#篇(一)——字段与属性

    字段和属性有什么区别? class Student { private int age; public int Age { get { return age; } set { age = value; ...

  6. hive查询不加分区的一个异常

    今天下午有同事反馈她提交了了一个SQL后,hive 查询就停止响应了. 我看了下,发现hiveserver确实hug住了.听过查看日志,发现了一个牛逼的SQL, 这个SQL很简单: select a. ...

  7. html中隐藏一个元素的方法

    display:none;                                                      隐藏不占位 opacity:0; fliter:alpha(opa ...

  8. AngularJs轻松入门(七)多视图切换

    在AngularJs应用中,我们可以將html碎片写在一个单独的文件中,然后在其他页面中將该段碎片加载进来.如果有多个碎片文件,我们还可以在控制器中根据用户的操作动态的加载不同的碎片,从而达到切换视图 ...

  9. ACM-ICPC 2017 Asia Urumqi(第八场)

    A. Coins Alice and Bob are playing a simple game. They line up a row of nnn identical coins, all wit ...

  10. 爬虫--pyquery使用

    强大又灵活的网页解析库. 初始化   字符串初始化 html = ''' <div> <ul> <li class="item-0">first ...