图论(2-sat):HDU 4421 Bit Magic】的更多相关文章

HDU 4421 Bit Magic pid=4421" target="_blank" style="">题目链接 题意:就依据题目,给定b数组.看能不能构造出一个符合的a数组 思路:把每一个数字的每一个二进制位单独考虑.就变成一个2-sat题目了,依据题目中的式子建立2-sat的边.然后每一位跑2-sat.假设每位都符合.就是YES,假设有一位不符合就是NO 代码: #include <cstdio> #include <cst…
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 ac…
Bit Magic Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3040    Accepted Submission(s): 871 Problem Description Yesterday, my teacher taught me about bit operators: and (&), or (|), xor (^). I…
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4421 题目大意: 给了你一段代码, 用一个数组的数 对其进行那段代码的处理,是可以得到一个矩阵 让你判断这个矩阵能否由一个数组转化而来. 思路: 既然每组数据可以得到,那么他肯定能消去. 我们用一个数组P[i][j] 保存 a[i]^a[j]   的值 a[i]^a[j] 我们可用 P[i][j] = P[i][j-1]^a[j-1]^a[j] 这样我们就可以找出所有 P[i][j] = a[i]^…
[题意] 这个函数是给A求B的,现在给你B,问你是否能有A的解存在. [2-SAT解法] 对于每个A[i]的每一位运行2-sat算法,只要跑到强连通就可以结束,应为只要判断是否有解,后面拓扑求解就不需要了.构图和算法思想和基本的2-sat一致,详见我的2-sat博文. #include <stdio.h> #include <string.h> inline int min(int a,int b){return a>b?b:a;} struct edge { int v,n…
题目链接:hdu 3183 A Magic Lamp 题目大意:给定一个字符串,然后最多删除K个.使得剩下的组成的数值最小. 解题思路:问题等价与取N-M个数.每次取的时候保证后面能取的个数足够,而且取的数最小,查询最小的操作用RMQ优化. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 10005; int N, M, d[m…
hdu 3183 A Magic Lamp RMQ ST 坐标最小值 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183 题目大意: 从给定的串中挑出来m个数使得剩余的数字最小,串的序列不能改变 思路: 将问题转化为求在n个数中挑选n-m个数,使之最小.假设最极端的情况,所有最大的数字都在左侧,占据了m个位置,那么我们需要挑选的最小的数字的第一位就是在m+1位上.依次类推,第二位在m+2位上,最后一位也就在原串的最后一位上.反过来,假设最大的数…
A Magic Lamp Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7170    Accepted Submission(s): 2866 Problem Description Kiki likes traveling. One day she finds a magic lamp, unfortunately the geni…
2-SAT,不要所有位置全部建好边再判断,那样会MLE的. 正解是,每一位建好边,就进行一次2-SAT. #include<cstdio> #include<cstring> #include<cmath> #include<stack> #include<queue> #include<algorithm> using namespace std; +; int N; ][]; stack<int>S; vector&l…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183 Problem DescriptionKiki likes traveling. One day she finds a magic lamp, unfortunately the genie in the lamp is not so kind. Kiki must answer a question, and then the genie will realize one of her d…
A Magic Lamp Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description Kiki likes traveling. One day she finds a magic lamp, unfortunately the genie in the lamp is not so kind. Kiki must answer a question…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4421 思路:枚举32位bit,然后2-sat判断可行性,这里给出2-sat矛盾关系构图: 1.a&b=0  :  a->~b,b->~a; 2.a&b=1  :  ~a->a,~b->b; 3.a|b=0   :   a->~a,b->~b; 4.a|b=1   :   ~a->b,~b->a; 5.a^b=0  :   a->b,b-&g…
题目转自hdu 1102,题目传送门 题目大意: 输入一个n*n的邻接矩阵,其中i行j列代表从i到j的路径的长度 然后又m条路已经帮你修好了,求最短要修多长的路才能使所有村庄连接 不难看出,这道题就是标准的最小生成树模板,多水啊 解题思路 虽然很水,但本人还是调了近1h才把代码调好...... 下面介绍一下解决最小生成树的两个方法: Prim 和 Kruskal 一,Prim(不懂的点这里) Prim的思想和dijkstra的想法很想(如果不知道dijkstra算法的请点这里) 那么Prim的复…
A Magic Lamp                                                                               Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description Kiki likes traveling. One day she finds a magic lamp, u…
题目转自hdu 1198,题目传送门 题目大意: 给你11种单位水管摆放位置,若上下或左右有水管连接则视为这两点相连. 最后让你求这些张图中有几个连通块. 解题思路: 本来觉得这道题很简单,不就一个建图在并查集不就完了吗? (如果连并查集都不会,请点此学习一下) 当然,并没有这么简单(在T了十几次后终于明白) 然后,我们可以发现,每个单位只有4个方向. 很容易想到用二进制进行状态压缩 压缩代码如下: int change(char ch) { switch(ch) { ; ; ; ; ; ; ;…
Description Kiki likes traveling. One day she finds a magic lamp, unfortunately the genie in the lamp is not so kind. Kiki must answer a question, and then the genie will realize one of her dreams. The question is: give you an integer, you are allowe…
原题目 A Magic Lamp Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3964    Accepted Submission(s): 1605 Problem Description Kiki likes traveling. One day she finds a magic lamp, unfortunately the…
直接模拟   如果后一位比前一位小,那就一直 向前 pop()掉 维护他单调递增: #include<iostream> #include<cstring> #include<algorithm> #include<cmath> #include<stdio.h> #include<vector> using namespace std; ]; ],num; int main( ) { while( scanf("%s%d&…
思路: dp[i][j][k]表示满足前i个数,和为j,lcm为k的数目. 设a为解的第i+1个数. 那么状态转移就为 dp[i+1][j+a][lcm(a,k)]+=dp[i][j][k]. 但是由于三维开不了,所以用滚动数组. 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include<iomanip> #include<cmath> #include<…
思路:我们需要判断是否有满足的a[n],其实也就是对每一个二进制位进行判断,看是否有满足的.那么我们每次取出一个二进制位,这样每一位只有0,1两种状态,就成了比较典型的2-SAT问题了. #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<queue> #define Maxn 1010 #define Maxm Maxn*Maxn…
一个长了一张数学脸的dp!!dp[ i ][ s ][ t ] 表示第 i 个数,sum为 s ,lcm下标为 t 时的个数.显然,一个数的因子的lcm还是这个数的因子,所以我们的第三维用因子下标代替lcm,可以有效的减少枚举量. #include<algorithm> #include<iostream> #include<cstring> #include<vector> #include<cstdio> #include<cmath&…
第一种做法是贪心做法,只要前面的数比后面的大就把他删掉,这种做法是正确的,也比较好理解,这里就不说了,我比较想说一下ST算法,RMQ的应用 主要是返回数组的下标,RMQ要改成<=(这里是个坑点,取连续数是可以的),他的转移方程为x = dp[i-1][j],y = dp[i-1][j+1<<(i-1)]; dp[i][j] = a[x] <= a[y] ? x : y; 这里既是转化为取n-m个数,首先在1 ~ m+1中必然选一个数,所以这个数就是n-m数中第一个数,记录所选的位置…
<题目链接> <转载于 >>>  > 题目大意: 给出一个长度不超过1000位的数,求删去m位数字以后形成的最小的数字是多少. 解题分析: 分析:我们可以把题目转化为这样一个模型:从A[1].A[2].…….A[n] n个数中选出n-m个数,使得组成的数最小.一.使用RMQ,设原数字长为n,那么除去m个数字后还剩n-m个数字.    下面的(一).(二)用到了抽屉原理(1)因为有n-m个数字,那么在0到m-1位置中最小的那个数字必是结果中的第一个数字,记录其位置为…
/* 题意:还是二进制异或,和poj3678类似 建边和poj3678一样 */ #include<stdio.h> #include<string.h> #include<math.h> #define N 2100 struct node { int v,next; } bian[N*N]; int head[N],dfn[N],low[N],vis[N],stac[N],belong[N],yong,ans,index,top; void init() { yon…
1.题目大意是,给你一个1000位的数,要你删掉m个为,求结果最小数. 思路:在n个位里面删除m个位.也就是找出n-m个位组成最小数 所以在区间 [0, m]里面找最小的数.相应的下标标号i 接着找区间 [i+1,m++]里面的最小数.对于下标为ii 接着找区间 [ii+1,m++]里面的最小数-- 这样就会找n-m个数了.区间这样安排的目的是为了保证取出来的数的顺序. 2代码: #include<cstdio> #include<cstring> #include<cmat…
#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <set> #include <map> #include <string> #include <ma…
Problem Description Ali has taken the Computer Organization and Architecture course this term. He learned that there may be dependence between instructions, like WAR (write after read), WAW, RAW. If the distance between two instructions is less than…
2-sat总结 2-sat问题,一般表现的形式为.每一个点有两种方式a,b,要么选a,要么选b.而且点点之间有一些约束关系.比如:u和v至少一个选a.那么这就是一个表达式.把a当成真,b当成假,那就是u真或v真.2-sat的题目就是这样.给定这些约束,推断是否会矛盾 注意表达式的转化形式,(事实上就是离散数学中那几种转换方式) 比方(u真且v真)或(u假且v假)就能够转化成(u真或v假)且(u假或v真),这样就能建立关系 2-sat中的原理,事实上和2染色是一样的,把每一个结点拆分成一个真结点和…
转自:http://blog.csdn.net/shahdza/article/details/7779369 [HDU]3062 Party1824 Let's go home3622 Bomb Game3715 Go Deeper1815 Building roads1816 Get Luffy Out *1814 Peaceful Commission4115 Eliminate the Conflict4421 Bit Magic=============================…
11.9 线段树 http://acm.hdu.edu.cn/showproblem.php?pid=6315 求逆序对个数 http://acm.hdu.edu.cn/showproblem.php?pid=6318 必赢博弈 http://acm.hdu.edu.cn/showproblem.php?pid=6312 欧拉回路 http://acm.hdu.edu.cn/showproblem.php?pid=6311 好难的构造题目 http://acm.hdu.edu.cn/showpr…