• BZOJ1923: [Sdoi2010]外星千足虫


    题解:

    我的做法是这样的:动态维护线性基,当线性基的个数达到n的时候就有唯一解。

    自己yy了bitset,好像有点儿慢。。。注意bitset上的位和int上的位差不多。不过从0位开始。

    代码:

     1 #include<cstdio>
     2 #include<cstdlib>
     3 #include<cmath>
     4 #include<cstring>
     5 #include<algorithm>
     6 #include<iostream>
     7 #include<vector>
     8 #include<map>
     9 #include<set>
    10 #include<queue>
    11 #include<string>
    12 #include<bitset>
    13 #define inf 1000000000
    14 #define maxn 2000+5
    15 #define maxm 100000+5
    16 #define eps 1e-10
    17 #define ll long long
    18 #define pa pair<int,int>
    19 #define for0(i,n) for(int i=0;i<=(n);i++)
    20 #define for1(i,n) for(int i=1;i<=(n);i++)
    21 #define for2(i,x,y) for(int i=(x);i<=(y);i++)
    22 #define for3(i,x,y) for(int i=(x);i>=(y);i--)
    23 #define for4(i,x) for(int i=head[x],y=e[i].go;i;i=e[i].next,y=e[i].go)
    24 #define mod 1000000007
    25 using namespace std;
    26 inline int read()
    27 {
    28     int x=0,f=1;char ch=getchar();
    29     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    30     while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
    31     return x*f;
    32 }
    33 int n,m,tot,b[maxn],ans[maxn];
    34 bitset<1005> a[maxn],c[2];
    35 int main()
    36 {
    37     freopen("input.txt","r",stdin);
    38     freopen("output.txt","w",stdout);
    39     n=read();m=read();
    40     c[0][0]=0;c[1][0]=1;
    41     for1(i,m)
    42     {
    43         for1(j,n+1)
    44         {
    45             char ch=getchar();
    46             while(ch!='0'&&ch!='1')ch=getchar();
    47             a[i]=a[i]<<1^c[(int)(ch-'0')];
    48         }
    49         for3(j,n,1)if(a[i][j]&1)
    50         {
    51             if(b[j])a[i]^=a[b[j]];
    52             else {b[j]=i;tot++;break;}
    53         }
    54         if(tot==n){ans[0]=i;break;}
    55     }
    56     if(tot<n)printf("Cannot Determine
    ");
    57     else
    58     {
    59         printf("%d
    ",ans[0]);
    60         //for1(i,n)cout<<i<<' '<<b[i]<<' '<<a[b[i]]<<endl;
    61         for1(i,n)
    62         {
    63             ans[i]=a[b[i]][0];
    64             for1(j,i-1)if(a[b[i]][j])ans[i]^=ans[j];
    65         }
    66         for3(i,n,1)printf("%s
    ",ans[i]?"?y7M#":"Earth");
    67     }
    68     return 0;
    69 }
    View Code

    1923: [Sdoi2010]外星千足虫

    Time Limit: 10 Sec  Memory Limit: 64 MB
    Submit: 433  Solved: 258
    [Submit][Status]

    Description

    Input

    第一行是两个正整数 N, M。 接下来 M行,按顺序给出 Charles 这M次使用“点足机”的统计结果。每行 包含一个“01”串和一个数字,用一个空格隔开。“01”串按位依次表示每只虫 子是否被放入机器:如果第 i 个字符是“0”则代表编号为 i 的虫子未被放入,“1” 则代表已被放入。后面跟的数字是统计的昆虫足数 mod 2 的结果。 由于 NASA的实验机器精确无误,保证前后数据不会自相矛盾。即给定数据 一定有解。

    Output

    在给定数据存在唯一解时有 N+1行,第一行输出一个不 超过M的正整数K,表明在第K 次统计结束后就可以确定唯一解;接下来 N 行 依次回答每只千足虫的身份,若是奇数条足则输出“?y7M#”(火星文),偶数 条足输出“Earth”。如果输入数据存在多解,输出“Cannot Determine”。 所有输出均不含引号,输出时请注意大小写。

    Sample Input

    3 5
    011 1
    110 1
    101 0
    111 1
    010 1

    Sample Output

    4
    Earth
    ?y7M#
    Earth

    HINT

    对于 20%的数据,满足 N=M≤20; 
    对于 40%的数据,满足 N=M≤500; 
    对于 70%的数据,满足 N≤500,M≤1,000; 
    对于 100%的数据,满足 N≤1,000,M≤2,000。 

    ==========================================================
    请不要提交!

    Source

  • 相关阅读:
    POJ 1651:Multiplication Puzzle(区间DP)
    POJ 2955:Brackets(区间DP)
    LightOJ 1422:Halloween Costumes(区间DP入门)
    Gym 101257G:24(尺取)
    Codeforces 777D:Cloud of Hashtags(水题)
    Gym 101257B:2Trees(DFS+思维)
    Codeforces 777C:Alyona and Spreadsheet(思维)
    Codeforces 776C:Molly's Chemicals(思维)
    HDU-3440 House Man
    BZOJ-1202 狡猾的商人
  • 原文地址:https://www.cnblogs.com/zyfzyf/p/4232246.html
Copyright © 2020-2023  润新知