uvalive 6185
高斯消元,以前从来没写过,今天的模拟比赛里面,添琦给了我一个模板!
虽然是个裸的,但是因为从来没写过,一个小细节竟然搞了我几个小时;
终于最后在小珺同志的帮助下成功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的更多相关文章
- UVALive - 6185 Find the Outlier暴力填表+高斯消元+卡eps
https://cn.vjudge.net/problem/UVALive-6185 我真的是服了orz eps 1e5,1e6过不了 开1e2 1e1都能过 题意:给你一个d阶多项式f的f(0),f ...
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
- UVALive - 3942 Remember the Word[树状数组]
UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...
- UVALive - 3942 Remember the Word[Trie DP]
UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...
- 思维 UVALive 3708 Graveyard
题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...
- UVALive 6145 Version Controlled IDE(可持久化treap、rope)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- UVALive 6508 Permutation Graphs
Permutation Graphs Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit ...
- UVALive 6500 Boxes
Boxes Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Pract ...
- UVALive 6948 Jokewithpermutation dfs
题目链接:UVALive 6948 Jokewithpermutation 题意:给一串数字序列,没有空格,拆成从1到N的连续数列. dfs. 可以计算出N的值,也可以直接检验当前数组是否合法. # ...
随机推荐
- UITableViewCell的选中时的颜色及tableViewCell的selecte与deselecte
1.系统默认的颜色设置 //无色 cell.selectionStyle = UITableViewCellSelectionStyleNone; //蓝色 cell.selectionStyle = ...
- javascript进击(六)Jquery
引用 jQuery 如需测试 JavaScript 库,您需要在网页中引用它. 为了引用某个库,请使用 <script> 标签,其 src 属性设置为库的 URL: <!DOCTYP ...
- java.util.Stack类简介
Stack是一个后进先出(last in first out,LIFO)的堆栈,在Vector类的基础上扩展5个方法而来 Deque(双端队列)比起Stack具有更好的完整性和一致性,应该被优先使用 ...
- Asp.NET获取文件及其路径
[相对路径] Request.ApplicationPath /src Path.GetDirectoryName(HttpContext.Current.Request.RawUrl ) //s ...
- centos 6.4 安装firefox使用的flashplayer插件
1.centos安装完后居然没flash-plugin,去官网下载居然告诉已经安装了,可是firefox又的确放不出来flash视频. 2.google一下,去官网下载个tar.gz格式文件.把lib ...
- apache2.2 + tomcat6 整合以及集群配置整理
运行环境:apache2.2.X + tomcat6.0.X + window xp 1. 安装Apache,服务启动后在浏览器中输入http://localhost进行测试,如果能看到一个" ...
- swing容器继承重绘问题解决
swing容器继承重绘问题解决 以JPanel为例,继承JPanel,想动态为器更换背景,这就涉及到重绘问题.一下是本人重写代码: package ui; import java.awt.Grap ...
- 一、VSTO概述
一.什么是VSTO? VSTO = Visual Studo Tools for Office,是.net平台下的Office开发技术.相对于传统的VBA(Visual Basic Applicati ...
- 初尝 Perl
本文将阐述以下几方面内容: 1.什么是Perl 2.Perl有什么用 3.Windows 下的Perl环境搭建 4.Perl 版Hello World 5.Perl 语法梗概 6.一些参考资料 什么是 ...
- C++类继承内存布局(二)
转自:http://blog.csdn.net/jiangyi711/article/details/4890889# (二 )成员变量 前面介绍完了类布局,接下来考虑不同的继承方式下,访问成员变量的 ...