hdu 6465 线性变换高斯消元
2024-09-06 08:40:29
http://acm.hdu.edu.cn/showproblem.php?pid=6465
题意
给你三个点,再给你经过线性变换后的三个点,然后q次询问,给你一个点,需要你输出线性变换后的点
题解
- 线性变换:
- \(a_1x+b_1y+c_1=X\)
- \(a_2x+b_2y+c_2=Y\)
- 构造高斯消元矩阵,Y同理
\[ \left[
\begin{matrix}
1 & x_1 & y_1 \\
1 & x_2 & y_2 \\
1 & x_3 & y_3
\end{matrix}
\right]
\left[
\begin{matrix}
a_1 \\
b_1 \\
c_1
\end{matrix}
\right]=\left[
\begin{matrix}
X_1 \\
X_2 \\
X_3
\end{matrix}
\right]
\]
\begin{matrix}
1 & x_1 & y_1 \\
1 & x_2 & y_2 \\
1 & x_3 & y_3
\end{matrix}
\right]
\left[
\begin{matrix}
a_1 \\
b_1 \\
c_1
\end{matrix}
\right]=\left[
\begin{matrix}
X_1 \\
X_2 \\
X_3
\end{matrix}
\right]
\]
代码
#include<bits/stdc++.h>
using namespace std;
void gao(double c[5][5]){
for(int i=1;i<=3;i++){
for(int j=i+1;j<=3;j++){
double rate=c[j][i]*1.0/c[i][i];
for(int k=i;k<=4;k++){
c[j][k]-=c[i][k]*rate;
}
}
}
for(int i=3;i>=1;i--){
for(int j=i-1;j>=1;j--){
double rate=c[j][i]*1.0/c[i][i];
c[j][4]-=c[i][4]*rate;
}
c[i][i]=c[i][4]/c[i][i];
}
}
double a[5][5],b[5][5];
int q,T;
double x,y,X,Y;
int main(){
cin>>T;
while(T--){
scanf("%lf%lf%lf%lf%lf%lf",&a[1][2],&a[1][3],&a[2][2],&a[2][3],&a[3][2],&a[3][3]);
a[1][1]=a[2][1]=a[3][1]=1;
for(int i=1;i<=3;i++)for(int j=1;j<=3;j++)b[i][j]=a[i][j];
scanf("%lf%lf%lf%lf%lf%lf",&a[1][4],&b[1][4],&a[2][4],&b[2][4],&a[3][4],&b[3][4]);
gao(a);gao(b);
scanf("%d",&q);
while(q--){
scanf("%lf%lf",&x,&y);
X=1*a[1][1]+x*a[2][2]+y*a[3][3];
Y=1*b[1][1]+x*b[2][2]+y*b[3][3];
printf("%.2f %.2f\n",X,Y);
}
}
}
最新文章
- 深入理解 JavaScript,以及 Linux 下的开发调试工具
- JAVA 堆栈知识和Volatile关键字
- jquery mobile的事件
- Azure IOT (EventHub + Stream Analytics + Table Storage)的使用
- C/C++ 动态存储分配
- C#脚本引擎 CS-Script 之(一)——初识
- Memcached 缓存个体,对象,泛型,表
- poj 1236 Network of Schools【强连通求孤立强连通分支个数&;&;最少加多少条边使其成为强连通图】
- CopyU!v2.2 增加对设备信息的识别
- Python 列表生成式、生成器、迭代器
- Delphi中MethodAddress汇编代码的解析
- hibernate sql查询转换成VO返回list
- sql语句联表更新(从一个数据库中的一张表更新到另一个数据库的另一张表)
- solr之环境配置二
- composer安装。
- (PMP)解题技巧和典型题目分析(0903-2班)
- 一、Ansible安装
- CSS3透明背景+渐变样式
- rpcbind.service启动失败
- css控制固定表头,兼容行列合并
热门文章
- As Simple as One and Two
- Please make sure you have the correct access rights and the repository exists.
- Paper | PyTorch: An Imperative Style, High-Performance Deep Learning Library
- 实时聊天-websocket与ajax的区别于联系
- 《细说PHP》第四版 样章 第23章 自定义PHP接口规范 11
- 【shell脚本语法】判断、流程控制语句
- Tkinter最佳实践(半小时)
- plsql基础练习题
- Installation request for topthink/think-captcha ^3.0 ->; satisfiable by topthink/think-captcha[v3.0.0].
- EF-入门操作