栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 2502 Odd Loving Bakers

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 2502 Odd Loving Bakers

#include <map>#include <cstdio>#include <string>#include <algorithm>using namespace std;char buf[108];bool mat[100][100], tmp[2][100][100];bool x[101], y[101];int first1(int x){    int ret = 30;    while((x & (1 << ret)) == 0)        --ret;    return ret;}void copy(const int n, bool t[100][100], const bool s[100][100]){    for (int i = 0; i < n; i++)        for (int j = 0; j < n; j++) t[i][j] = s[i][j];}void mul(const int n, const bool a[100][100], const bool b[100][100], bool ret[100][100]){    int t;    for (int i = 0; i < n; i++)        for (int j = 0; j < n; j++) { t = 0; for (int k = 0; k < n; k++)     if(a[i][k] & b[k][j])         ++t; ret[i][j] = (t & 1);        }}int main(void){    int re;    int n, t, m, a, b;    map<string, int> mp;    map<string, int>::iterator it;    scanf("%d", &re);    while(re--) {        mp.clear();        scanf("%d%d", &n, &t);        for (int i = 0; i < n; i++) for (int j = 0; j < n; j++)     mat[i][j] = false;        for (int i = 0; i < n; i++) { scanf("%s", buf); it = mp.find(buf); if(it == mp.end()) {     a = (int)mp.size();     mp.insert(make_pair((string)buf, a)); } else {     a = it->second; } scanf("%d%d", &b, &m); x[a] = (b & 1); for (int j = 0; j < m; j++) {     scanf("%s", buf);     it = mp.find(buf);     if(it == mp.end()) {         b = (int)mp.size();         mp.insert(make_pair((string)buf, b));     }     else {         b = it->second;     }     mat[b][a] = true; }        }        for (int i = 0; i < n; i++) mat[i][i] = !mat[i][i];        if(t == 1) { printf("%dn", count(x, x + n, true));        }        else { --t; a = 0; b = 1; copy(n, tmp[a], mat); for (int i = first1(t) - 1; i >= 0; i--) {     mul(n, tmp[a], tmp[a], tmp[b]);     swap(a, b);     if(t & (1 << i)) {         mul(n, mat, tmp[a], tmp[b]);         swap(a, b);     } } for (int i = 0; i < n; i++) {     y[i] = false;     for (int j = 0; j < n; j++)         if(x[j] & tmp[a][i][j])  y[i] = !y[i]; } printf("%dn", count(y, y + n, true));        }    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/377294.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号