博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 4421 Bit Magic (图论-2SAT)
阅读量:6993 次
发布时间:2019-06-27

本文共 2411 字,大约阅读时间需要 8 分钟。

Bit Magic



Problem Description
Yesterday, my teacher taught me about bit operators: and (&), or (|), xor (^). I generated a number table a[N], and wrote a program to calculate the matrix table b[N][N] using three kinds of bit operator. I thought my achievement would get teacher's attention.
The key function is the code showed below.
There is no doubt that my teacher raised lots of interests in my work and was surprised to my talented programming skills. After deeply thinking, he came up with another problem: if we have the matrix table b[N][N] at first, can you check whether corresponding number table a[N] exists?
 

Input
There are multiple test cases.
For each test case, the first line contains an integer N, indicating the size of the matrix. (1 <= N <= 500).
The next N lines, each line contains N integers, the jth integer in ith line indicating the element b[i][j] of matrix. (0 <= b[i][j] <= 2 
31 - 1)
 

Output
For each test case, output "YES" if corresponding number table a[N] exists; otherwise output "NO".
 

Sample Input
 
2 0 4 4 0 3 0 1 24 1 0 86 24 86 0
 

Sample Output
 
YES NO
 

Source
 

Recommend
zhuyuanchen520   |   We have carefully selected several similar problems for you:            
 

题目大意:

         给你b[i][j],问你a[i]是否冲突?

解题思路:

      对于a[i]的每一位依据 d[i][j] 进行2at

解题代码:

#include 
#include
#include
#include
using namespace std;const int maxn=510;struct edge{ int u,v,next; edge(int u0=0,int v0=0){ u=u0,v=v0; }}e[maxn*maxn*4];int head[maxn*2],cnt,N;int dfn[maxn*2],low[maxn*2],color[maxn*2],index,nc;bool mark[maxn*2];vector
vec;void adde(int u,int v){ e[cnt]=edge(u,v),e[cnt].next=head[u],head[u]=cnt++;}void init(){ vec.clear(); index=nc=cnt=0; for(int i=0;i<=2*N;i++){ dfn[i]=0; color[i]=head[i]=-1; mark[i]=false; }}void tarjan(int s){ dfn[s]=low[s]=++index; mark[s]=true; vec.push_back(s); for(int i=head[s];i!=-1;i=e[i].next){ int d=e[i].v; if(!dfn[d]){ tarjan(d); low[s]=min(low[s],low[d]); }else if(mark[d]){ low[s]=min(low[s],dfn[d]); } } if(low[s]==dfn[s]){ int d; nc++; do{ d=vec.back(); vec.pop_back(); color[d]=nc; mark[d]=false; }while(s!=d); }}bool sat2(){ for(int i=0;i<2*N;i++){ if(!dfn[i]) tarjan(i); } for(int i=0;i

转载地址:http://ghivl.baihongyu.com/

你可能感兴趣的文章
C++l联系常见问题
查看>>
我的友情链接
查看>>
网络测试工具netperf
查看>>
大数据企业战略规划高级培训课程
查看>>
centos 5,6 启动流程
查看>>
我在 CSDN 的回复(其实不咋上,从12306NG过去的)
查看>>
CCNA学习笔记4---路由器启动过程和寄存器值作用
查看>>
React 定义组件
查看>>
第6章Zabbix分布式监控
查看>>
eclipse通过android layour editor无法查看布局文件问题解决
查看>>
oracle常用系统表
查看>>
struts的Action中使用spring的@Transactional注解事务出错
查看>>
单服100w长连接报告笔记
查看>>
解决虚拟主机wordpress邮件发送问题
查看>>
基于OpenResty的Lua Web框架lor
查看>>
我的友情链接
查看>>
C#泛型编程
查看>>
自动删除svn下未版本化的文件和文件夹
查看>>
List<Map> 导出XML格式
查看>>
ActiveMQ简单介绍以及安装
查看>>