题目

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的更多相关文章

  1. 转:Media Player Classic - HC 源代码分析

    VC2010 编译 Media Player Classic - Home Cinema (mpc-hc) Media Player Classic - Home Cinema (mpc-hc)播放器 ...

  2. 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/ ...

  3. Codeforces Round #192 (Div. 1) C. Graph Reconstruction 随机化

    C. Graph Reconstruction Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/3 ...

  4. Media Player Classic - HC 源代码分析 3:核心类 (CMainFrame)(2)

    ===================================================== Media Player Classic - HC 源代码分析系列文章列表: Media P ...

  5. Media Player Classic - HC 源代码分析 2:核心类 (CMainFrame)(1)

    ===================================================== Media Player Classic - HC 源代码分析系列文章列表: Media P ...

  6. Unity Shader Graph(二)Dissolve Effect

    此篇文章记录Dissolve Effect(溶解特效)的制作过程 软件环境 Unity 2018.1.2f1 Packages: Lightweight Render Pipeline 1.1.11 ...

  7. 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 ...

  8. 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 ...

  9. HDU - 3407 - String-Matching Automata

    先上题目: String-Matching Automata Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

随机推荐

  1. arm Linux 驱动LED子系统 测试

    Linux内核在3.0以上引入了设备树概念(具体哪个版本不清楚)在编译内核后需要将与之对应的dtb文件也下载人板子上才能使内核与硬件关联起来. dtb文件是有dts文件编译后生成的:例如 /* * C ...

  2. intellij idea 中文 汉化包 韩梦飞沙

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha 汉化包 百度云盘 下载地址: https://pan.baidu.com/s/1hs6B ...

  3. codevs 3160 最长公共子串 后缀自动机

    http://codevs.cn/problem/3160/ 后缀自动机板子题,匹配的时候要注意如果到一个点失配向前匹配到一个点时,此时的tmp(当前匹配值)为t[j].len+1而不是t[t[j]. ...

  4. loj2576 「TJOI2018」str

    link 题意: 给一个模板串s和n个模式串,每个模式串有$a_i$种可取的串.现在要将n个模式串每个任取一种它可取的串,连接起来,记为串t,那么这种连接方式对答案的贡献为t在s中出现的次数.问所有连 ...

  5. 2017-2018-1 JAVA实验站 冲刺 day02

    2017-2018-1 JAVA实验站 冲刺 day02 各个成员今日完成的任务 小组成员 今日工作 完成进度 张韵琪 写博客.进行工作总结 100% 齐力锋 找背景音乐.开始界面图片.按钮图片.按钮 ...

  6. Laravel输出JSON时设定输出字段的几种情况总结

    1.如果输出json的时候需要屏蔽某些字段,或则想自定义显示的字段: 1.model里面设置 protected $hidden = ['password'];//要屏蔽的字段 2.model里面设置 ...

  7. poj 3468 A Simple Problem with Integers 线段树区间加,区间查询和

    A Simple Problem with Integers Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://poj.org/problem?i ...

  8. “请不要直接访问超全局$_GET数组”

    下载了一个名为NetBeans的IDE开发PHP程序,当我输入常用的的$name = $_GET['name'];时却收到警告:请不要直接访问超全局$_GET数组 请改用某些过滤函数(例如filter ...

  9. object-c语言的nonatomic,assign,copy,retain的区别

    nonatomic: 非原子性访问,不加同步,多线程并发访问会提高性能.如果不加此属性,则默认是两个访问方法都为原子型事务访问.                    (atomic是Objc使用的一 ...

  10. 使用Redisson实现分布式锁

    原文:https://www.jianshu.com/p/cde0700f0128 1. 可重入锁(Reentrant Lock) Redisson的分布式可重入锁RLock Java对象实现了jav ...