【bzoj1923】 Sdoi2010—外星千足虫
http://www.lydsy.com/JudgeOnline/problem.php?id=1923 (题目链接)
题意
按顺序给出m个n元模线性方程,问最少当给出多少个方程时整个方程组有解。
Solution
当所消的当前位为0时在下面的方程里面去找,如果没找到,则无解。
刚开始还想能否在消元之前就判断多余方程,不过看来是不行了。。。。
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | // bzoj1923 #include<algorithm> #include<iostream> #include<cstdlib> #include<cstring> #include<cstdio> #include<cmath> #include<map> #define LL long long #define inf 2147483640 #define Pi acos(-1,0) #define free(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout); using namespace std; const int maxn=2010; int a[maxn][maxn],n,m,ans; char ch[maxn]; void Gauss() { ans=0; for ( int r,i=1;i<=n;i++) { r=i; while (!a[r][i] && r<=m) r++; if (r==m+1) {ans=0; return ;} ans=max(ans,r); if (r!=i) for ( int j=1;j<=n+1;j++) swap(a[i][j],a[r][j]); for ( int j=1;j<=m;j++) if (j!=i && a[j][i]) { for ( int k=i;k<=n+1;k++) a[j][k]^=a[i][k]; } } } int main() { scanf ( "%d%d" ,&n,&m); for ( int x,i=1;i<=m;i++) { scanf ( "%s%d" ,ch,&x); for ( int j=0;j<n;j++) a[i][j+1]=ch[j]- '0' ; a[i][n+1]=x; } Gauss(); if (ans==0) puts ( "Cannot Determine" ); else { printf ( "%d\n" ,ans); for ( int i=1;i<=n;i++) { if (a[i][n+1]) puts ( "?y7M#" ); else puts ( "Earth" ); } } return 0; } |
This passage is made by MashiroSky.
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步