Graph Automata Player
题目 action=problem&type=show&id=12839&courseid=269">here
第一道高速幂。同一时候也是第一道高斯消元。
输入的边的关系矩阵就是系数矩阵co
[co] ^ T * [ans]== (当前0时刻的状态)。[co] ^ T可由矩阵高速幂解得
那么-T时刻的状态便是ans矩阵的值。可由高斯消元解得
推断一下就可以
高斯消元中 系数矩阵是a[0...n - 1][0...m - 1] 常数矩阵是a[0...n - 1][m]
返回-1表示无解,等于0有唯一解。大于0表示不确定的变量个数
#include <cstdio>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <string>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <bitset>
#include <fstream>
using namespace std; //LOOP
#define FF(i, a, b) for(int i = (a); i < (b); ++i)
#define FE(i, a, b) for(int i = (a); i <= (b); ++i)
#define FED(i, b, a) for(int i = (b); i>= (a); --i)
#define REP(i, N) for(int i = 0; i < (N); ++i)
#define CLR(A,value) memset(A,value,sizeof(A))
#define FC(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++) //OTHER
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair
#define all(x) (x).begin(),(x).end() //INPUT
#define RI(n) scanf("%d", &n)
#define RII(n, m) scanf("%d%d", &n, &m)
#define RIII(n, m, k) scanf("%d%d%d", &n, &m, &k)
#define RIV(n, m, k, p) scanf("%d%d%d%d", &n, &m, &k, &p)
#define RV(n, m, k, p, q) scanf("%d%d%d%d%d", &n, &m, &k, &p, &q)
#define RS(s) scanf("%s", s) //OUTPUT
#define WI(n) printf("%d\n", n)
#define WS(n) printf("%s\n", n) //debug
//#define online_judge
#ifndef online_judge
#define dt(a) << (#a) << "=" << a << " "
#define debugI(a) cout dt(a) << endl
#define debugII(a, b) cout dt(a) dt(b) << endl
#define debugIII(a, b, c) cout dt(a) dt(b) dt(c) << endl
#define debugIV(a, b, c, d) cout dt(a) dt(b) dt(c) dt(d) << endl
#define debugV(a, b, c, d, e) cout dt(a) dt(b) dt(c) dt(d) dt(e) << endl
#else
#define debugI(v)
#define debugII(a, b)
#define debugIII(a, b, c)
#define debugIV(a, b, c, d)
#endif #define sqr(x) (x) * (x)
typedef long long LL;
typedef unsigned long long ULL;
typedef vector <int> VI;
const double eps = 1e-9;
const int MOD = 1000000007;
const double PI = acos(-1.0);
//const int INF = 0x3f3f3f3f;
const int maxn = 310;
const LL INF = 0x3f3f3f3f3f3f3f3fLL; struct Mat{
int n, m;
bool v[maxn][maxn];
Mat(int n = 0, int m = 0, int zero = 0)
{
this->n = n; this->m = m;
if (zero)
{
REP(i, n) REP(j, m)
v[i][j] = false;
}
}
}; Mat mul(Mat& a, Mat&b)
{
Mat ret(a.n, b.m, 1);
REP(i, a.n)
REP(j, b.m)
REP(k, a.m)
ret.v[i][j] ^= (a.v[i][k] & b.v[k][j]);
return ret;
} Mat qpow(Mat& a, int b)
{
Mat ret(a.n, a.m);
bool f = 1;
while (b)
{
if (b & 1)
{
if (f)
ret = a, f = 0;
else
ret = mul(ret, a);
}
b >>= 1;
a = mul(a, a);
}
return ret;
} bool a[maxn][maxn];
int gauss(int N, int M)
{
int r, c, pvt;
bool flag;
for (r = 0, c = 0; r < N && c < M; r++, c++)
{
flag = false;
for (int i = r; i < N; i++)
if (a[i][c])
{
flag = a[pvt = i][c];
break;
}
if (!flag)
{
r--;
continue;
}
if (pvt != r)
for (int j = r; j <= M; j++)
swap(a[r][j], a[pvt][j]);
for (int i = r + 1; i < N; ++i) {
if (a[i][c])
{
a[i][c] = false;
for (int j = c + 1; j <= M; ++j)
if (a[r][j])
a[i][j] = !a[i][j];
}
}
}
for (int i = r; i < N; i++)
if (a[i][M])
return -1;
if (r < M)
return M - r;
for (int i = M - 1; i >= 0; i--)
{
for (int j = i + 1; j < M; j++)
if (a[i][j])
a[i][M] ^= a[j][M];
a[i][M] /= a[i][i];
}
return 0;
} int main()
{
int n, T, x;
while (~RI(n))
{
Mat co(n, n);
REP(i, n)
REP(j, n)
{
RI(x);
co.v[i][j] = (x == 1 ? true : false);
}
REP(i, n)
{
RI(x);
a[i][n] = (x == 1 ? true : false);
}
RI(T);
co = qpow(co, T);
REP(i, n) REP(j, n) a[i][j] = co.v[i][j];
int ans = gauss(n, n);
if (ans == -1)
puts("none");
else if (ans)
puts("ambiguous");
else
{
REP(i, n)
printf("%d%c", a[i][n], (i == n - 1 ? '\n' : ' '));
}
}
return 0;
}
Graph Automata Player的更多相关文章
- 转:Media Player Classic - HC 源代码分析
VC2010 编译 Media Player Classic - Home Cinema (mpc-hc) Media Player Classic - Home Cinema (mpc-hc)播放器 ...
- Codeforces Round #286 (Div. 1) D. Mr. Kitayuta's Colorful Graph 并查集
D. Mr. Kitayuta's Colorful Graph Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/ ...
- Codeforces Round #192 (Div. 1) C. Graph Reconstruction 随机化
C. Graph Reconstruction Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/3 ...
- Media Player Classic - HC 源代码分析 3:核心类 (CMainFrame)(2)
===================================================== Media Player Classic - HC 源代码分析系列文章列表: Media P ...
- Media Player Classic - HC 源代码分析 2:核心类 (CMainFrame)(1)
===================================================== Media Player Classic - HC 源代码分析系列文章列表: Media P ...
- Unity Shader Graph(二)Dissolve Effect
此篇文章记录Dissolve Effect(溶解特效)的制作过程 软件环境 Unity 2018.1.2f1 Packages: Lightweight Render Pipeline 1.1.11 ...
- NEERC 2016-2017 Probelm G. Game on Graph
title: NEERC 2016-2017 Probelm G. Game on Graph data: 2018-3-3 22:25:40 tags: 博弈论 with draw 拓扑排序 cat ...
- Codeforces Gym 101190 NEERC 16 G. Game on Graph(博弈+拓扑)
Gennady and Georgiy are playing interesting game on a directed graph. The graph has n vertices and m ...
- HDU - 3407 - String-Matching Automata
先上题目: String-Matching Automata Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
随机推荐
- Linux Shall命令入门
Linux Shall命令入门 ifconfig //查看ip信息 service network start ...
- luogu P1011 车站
题目描述 火车从始发站(称为第1站)开出,在始发站上车的人数为a,然后到达第2站,在第2站有人上.下车,但上.下车的人数相同,因此在第2站开出时(即在到达第3站之前)车上的人数保持为a人.从第3站起( ...
- 【manacher+FFT】BZOJ3160-万径人踪灭
[题目大意] 在一个仅仅含有a,b的字符串里选取一个子序列,使得: 1.位置和字符都关于某条对称轴对称: 2.不能是连续的一段. [思路] 不连续的回文串的个数=总的回文串个数-连续回文串的个数. 后 ...
- Java后台直接生成二维码介绍
Java后台直接生成二维码 1.其实jquery也可以直接生成二维码的,但我测试的时候,二维码生成后太模糊,难以识别.所以在这里介绍在后来生成二维码的方式. 2.不善于文字描述,直接上代码了. imp ...
- Spring Boot中Request method 'PUT' not supported
在项目中使用restful风格put提交时报错,是由于form表单中的th:href引起的(支持post提交),改为th:action即可
- Problem B: 深入浅出学算法003-计算复杂度
Description 算法复杂度一般分为:时间复杂度.空间复杂度.编程复杂度. 这三个复杂度本身是矛盾体,不能一味地追求降低某一复杂度,否则会带来其他复杂度的增加.在权衡各方面的情况下,降低时间复杂 ...
- 【8.28校内测试】【区间DP】
感受到了生活的艰辛QAQ...这才是真正的爆锤啊...(因为t1t3还没有理解所以只能贴t2叻QAQ 区间DP...爆哭把题理解错了,以为随着拿的东西越来越多,断点也会越来越多,出现可以选很多的情况Q ...
- 2015 UESTC 数据结构专题H题 秋实大哥打游戏 带权并查集
秋实大哥打游戏 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 Descr ...
- 博雅PHP高级工程师面试题-自拟
作者:元如枫 2010年 1.现有学校课程内容系统简单需求描述,试着提供解决方案. 需求简单描述如下: 1)对象及属性 学校: 学校名称,学校所属分类,学校介绍,学校地图标记,学校所属地区,标签, ...
- 基于Memcached的tomcat集群session共享所用的jar及多个tomcat各种序列化策略配置
原文:http://www.cnblogs.com/interdrp/p/4096466.html 多个tomcat各种序列化策略配置如下:一.java默认序列化tomcat配置conf/contex ...