sgu-260 Puzzle

题目大意:

给你一个01串,长度为N(N<=200),每一位不但能控制自己,还可以控制别的一些位,现在有反转操作,假设我们对第i位执行反转操作,那么i所控制的所有位都会反转。现在给你每位控制的集合,和初始01串,问是否存在一种操作方式使得这个串都为0或1。

解题思路:

直接高斯消元就行了。

没什么可说的。

AC代码:

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream>

using namespace std;

int fc_[300][300]={{0}};
int fc[300][300]={{0}};
int prt[300]={0};
int N;

bool Gauss()
{
    memcpy(fc,fc_,sizeof(fc));
    int remain=1;
    for(int cnt=1;cnt<=N && remain<=N;cnt++)
    {
        int g;
        for(g=remain;g<=N;g++)
        {
            if(fc[g][cnt]!=0)
                break;
        }
        if(g==N+1) continue;
        for(int i=0;i<=N;i++)
            swap(fc[g][i],fc[remain][i]);
        for(int i=1;i<=N;i++)
        {
            if(i==remain || fc[i][cnt]==0) continue;
            for(int j=0;j<=N;j++)
                fc[i][j]^=fc[remain][j];
        }
        remain++;
    }
    for(int i=remain;i<=N;i++)
        if(fc[i][0]==1)
            return false;
    int ans=0;
    for(int i=1;i<=N;i++)
    {
        for(int j=1;j<=N;j++)
        {
            if(fc[i][j]==1 && fc[i][0]==1)
            {
                ans++;
                prt[j]=1;
                break;
            }
        }
    }
    printf("%d\n",ans);
    for(int i=1;i<=N;i++)
        if(prt[i]==1)
            printf("%d ",i);
    printf("\n");
    return true;
}

int main()
{
    scanf("%d",&N);
    for(int i=1;i<=N;i++)
    {
        int j;
        scanf("%d",&j);
        for(;j>0;j--)
        {
            int p;
            scanf("%d",&p);
            fc_[p][i]=1;
        }
    }
    for(int i=1;i<=N;i++)
        scanf("%d",&fc_[i][0]);
    if(Gauss())
        return 0;
    for(int i=1;i<=N;i++)
        fc_[i][0]^=1;
    if(Gauss())
        return 0;
    printf("-1\n");
    return 0;
}
时间: 2024-10-19 01:07:46

sgu-260 Puzzle的相关文章

260. Single Number III

260. Single Number III DescriptionHintsSubmissionsDiscussSolution DiscussPick One Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only o

【SGU 390】Tickets (数位DP)

Tickets Description Conductor is quite a boring profession, as all you have to do is just to sell tickets to the passengers. So no wonder that once upon a time in a faraway galaxy one conductor decided to diversify this occupation. Now this conductor

ACM: SGU 101 Domino- 欧拉回路-并查集

sgu 101 - Domino Time Limit:250MS     Memory Limit:4096KB     64bit IO Format:%I64d & %I64u Description Dominoes – game played with small, rectangular blocks of wood or other material, each identified by a number of dots, or pips, on its face. The bl

UVa - 227 - Puzzle

给空格子上下左右的互换操作,问最后是怎样的 注意一行的最后一个若是空格,需要自己加注意读取时 操作可能分好多行,一定要读取到 0 为止 1 #include <iostream> 2 #include <cstring> 3 using namespace std; 4 char map[50][50],op[1000],c,tmp; 5 int k,t,x,y,cnt; 6 bool flag; 7 void fuc() 8 { 9 flag=1; 10 for(int i=0;

HDU 5465 Clarke and puzzle Nim游戏+二维树状数组

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5465 Clarke and puzzle Accepts: 42 Submissions: 269 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 问题描述 克拉克是一名人格分裂患者.某一天,有两个克拉克(aa和bb)在玩一个方格游戏. 这个方格是一个n*mn∗m的矩阵,每个格子里有一

uva 260 - Il Gioco dell&#39;X

题解: 一定有人获胜,非黑即白:获胜条件为:black是由 上走到下,white是由 左走到右: 1 #include <cstdio> 2 using namespace std; 3 int N; 4 char board[201][201]; 5 const int direction[][2] = {{-1,-1},{-1,0},{0,-1},{0,1},{1,0},{1,1}}; 6 void DFS(int i, int j, char c,int &win) 7 { 8

HDU 1098 Ignatius&#39;s puzzle 费马小定理+扩展欧几里德算法

题目大意: 给定k,找到一个满足的a使任意的x都满足 f(x)=5*x^13+13*x^5+k*a*x 被65整除 推证: f(x) = (5*x^12 + 13 * x^4 + ak) * x 因为x可以任意取 那么不能总是满足 65|x 那么必须是 65 | (5*x^12 + 13 * x^4 + ak) 那么就是说 x^12 / 13 + x^4 / 5 + ak / 65 正好是一个整数 假设能找到满足的a , 那么将 ak / 65 分进x^12 / 13 + x^4 / 5中得到

HDU 4708 Rotation Lock Puzzle (贪心+模拟)

Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1668    Accepted Submission(s): 530 Problem Description Alice was felling into a cave. She found a strange door with a number

Dearboy&#39;s Puzzle (poj 2308 搜索 dfs+bfs)

Language: Default Dearboy's Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1202   Accepted: 208 Description Dearboy is a game lover. Recently, he loves playing the game Lian Lian Kan. This game is played on a board with N*M grids

hduoj 4708 Rotation Lock Puzzle 2013 ACM/ICPC Asia Regional Online —— Warmup

http://acm.hdu.edu.cn/showproblem.php?pid=4708 Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description Alice was felling into a cave. She found a strange door with a number square m