The Water Bowls [POJ3185] [开关问题]】的更多相关文章

题意 一串长度为20的0,1数列,每次翻转i,会影响i-1,i+1,也被翻转,最少翻转成0的步骤数是多少? Sample Input 0 0 1 1 1 0 0 1 1 0 1 1 0 0 0 0 0 0 0 0 Sample Output 3 分析 这一道开关问题和POJ3276很类似,但是那个是有固定长度的,我们可以看做是一个点向后的一个区间进行翻转,就不会对前面产生影响. 这道题就不一样,会影响前面的,那我们就看做是i为作用点,i+1,i+2为附带效应点,就可以转换成上面那种类型了.只是要…
Description The cows have a line of 20 water bowls from which they drink. The bowls can be either right-side-up (properly oriented to serve refreshing cool water) or upside-down (a position which holds no water). They want all 20 water bowls to be ri…
POJ3185 The Water Bowls 题目大意: 奶牛有20只碗摆成一排,用鼻子顶某只碗的话,包括左右两只在内的一共三只碗会反向,现在给出碗的初始状态,问至少要用鼻子顶多少次才能使所有碗都朝上 一开始试了一下dfs,由于对dfs还是不太熟悉,先是用了一个数组b[i]来储存翻转后的状态,后来发现这个搜索的状态虽然类似背包,要么翻转,要么不翻转,但是翻转某个碗以后会对其他的也造成影响,所以这样这样做就错了,可以只用原来的数组就ok了 在上述问题解决后,又因为胡乱剪枝导致wa了几次,一开始我…
任意门:http://poj.org/problem?id=3185 The Water Bowls Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7676   Accepted: 3036 Description The cows have a line of 20 water bowls from which they drink. The bowls can be either right-side-up (pro…
Description The cows have a line of water bowls water bowls to be right-side-up and thus use their wide snouts to flip bowls. Their snouts, though, are so wide that they flip not only one bowl but also the bowls on either side of that bowl (a total o…
The Water Bowls 题意:给定20个01串(最终的状态),每个点变化时会影响左右点,问最终是20个0所需最少操作数? 水题..直接修改增广矩阵即可:看来最优解不是用高斯消元(若是有Gauss消元0ms A的请留言~~),很多是0ms过的,我用了32ms; #include<iostream> #include<cstdio> #include<cstring> #include<string.h> #include<algorithm>…
The Water Bowls Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7402 Accepted: 2927 Description The cows have a line of 20 water bowls from which they drink. The bowls can be either right-side-up (properly oriented to serve refreshing cool…
题意:反正就是要给的一串01的变成全0 能影响自己和左右 最少需要几步 01方程组 异或解 ][]; // 增广矩阵 ]; // 解 ]; // 标记是否为自由未知量 int n; void debug() { ;i<n*n;i++) { ;j<n*n;j++) printf("%d ", a[i][j]); printf("\n"); } } int Gauss(int n, int m) // n个方程 m个未知数 即 n行m+1列 { //转换为阶…
水池 题目大意:给定一个20的数组,全都是0和1,可以翻一个数改变成另一个数(0或者1),但是其左右两边的数都会跟着变为原来的相反数,问你怎么用最小的操作数使全部数变成0 这一题的:满足 1:翻转次序不改变结果 2.  从特定次序翻转以后左侧的元素不会再改变 其实就是3276的变形,只是他这次固定变三个数,而且是一前一后,我们把方向dir的查看往前挪一个数就好了,但是这样我们就不能知道第一个数是否需要翻转,所以我们分两种情况来讨论就好了 一开始我想着像3279那样枚举,可是1<<20次实在是太…
题目链接 题意:翻译过来就是20个0或1的开关,每次可以改变相邻三个的状态,问最小改变多少次使得所有开关都置为0,题目保证此题有解. 题解:因为一定有解,所以我们可以正序逆序遍历两次求出较小值即可.当然这题也可以用万能的高斯消元来做.给出两种代码. 暴力代码: #include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm>…