HDU 3365 New Ground (计算几何)
题意:给定点A[0~n-1]和B[0],B[1],A[0]、A[1]映射到B[0]、B[1],求出其余点的映射B[2]~B[n-1]。
析:运用复数类,关键是用模板复数类,一直编译不过,我明明能编译过,交上就不过,只能写一个复数了。。。
代码如下:
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
using namespace std ;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f3f;
const int maxn = 10000 + 5;
template<class T>
class Complex
{
public:
Complex( ){real=0;imag=0;}
Complex(T r,T i){real=r;imag=i;}
Complex complex_add(Complex &c2);
Complex complex_minus(Complex &c2);
Complex complex_multiply(Complex &c2);
Complex complex_divide(Complex &c2);
T real1();
T imag1(); public:
friend istream &operator >>(istream &is, Complex<T> &p){
cin >> p.real >> p.imag;
return is;
} private:
T real;
T imag;
}; template<class T>
Complex<T> Complex<T>::complex_add(Complex<T> &c2)
{
Complex<T> c;
c.real=real+c2.real;
c.imag=imag+c2.imag;
return c;
} template <class T>
Complex<T> Complex<T>::complex_minus(Complex <T> &c2)
{
Complex <T> c;
c.real=real-c2.real;
c.imag=imag-c2.imag;
return c;
} template <class T>
Complex<T> Complex<T>::complex_multiply(Complex <T> &c2)
{
Complex <T> c;
c.real=real*c2.real-imag*c2.imag;
c.imag=imag*c2.real+real*c2.imag;
return c;
} template <class T>
Complex<T> Complex<T>::complex_divide(Complex <T> &c2)
{
Complex <T> c;
T d=c2.real*c2.real+c2.imag*c2.imag;
c.real=(real*c2.real+imag*c2.imag)/d;
c.imag=(imag*c2.real-real*c2.imag)/d;
return c;
} template <class T>
T Complex<T>::real1(){
return real;
} template <class T>
T Complex<T>::imag1(){
return imag;
} Complex<double> a[maxn], b[2], ans; int main(){
int T, n; cin >> T;
for(int kase = 1; kase <= T; ++kase){
scanf("%d", &n);
double x, y;
for(int i = 0; i < n; ++i){
cin >> a[i]; }
for(int i = 0; i < 2; ++i){
cin >> b[i];
} Complex<double> tmp = (b[1].complex_minus(b[0]));
Complex<double> tmp1 = (a[1].complex_minus(a[0]));
tmp = tmp.complex_divide(tmp1);
printf("Case %d:\n", kase);
for(int i = 0; i < n; ++i){
ans = (a[i].complex_minus(a[0]));
ans = ans.complex_multiply(tmp);
ans = ans.complex_add(b[0]);
printf("%.2lf %.2lf\n", ans.real1(), ans.imag1());
}
}
return 0;
}
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <complex>
using namespace std ;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f3f;
const int maxn = 10000 + 5;
complex<double> a[maxn], b[2], ans; int main(){
int T, n; cin >> T;
for(int kase = 1; kase <= T; ++kase){
scanf("%d", &n);
for(int i = 0; i < n; ++i)
scanf("%lf %lf", &a[i].real(), &a[i].imag());
scanf("%lf %lf %lf %lf", &b[0].real(), &b[0].imag(), &b[1].real(), &b[1].imag());
complex<double> tmp = (b[1]-b[0])/(a[1]-a[0]);
printf("Case %d:\n", kase);
for(int i = 0; i < n; ++i){
ans = (a[i]-a[0]) * tmp + b[0];
printf("%.2lf %.2lf\n", ans.real(), ans.imag());
}
}
return 0;
}
HDU 3365 New Ground (计算几何)的更多相关文章
- HDU 5130 Signal Interference(计算几何 + 模板)
HDU 5130 Signal Interference(计算几何 + 模板) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5130 Descripti ...
- HDU 4063 Aircraft(计算几何)(The 36th ACM/ICPC Asia Regional Fuzhou Site —— Online Contest)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4063 Description You are playing a flying game. In th ...
- hdu 1348:Wall(计算几何,求凸包周长)
Wall Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- hdu 1174:爆头(计算几何,三维叉积求点到线的距离)
爆头 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...
- HDU 5979 Convex【计算几何】 (2016ACM/ICPC亚洲区大连站)
Convex Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- hdu 4631Sad Love Story<计算几何>
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4631 题意:依次给你n个点,每次求出当前点中的最近点对,输出所有最近点对的和: 思路:按照x排序,然后用s ...
- HDU 4606 Occupy Cities (计算几何+最短路+最小路径覆盖)
转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove 题目:给出n个城市需要去占领,有m条线段是障碍物, ...
- 2017 Multi-University Training Contest - Team 9 1003&&HDU 6163 CSGO【计算几何】
CSGO Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- HDU 5839 Special Tetrahedron 计算几何
Special Tetrahedron 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5839 Description Given n points ...
随机推荐
- Flyway客户端使用
一.flyway介绍 Flyway是一款开源的数据库版本管理工具,它更倾向于规约优于配置的方式.Flyway可以独立于应用实现管理并跟踪数据库变更,支持数据库版本自动升级,并且有一套默认的规约,不需要 ...
- 关于 SMT 一个重要提示
关于 SMT 一个重要提示 温度曲线是对应的具体的PCB的最差焊盘位置处的所用焊锡膏对应的熔化曲线.从这种角度来观察,我想你会明白我的意思的. https://www.amobbs.com/forum ...
- 1021. Deepest Root (25)——DFS+并查集
http://pat.zju.edu.cn/contests/pat-a-practise/1021 无环连通图也可以视为一棵树,选定图中任意一点作为根,如果这时候整个树的深度最大,则称其为 deep ...
- sublime 工具
http://blog.csdn.net/admin_yi/article/details/53608965
- (转)Apache转发配置
本文转载自:http://blog.csdn.net/leshjmail/article/details/6163581 安装文件 1.httpd-2.2.15-win32-x86-no_ssl.ms ...
- 单片机keil C中的data、bdata、idata、xdata、hdata、pdata、code解释
从数据存储类型来说,8051系列有片内.片外程序存储器,片内.片外数据存储器,片内程序存储器还分直接寻址区和间接寻址类型,分别对应code.data.xdata.idata以及根据51系列特点而设定的 ...
- Centos 6.* / 7.*下通过yum安装php7
查看 centos 版本 # cat /etc/centos-release 删除之前的 php 版本 # yum remove php* php-common rpm 安装 Php7 相应的 yum ...
- 微信小程序简单步骤记录
- 使用Selenium登录新浪微博
为了总结一下Selenium的用法,具体用了这个例子来说明一下. Selenium简单来说,就是通过程序驱动一个浏览器,并且可以通过程序来帮你做一些事情,例如点击.填表呀之类的. 换句话说,你在浏览器 ...
- Strom简单介绍
1.离线计算是什么? 离线计算:批量获取数据.批量传输数据.周期性批量计算数据.数据展示 代表技术:Sqoop批量导入数据.HDFS批量存储数据.MapReduce批量计算数据.Hive批量计算数据. ...