题目链接 题意:翻译过来就是20个0或1的开关,每次可以改变相邻三个的状态,问最小改变多少次使得所有开关都置为0,题目保证此题有解. 题解:因为一定有解,所以我们可以正序逆序遍历两次求出较小值即可.当然这题也可以用万能的高斯消元来做.给出两种代码. 暴力代码: #include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm>…
题目链接 给一行0 1 的数, 翻转一个就会使他以及它左右两边的都变, 求最少多少次可以变成全0. 模板题. #include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <map> #include <set> #include…
任意门: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…
题目链接:http://poj.org/problem?id=3185 题意:20盏灯排成一排.操作第i盏灯的时候,i-1和i+1盏灯的状态均会改变.给定初始状态,问最少操作多少盏灯使得所有灯的状态最后均为0. 思路:高斯消元,记录变元个数,枚举变元. int a[N][N],ans[N]; vector<int> b; int Gauss() { b.clear(); int i,j=1,k,t; for(i=1;i<=20;i++) { for(k=j;k<=20;k++) i…
The Water Bowls 题意:给定20个01串(最终的状态),每个点变化时会影响左右点,问最终是20个0所需最少操作数? 水题..直接修改增广矩阵即可:看来最优解不是用高斯消元(若是有Gauss消元0ms A的请留言~~),很多是0ms过的,我用了32ms; #include<iostream> #include<cstdio> #include<cstring> #include<string.h> #include<algorithm>…
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…
题目链接 题意:有20个数字,0或1.如果改变一个数的状态,它左右两边的两个数的状态也会变反.问从目标状态到全0,至少需要多少次操作. 分析: 和上一题差不多,但是比上一题还简单,不多说了,但是在做题的时候犯了一个非常二的错误..看图吧. 先输入了a[0]又,初始了a[][]数组 #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <c…
POJ   1681---Painter's Problem(高斯消元) Description There is a square wall which is made of n*n small square bricks. Some bricks are white while some bricks are yellow. Bob is a painter and he wants to paint all the bricks yellow. But there is something…
思路:乍一看好像和线性代数没什么关系.我们用一个数组B表示第i个位置的灯变了没有,然后假设我用u[i] = 1表示动开关i,mp[i][j] = 1表示动了i之后j也会跟着动,那么第i个开关的最终状态为:u[1]*mp[1][i]^u[2]*mp[2][i]....^u[n]*mp[n][i](或者改为相加 % 2).显然,前式等于B[i],所以,问题转化为了求u的解个数:MP*U = B.注意MP矩阵的写法. 关于矩阵: r(A) = r(A,b)           有解 r(A) = r(…
题目链接:[http://poj.org/problem?id=1222] 题意:Light Out,给出一个5 * 6的0,1矩阵,0表示灯熄灭,反之为灯亮.输出一种方案,使得所有的等都被熄灭. 题解:首先可以用高斯消元来做,对于每个点,我们列出一个方程,左边是某个点和它相邻的点,他们的异或值等于右边的值(灯亮为1 ,灯灭为0),然后求一个异或高斯消元就可以了.可以用bitset优化,或者__int128优化(其实unsigned就可以了). 还可以枚举第一行的按开关的状态共有1<<6中状态…