CSUOJ 1637 Yet Satisfiability Again!
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!的更多相关文章
- csuoj 1511: 残缺的棋盘
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1511 1511: 残缺的棋盘 时间限制: 1 Sec 内存限制: 128 MB 题目描述 输入 ...
- POJ 1637 Sightseeing tour (混合图欧拉路判定)
Sightseeing tour Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6986 Accepted: 2901 ...
- bzoj 1637: [Usaco2007 Mar]Balanced Lineup
1637: [Usaco2007 Mar]Balanced Lineup Time Limit: 5 Sec Memory Limit: 64 MB Description Farmer John ...
- csuoj 1354: Distinct Subsequences
这个题是计算不同子序列的和: spoj上的那个同名的题是计算不同子序列的个数: 其实都差不多: 计算不同子序列的个数使用dp的思想: 从头往后扫一遍 如果当前的元素在以前没有出现过,那么dp[i]=d ...
- BZOJ 1637: [Usaco2007 Mar]Balanced Lineup( sort + 前缀和 )
将 0 变为 -1 , 则只需找区间和为 0 , 即前缀和相同的最长区间 , 记录一下每个前缀和出现的最早和最晚的位置 , 比较一下就 OK 了 --------------------------- ...
- POJ 1637 Sightseeing tour(最大流)
POJ 1637 Sightseeing tour 题目链接 题意:给一些有向边一些无向边,问能否把无向边定向之后确定一个欧拉回路 思路:这题的模型很的巧妙,转一个http://blog.csdn.n ...
- 1637: [Usaco2007 Mar]Balanced Lineup
1637: [Usaco2007 Mar]Balanced Lineup Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 393 Solved: 263[ ...
- [POJ 1637] Sightseeing tour(网络流)
题意 (混合图的欧拉回路判定) 给你一个既存在有向边, 又存在无向边的图. 问是否存在欧拉回路. \(N ≤ 200, M ≤ 1000\) 题解 难点在于无向边. 考虑每个点的度数限制. 我们先对无 ...
- POJ 1637 - Sightseeing tour - [最大流解决混合图欧拉回路]
嗯,这是我上一篇文章说的那本宝典的第二题,我只想说,真TM是本宝典……做的我又痛苦又激动……(我感觉ACM的日常尽在这张表情中了) 题目链接:http://poj.org/problem?id=163 ...
随机推荐
- 微软100题第51题:和为n连续正数序列
题目:输入一个正数n,输出全部和为n连续正数序列.比如输入15,因为1+2+3+4+5=4+5+6=7+8=15,所以输出3个连续序列1-5.4-6和7-8. 方法一:记录序列长度.推断首项是否满足条 ...
- 【BZOJ 1660】 [Usaco2006 Nov]Bad Hair Day 乱发节
1660: [Usaco2006 Nov]Bad Hair Day 乱发节 Time Limit: 2 Sec Memory Limit: 64 MB Submit: 678 Solved: 32 ...
- Django是什么
Django是什么 Django是什么? 是基于python语言的优秀的web开发框架.很多有名的网站比如youtube就是用django开发的. Python写的开源Web应用框架, 快速搭建blo ...
- Laravel-路由组和中间件
Laravel-路由组和中间件 标签(空格分隔): php 定义路由组 Route::group(['prefix'=>'Anime'], function(){ Rout::match(['g ...
- POJ 2248 搜索
剪枝: 1.从后向前枚举 2.迭代加深 然后就0msAC了 //By SiriusRen #include <cstdio> using namespace std; int n,T,s[ ...
- jsp输出九九乘法表
<% String st = ""; for(int i = 1; i <= 9; i++){ for(int j = 1; j <= i; j++){ st + ...
- python3.x 学习笔记1(基础知识)
1.python模块: 标准库和第三方库,第三方库需要下载安装 2.模块sys: 命令 功能 sys.stdin 标准输入流sys.stdout 标准输出流sys.stderr ...
- 减少XML文件数
在android开发中,做出漂亮的ui的应用,往往有数量庞大的xml文件.比如,我们要给一个Button加上一个selector,如果背景不是图片,就得写三个xml文件,分别是:edit_focuse ...
- .net 操作INI文件
using System.Runtime.InteropServices; using System.Text; namespace FaureciaManager { public class Fi ...
- 冒泡排序php
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> <b ...