高斯消元,以前从来没写过,今天的模拟比赛里面,添琦给了我一个模板!

虽然是个裸的,但是因为从来没写过,一个小细节竟然搞了我几个小时;

终于最后在小珺同志的帮助下成功a掉了,太开心了!

存一下,作为模板!

代码:

 #include<cstdio>
#define maxn 10
#include<cstring>
#include<cmath>
#include<algorithm>
#define eps 0.00001
using namespace std;
double matrix[maxn][maxn+];
double ans[maxn];
double a[maxn]; void exchange_col(int p1,int p2,int n)
{
double t;
int i;
for(int i=; i<=n; i++)
t=matrix[p1][i],matrix[p1][i]=matrix[p2][i],matrix[p2][i]=t;
} bool gauss(int n)
{
int i,j,k;
int p;
double r;
for(i=; i<n-; i++)
{
p=i;
for(j=i+; j<n; j++)
if(abs(matrix[j][i])>abs(matrix[p][i]))
p=j;
if(p!=i)
exchange_col(i,p,n);
if(matrix[i][i]==) return false;
for(j=i+; j<n; j++)
{
r=matrix[j][i]/matrix[i][i];
for(k=i; k<=n; k++)
matrix[j][k]-=r*matrix[i][k];
}
}
for(i=n-; i>=; i--)
{
ans[i]=matrix[i][n];
for(j=n-; j>i; j--)
ans[i]-=matrix[i][j]*ans[j];
if(abs(matrix[i][i])<eps)return false;
ans[i]/=matrix[i][i];
}
return true;
} int main()
{
int d;
while(scanf("%d",&d)&&d)
{
memset(matrix,,sizeof matrix);
for(int i=; i<=d+; i++)
scanf("%lf",&a[i]);
for(int k=; k<=d+; k++)
{
int cnt=;
for(int j=; j<=d+; j++)
{
if(k==j) continue;
matrix[cnt][d+]=a[j];
for(int i=; i<=d; i++)
{
if(i==) matrix[cnt][i]=;
else matrix[cnt][i]=matrix[cnt][i-]*j;
}
cnt++;
}
if(!gauss(d+))
{
printf("%d\n",k);
break;
}
}
}
return ;
}

uvalive 6185的更多相关文章

  1. UVALive - 6185 Find the Outlier暴力填表+高斯消元+卡eps

    https://cn.vjudge.net/problem/UVALive-6185 我真的是服了orz eps 1e5,1e6过不了 开1e2 1e1都能过 题意:给你一个d阶多项式f的f(0),f ...

  2. UVALive - 4108 SKYLINE[线段树]

    UVALive - 4108 SKYLINE Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug ...

  3. UVALive - 3942 Remember the Word[树状数组]

    UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...

  4. UVALive - 3942 Remember the Word[Trie DP]

    UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...

  5. 思维 UVALive 3708 Graveyard

    题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...

  6. UVALive 6145 Version Controlled IDE(可持久化treap、rope)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  7. UVALive 6508 Permutation Graphs

    Permutation Graphs Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit ...

  8. UVALive 6500 Boxes

    Boxes Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Pract ...

  9. UVALive 6948 Jokewithpermutation dfs

    题目链接:UVALive 6948  Jokewithpermutation 题意:给一串数字序列,没有空格,拆成从1到N的连续数列. dfs. 可以计算出N的值,也可以直接检验当前数组是否合法. # ...

随机推荐

  1. Android(java)学习笔记150:为什么局部内部类只能访问外部类中的 final型的常量

    为什么匿名内部类参数必须为final类型: 1)  从程序设计语言的理论上:局部内部类(即:定义在方法中的内部类),由于本身就是在方法内部(可出现在形式参数定义处或者方法体处),因而访问方法中的局部变 ...

  2. 一行 Python 代码搞定一棵树

    使用 Python 内建的 defaultdict 方法可以轻松定义一个树的数据结构. 简单的说树也可以是一个字典数据结构           Python   1 def tree(): retur ...

  3. magento中的一些技巧

    1.加载某个attribute: $attributeCode=Mage::getModel('catalog/resource_eav_attribute')                     ...

  4. HTML 学习整理

    一.名词解释 一.  HTML : Hypertext Markup Language  超文本标记语言 二.  CSS : Cascading Style Sheet  层叠样式表 三.  浏览器: ...

  5. ADO.Net知识总结

    (一)基础知识 ADO.NET: .NET中用来向数据库提交执行SQL语句的一堆类 本机访问直接"Windows验证",但是一般项目中都是单独的数据库服务器,程序在另外一台电脑上连 ...

  6. Android 在子线程中更新UI

    今天在做练习时,在一个新开启的线程中调用“Toast.makeText(MainActivity.this, "登陆成功",Toast.LENGTH_SHORT).show();” ...

  7. store procedure 翻页

    store procedure 翻页例子 .turn page CREATE PROCEDURE pageTest --用于翻页的测试 --需要把排序字段放在第一列 ( )=null, --当前页面里 ...

  8. 学习笔记_过滤器概述(过滤器JavaWeb三大组件之一)

    过滤器Filter Filter和Lister是Servlet规范里的两个高级特性.不同于Servlet,它们不用于处理客户端请求,只用于对request.response进行修改或者对context ...

  9. 使用 Virtual Box 安装 android x86

    1.安装 跟随别人的教程:http://www.maketecheasier.com/run-android-4-3-in-virtualbox/ 2.问题 安装过程出现以下问题:Kernel pan ...

  10. Xcode 5.1 更新后插件不能用

    打开目录 ~/Library/Application Support/Developer/Shared/Xcode/Plug-ins 右击选择"显示包内容" 找到"Inf ...