NOIP 考前 高斯消元练习
POJ 1830
列出n个方程右边为最后的情况
每一行代表第几个灯的情况,每一行代表是否按第几个按钮写出方程即可。
#include <cstdio>
#include <cstring>
const int Maxn=;
int M[Maxn][Maxn],Ans,a[Maxn],b[Maxn],p,q,KASE,n;
inline void Swap(int &x,int &y) {int t=x;x=y;y=t;}
inline bool Check(int x)
{
for (int i=;i<=n;i++) if (M[x][i]) return false;
return true;
}
bool Gauss()
{
int Pos=;
for (int i=;i<=n;i++)
{
int k=;
for (int j=Pos;j<=n;j++) if (M[j][i]) {k=j; break;}
if (k==) continue;
for (int j=;j<=n+;j++) Swap(M[Pos][j],M[k][j]);
for (int j=;j<=n;j++)
if (M[j][i] && j!=Pos)
for (int l=;l<=n+;l++) M[j][l]^=M[Pos][l];
Pos++;
}
int cnt=;
for (int i=;i<=n;i++)
if (Check(i))
{
if (M[i][n+]) return false;
cnt++;
}
return Ans=(<<cnt);
}
int main()
{
scanf("%d",&KASE);
for (int Kase=;Kase<=KASE;Kase++)
{
scanf("%d",&n);
memset(M,,sizeof(M));
for (int i=;i<=n;i++) scanf("%d",&a[i]);
for (int i=;i<=n;i++) scanf("%d",&b[i]);
for (int i=;i<=n;i++) M[i][n+]=a[i]^b[i];
for (int i=;i<=n;i++) M[i][i]=;
while (scanf("%d%d",&p,&q)!=EOF)
{
if (p== && q==) break;
M[q][p]=;
}
if (Gauss()) printf("%d\n",Ans); else puts("Oh,it's impossible~!!");
}
return ;
}
POJ 1830
NOIP 考前 高斯消元练习的更多相关文章
- 【BZOJ-3143】游走 高斯消元 + 概率期望
3143: [Hnoi2013]游走 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2264 Solved: 987[Submit][Status] ...
- 【BZOJ-3270】博物馆 高斯消元 + 概率期望
3270: 博物馆 Time Limit: 30 Sec Memory Limit: 128 MBSubmit: 292 Solved: 158[Submit][Status][Discuss] ...
- *POJ 1222 高斯消元
EXTENDED LIGHTS OUT Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9612 Accepted: 62 ...
- [bzoj1013][JSOI2008][球形空间产生器sphere] (高斯消元)
Description 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困在了这个n维球体中,你只知道球 面上n+1个点的坐标,你需要以最快的速度确定这个n维球体的球心坐标,以便于摧 ...
- hihoCoder 1196 高斯消元·二
Description 一个黑白网格,点一次会改变这个以及与其连通的其他方格的颜色,求最少点击次数使得所有全部变成黑色. Sol 高斯消元解异或方程组. 先建立一个方程组. \(x_i\) 表示这个点 ...
- BZOJ 2844 albus就是要第一个出场 ——高斯消元 线性基
[题目分析] 高斯消元求线性基. 题目本身不难,但是两种维护线性基的方法引起了我的思考. void gauss(){ k=n; F(i,1,n){ F(j,i+1,n) if (a[j]>a[i ...
- SPOJ HIGH Highways ——Matrix-Tree定理 高斯消元
[题目分析] Matrix-Tree定理+高斯消元 求矩阵行列式的值,就可以得到生成树的个数. 至于证明,可以去看Vflea King(炸树狂魔)的博客 [代码] #include <cmath ...
- UVALive 7138 The Matrix Revolutions(Matrix-Tree + 高斯消元)(2014 Asia Shanghai Regional Contest)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...
- [高斯消元] POJ 2345 Central heating
Central heating Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 614 Accepted: 286 Des ...
随机推荐
- find / -type f -name "*fetion*" |xargs rm -rf {}\
find / -type f -name "*fetion*" |xargs rm -rf {}\
- Tomcat version 7.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5 and 6 Web modules
解决方案: 找到如下文件 将"jst.web"的version改低一些
- iOS -初识UIKit
UIKit框架:UI界面上每一个元素都是一个对象 一张图片是UIimageView对象 一段文字是一个UILabei对象 一个按钮是一个UIButton对象 搭建UI界面的步骤 利用类创建对象 将对象 ...
- JQuery,拼接字符串问题(求助)
Js代码 $("#span_btnSave").html(str1); 结果 <span id="span_btnSave"><button ...
- asp.net网站运行出错:the underlying provider failed on open的解决
在登录系统,通过linq查询时发生错误,the underlying provider failed on open,如何解决,请看: Step 1:Open Internet Information ...
- nginx 页面乱码问题
在配置nginx时常常遇到网页乱码的问题如图: 这时需要在server段里面添加两行: default_type 'text/html'; charset utf-8; 然后执行测试 重启操作 ng ...
- 读取.properties配置文件
方法1 public class SSOUtils { protected static String URL_LOGIN = "/uas/service/api/login/info&q ...
- tensor flow入门笔记
个人学习笔记,欢迎交流.
- js动画之缓冲运动
缓冲运动就是运动的速度与时间或者距离有关联,不是一般的匀速运动 <!DOCTYPE html> <html lang="en"> <head> ...
- 【转帖】Python在大数据分析及机器学习中的兵器谱
Flask:Python系的轻量级Web框架. 1. 网页爬虫工具集 Scrapy 推荐大牛pluskid早年的一篇文章:<Scrapy 轻松定制网络爬虫> Beautiful Soup ...