[bzoj1923][高斯消元]外星千足虫
2018-03-01 07:14
323 查看
1923: [Sdoi2010]外星千足虫
Time Limit: 10 Sec Memory Limit: 64 MB
Submit: 1322 Solved: 849
[Submit][Status][Discuss]
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
第一轮Day1
设虫子足数为x x<=1;
那么题目就相当于给出了a[1]*x1+a[2]*x2+….+a
*xn=0/1这种方程,那么显然这种方程就是异或方程的形式,题目要求最少要用多少个异或方程,这个消的时候取max就行了,自由元的时候就是Cannot Determine.
但是n^3肯定是过不了这题的(但是我在bzoj上过了)。所以用bitset优化一下。
n^3
bitset
n^3/32
Time Limit: 10 Sec Memory Limit: 64 MB
Submit: 1322 Solved: 849
[Submit][Status][Discuss]
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
第一轮Day1
sol:
显然只要知道足数的奇偶性,也就是%2后的结果。设虫子足数为x x<=1;
那么题目就相当于给出了a[1]*x1+a[2]*x2+….+a
*xn=0/1这种方程,那么显然这种方程就是异或方程的形式,题目要求最少要用多少个异或方程,这个消的时候取max就行了,自由元的时候就是Cannot Determine.
但是n^3肯定是过不了这题的(但是我在bzoj上过了)。所以用bitset优化一下。
n^3
#include<iostream> #include<algorithm> #include<string> #include<cstring> #include<cstdio> #include<cstdlib> #include<cmath> using namespace std; typedef long long ll; typedef double s64; int n,m; inline int read() { char c; int res,flag=0; while((c=getchar())>'9'||c<'0') if(c=='-')flag=1; res=c-'0'; while((c=getchar())>='0'&&c<='9') res=(res<<3)+(res<<1)+c-'0'; return flag?-res:res; } const int N=2100; int c ,ans; inline void debug() { for(int i=1;i<=n;++i) {for(int j=1;j<=m;++j) printf("%d ",c[i][j]); printf("\n"); } printf("\n"); } inline void guass() { for(int i=1;i<m;++i) { int row; for(row=i;row<=n;++row) if(c[row][i]) break; if(row>n) { ans=-1; return; } ans=max(ans,row); if(row!=i) for(int j=1;j<=m;++j) swap(c[row][j],c[i][j]); for(int j=1;j<=n;++j) if(i!=j&&c[j][i]) for(int k=1;k<=m;++k) c[j][k]^=c[i][k]; // debug(); } } char sr ; int main() { // freopen("1923.in","r",stdin); // freopen(".out","w",stdout); m=read(); n=read(); for(int i=1;i<=n;++i) { scanf("%s",sr+1); for(int j=1;j<=m;++j) c[i][j]=sr[j]-'0'; c[i][m+1]=read(); } ++m; guass(); if(ans==-1) printf("Cannot Determine"); else { printf("%d\n",ans); for(int i=1;i<m;++i) { if(c[i][m]==1) printf("?y7M#\n"); else printf("Earth\n"); } } }
bitset
n^3/32
#include<iostream> #include<algorithm> #include<string> #include<cstring> #include<cstdio> #include<cstdlib> #include<cmath> #include<bitset> using namespace std; typedef long long ll; typedef double s64; int n,m; inline int read() { char c; int res,flag=0; while((c=getchar())>'9'||c<'0') if(c=='-')flag=1; res=c-'0'; while((c=getchar())>='0'&&c<='9') res=(res<<3)+(res<<1)+c-'0'; return flag?-res:res; } const int N=2100; bitset<N> c ; int ans; inline void guass() { for(int i=1;i<m;++i) { int row; for(row=i;row<=n;++row) if(c[row][i]) break; if(row>n) { ans=-1; return; } ans=max(ans,row); if(row!=i) swap(c[row],c[i]); for(int j=1;j<=n;++j) if(i!=j&&c[j][i]) c[j]^=c[i]; } } char sr ; int main() { // freopen("1923.in","r",stdin); // freopen(".out","w",stdout); m=read(); n=read(); for(int i=1;i<=n;++i) { scanf("%s",sr+1); for(int j=1;j<=m;++j) c[i][j]=sr[j]-'0'; c[i][m+1]=read(); } ++m; guass(); if(ans==-1) printf("Cannot Determine"); else { printf("%d\n",ans); for(int i=1;i<m;++i) { if(c[i][m]==1) printf("?y7M#\n"); else printf("Earth\n"); } } }
相关文章推荐
- bzoj 1923 [Sdoi2010]外星千足虫(高斯消元+bitset)
- Bzoj 1923: [Sdoi2010]外星千足虫(bitset优化高斯消元)
- 【BZOJ-1923】外星千足虫 高斯消元 + xor方程组
- [BZOJ1923][SDOI2010]外星千足虫(高斯消元---异或方程组)
- 【BZOJ 1923】1923: [Sdoi2010]外星千足虫 (高斯消元异或 | BITSET用法)
- bzoj 1923: [Sdoi2010]外星千足虫 高斯消元
- bzoj 1923: [Sdoi2010]外星千足虫 (高斯消元)
- 【BZOJ1923】外星千足虫,高斯消元解xor方程组
- 【bzoj1923】[Sdoi2010]外星千足虫 高斯消元解xor方程组
- BZOJ 1923 外星千足虫(高斯消元)
- 【BZOJ 1923】 [Sdoi2010]外星千足虫 高斯消元
- [BZOJ1923][Sdoi2010]外星千足虫(高斯消元)
- bzoj 1923: [Sdoi2010]外星千足虫【高斯消元】
- BZOJ 1923: [Sdoi2010]外星千足虫 [高斯消元XOR]
- BZOJ1923 [Sdoi2010]外星千足虫 【高斯消元】
- bzoj1923 [Sdoi2010]外星千足虫 压位+高斯消元
- BZOJ_1923_[Sdoi2010]外星千足虫_高斯消元+bitset
- 【BZOJ1923】[Sdoi2010]外星千足虫 高斯消元
- bzoj1923 [Sdoi2010]外星千足虫 高斯消元
- 【高斯消元】【异或方程组】【bitset】bzoj1923 [Sdoi2010]外星千足虫