HDU 3359高斯消元
来源:互联网 发布:淘宝网开通淘金币活动 编辑:程序博客网 时间:2024/06/05 08:13
HDU 3359 http://acm.hdu.edu.cn/showproblem.php?pid=3359
高斯消元基础题 模板题吧
参考黑书上的代码写的
#include<stdio.h>#include<iostream>#include<string>#include<stdlib.h>#include<string.h>#include<math.h>using namespace std;typedef double Matrix[105][105];int mht(int i,int j,int m,int n){ return abs(i-m)+abs(j-n); }void gauss(Matrix A ,int n){ int i,j,k,r; for(i = 0; i < n; i++){ r = i; for(j = i+1; j < n; j++){ if( fabs(A[j][i]) > fabs(A[r][i]) ) r = j; } if(r != i) for(j = 0; j <= n; j++) swap(A[r][j],A[i][j]); for(k = i+1; k < n; k++){ double f = A[k][i] / A[i][i]; for(j = i; j <= n; j++) A[k][j] -= f * A[i][j]; } /* for(j = n; j >= i; j--){ for(k = i+1; k < n; ++k) A[k][j] -= A[k][i]/A[i][i] * A[i][j]; } */ } for(i = n-1; i >= 0; --i ){ for(j = i+1; j < n; ++j) A[i][n] -= A[j][n] * A[i][j]; A[i][n] /= A[i][i]; } }int main(){// freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); Matrix g; double map[12][12]; int pos[120][120]; int r,c,d; bool is_first=true; while(scanf("%d%d%d",&c,&r,&d),r||c||d){ if(!is_first) printf("\n"); is_first=false; int i,j; int cnt=0; for(i=0;i<r;i++){ for(j=0;j<c;j++){ pos[i][j]=cnt++; scanf("%lf",&map[i][j]); } } memset(g,0,sizeof(g)); int m,n; for(i=0;i<r;i++){ for(j=0;j<c;j++){ for(m=0;m<r;m++){ for(n=0;n<c;n++){ if( mht(i,j,m,n)<=d ){ g[ pos[i][j] ][ pos[m][n] ]=1; g[ pos[i][j] ][cnt] += map[i][j]; } } } } } gauss(g,cnt); for(i=0;i<cnt;i++){ printf("%8.2lf",g[i][cnt]); if( (i+1)%c == 0 ) putchar(10); } } return 0;}
0 0
- HDU 3359高斯消元
- hdu 3359(高斯消元)
- 【HDU】3359
- hdu 3359 高斯消元法
- HDU 3359 (浮点数高斯消元)
- 【高斯消元】[HDU 3359][POJ3999][UVALive4741]Kind of a Blur
- hdu 3359 Kind of a Blur(高斯消元)
- hdu 4326 高斯消元
- HDU 4870 Rating(高斯消元)
- HDU-#3364 Lanterns(高斯消元)
- HDU 3949 XOR 高斯消元
- hdu 3915 高斯消元
- 高斯消元HDU-3364 Lanterns
- HDU 3364 (高斯消元)
- hdu 5088(高斯消元)
- HDU 1487高斯消元
- HDU 5755 (高斯消元)
- HDU 5755 高斯消元
- [2014年学习计划之RoR系列] 第二步 – 熟悉Ruby语言 (2/n) Blocks and Iterators (代码块和迭代器)
- warning: incompatible implicit declaration of built-in function 'exit'
- 读《重构》,学习Collections.unmodifiableList()用法
- libevent源代码分析--event_dispatch() (一)
- ApplicationContextAware动态获取spring bean
- HDU 3359高斯消元
- WPF画红色波浪线
- DevExpress的DateEdit设置显示日期和时间
- C++编程思想笔记
- jQuery 入门教程(3): Selectors
- javaweb通过bonecp连接池连接数据库
- 查看ubuntu硬件信息命令
- 有偿求助鸡西本地期货指导
- java_集合体系之总体目录——00