POJ 3185 The Water Bowls(高斯消元)
来源:互联网 发布:php fpm mysql长连接 编辑:程序博客网 时间:2024/05/17 03:24
题目地址:POJ 3185
醉了。,。高斯消元这种题样例都不过的时候怎么调试好。。。干瞪着看了半天代码终于发现是一个符合写错了。。
这题同样是高斯消元+自由元枚举。没什么好说的。
代码如下:
#include <iostream>#include <string.h>#include <math.h>#include <queue>#include <algorithm>#include <stdlib.h>#include <map>#include <set>#include <stdio.h>using namespace std;#define LL __int64#define pi acos(-1.0)const int mod=1e9+7;const int INF=0x3f3f3f3f;const double eqs=1e-6;int b[31], a[30][30];int free_num, free_x[30], state[30];int gauss(){ int i, j, k, h, max_r, tmp; free_num=0; for(i=0,j=0;i<20&&j<20;i++,j++){ max_r=i; for(k=i+1;k<20;k++){ if(a[k][j]>a[max_r][j]) max_r=k; } if(max_r!=i){ for(k=j;k<=20;k++){ swap(a[i][k],a[max_r][k]); } } if(!a[i][j]){ free_x[free_num++]=j; i--; continue ; } for(k=i+1;k<20;k++){ if(a[k][j]==0) continue ; for(h=j;h<21;h++){ a[k][h]^=a[i][h]; } } } //printf("%d\n",free_num); tmp=i; for(i=tmp;i<20;i++){ if(a[i][20]) return INF; } int tot=1<<free_num, cnt, ans=INF; //printf("%d\n",tot); for(i=0;i<tot;i++){ cnt=0; for(j=0;j<free_num;j++){ if(i&(1<<j)){ state[free_x[j]]=1; cnt++; } else{ state[free_x[j]]=0; } } for(j=tmp-1;j>=0;j--){ int t=0; while(a[j][t]==0) t++; state[t]=a[j][20]; for(k=t+1;k<20;k++){ if(a[j][k]) state[t]^=state[k]; } cnt+=state[t]; } //printf("--%d\n",cnt); ans=min(ans,cnt); } return ans;}int main(){ int i; for(i=0;i<20;i++){ scanf("%d",&b[i]); } memset(a,0,sizeof(a)); for(i=0;i<20;i++){ a[i][i]=1; if(i) a[i][i-1]=1; if(i!=19) a[i][i+1]=1; a[i][20]=b[i]; } printf("%d\n",gauss()); return 0;}
1 0
- poj 3185 The Water Bowls 高斯消元
- poj -- 3185 The Water Bowls(高斯消元)
- poj 3185 The Water Bowls(高斯消元)
- poj 3185 The Water Bowls(高斯消元)
- POJ 3185 The Water Bowls(高斯消元)
- poj 3185 The Water Bowls (高斯消元)
- POJ 3185 The Water Bowls(高斯消元)
- POJ 3185 The Water Bowls (高斯消元)
- poj 3185 The Water Bowls(高斯消元)
- poj 3185 The Water Bowls
- POJ 3185 (The Water Bowls)
- POJ 3185 The Water Bowls
- poj 3185 The Water Bowls
- POJ 3185 The Water Bowls
- POJ 3185 The Water Bowls
- POJ-3185-The Water Bowls
- poj-3185 The Water Bowls
- The Water Bowls POJ 3185
- LINUX/UNIX 命令
- android 取消点击GridView的时候出现的那个黄色背景
- jQuery $.ajax() $.get() $.post() $.getJSON()
- 队列浅析[解密QQ号]
- 2015年丰田RAV4评析
- POJ 3185 The Water Bowls(高斯消元)
- 记录一个CI、jquery、ajax(post)的计算器小例子
- 微信公众平台PHP开发 流程经验_1
- 如何马上提高你的邮件送达率?
- iOS动画进阶(二)寄宿图
- Hive数据倾斜
- 为何放弃IE6
- 【ArcGIS平台系列】Server,新一代Web GIS平台的重要支撑
- redis源码学习(客户端)