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

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

终于最后在小珺同志的帮助下成功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. inux设置普通用户无密码sudo权限

    配置普通用户无密码sudo权限: root用户进入到Linux系统的/etc目录下 cd /etc 将sudoers文件赋予写的权限 chmod u+w /etc/sudoers 编辑sudoers文 ...

  2. Maven 管理项目 jar出现miss

    这个情况出现在包并没有下载下来就断了,这样的情况就从别人机器上copy一份完好的jar直接报错的那个根目录给覆盖就好了.

  3. 20160501--struts2入门2

    一.Action名称的搜索顺序 1.获得请求路径的URI,例如url是:http://server/struts2/path1/path2/path3/test.action   2.首先寻找name ...

  4. MVC小系列(二十二)【MVC的Session超时,导致的跳转问题】

    由于mvc内部跳转机制的问题,它只在当前的action所渲染的view上进行跳转,如果希望在当前页面跳,需要将mvc方法改为js方法: filterContext.Result = new Redir ...

  5. SQL Server自动化运维系列 - 监控磁盘剩余空间及SQL Server错误日志(Power Shell)

    需求描述 在我们的生产环境中,大部分情况下需要有自己的运维体制,包括自己健康状态的检测等.如果发生异常,需要提前预警的,通知形式一般为发邮件告知. 在所有的自检流程中最基础的一个就是磁盘剩余空间检测. ...

  6. thinkphp之wampserver安装

    1.如何修改www目录 打开httpd.conf(wamp\bin\apache\Apache2.4.4\conf): 把DocumentRoot "c:/wamp/www" 修改 ...

  7. JDBC对sql server的操作

    1.过程: 1>注册驱动器类:Class.forName()       2>连接数据库:             String url = "jdbc:sqlserver:// ...

  8. swift入门-day02

    1.函数 2.闭包 3.构造函数基础 4.重载构造函数 5.KVC构造函数 6.遍历构造函数 7.懒加载 8.只读属性 1.函数 掌握函数的定义 掌握外部参数的用处 掌握无返回类型的三种函数定义方式 ...

  9. swift-01-利用元组判断字符串出现次数

    //问题的提出:有一个字符串 array = ["1","2","4","4","2"," ...

  10. LA 3708 Graveyard(推理 参考系 中位数)

    Graveyard Programming contests became so popular in the year 2397 that the governor of New Earck -- ...