E. Hag's Khashba+计算几何+旋转+重心

E. Hag's Khashba
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Hag is a very talented person. He has always had an artist inside him but his father forced him to study mechanical engineering.

Yesterday he spent all of his time cutting a giant piece of wood trying to make it look like a goose. Anyway, his dad found out that he was doing arts rather than studying mechanics and other boring subjects. He confronted Hag with the fact that he is a spoiled son that does not care about his future, and if he continues to do arts he will cut his 25 Lira monthly allowance.

Hag is trying to prove to his dad that the wooden piece is a project for mechanics subject. He also told his dad that the wooden piece is a strictly convex polygon with n

vertices.

Hag brought two pins and pinned the polygon with them in the 1

-st and 2-nd vertices to the wall. His dad has q

queries to Hag of two types.

  • 1
f t: pull a pin from the vertex f, wait for the wooden polygon to rotate under the gravity force (if it will rotate) and stabilize. And then put the pin in vertex t

. 2 v: answer what are the coordinates of the vertex v
  • .

Please help Hag to answer his father's queries.

You can assume that the wood that forms the polygon has uniform density and the polygon has a positive thickness, same in all points. After every query of the 1-st type Hag's dad tries to move the polygon a bit and watches it stabilize again.

Input

The first line contains two integers n

and q ( 3n10000, 1q200000

) — the number of vertices in the polygon and the number of queries.

The next n

lines describe the wooden polygon, the i-th line contains two integers xi and yi ( |xi|,|yi|108) — the coordinates of the i

-th vertex of the polygon. It is guaranteed that polygon is strictly convex and the vertices are given in the counter-clockwise order and all vertices are distinct.

The next q

lines describe the queries, one per line. Each query starts with its type 1 or 2. Each query of the first type continues with two integers f and t ( 1f,tn) — the vertex the pin is taken from, and the vertex the pin is put to and the polygon finishes rotating. It is guaranteed that the vertex f contains a pin. Each query of the second type continues with a single integer v ( 1vn

) — the vertex the coordinates of which Hag should tell his father.

It is guaranteed that there is at least one query of the second type.

Output

The output should contain the answer to each query of second type — two numbers in a separate line. Your answer is considered correct, if its absolute or relative error does not exceed 104

.

Formally, let your answer be a

, and the jury's answer be b. Your answer is considered correct if |ab|max(1,|b|)104
Examples
Input
Copy
3 4
0 0
2 0
2 2
1 1 2
2 1
2 2
2 3
Output
Copy
3.4142135624 -1.4142135624
2.0000000000 0.0000000000
0.5857864376 -1.4142135624
Input
Copy
3 2
-1 1
0 0
1 1
1 1 2
2 1
Output
Copy
1.0000000000 -1.0000000000
Note

In the first test note the initial and the final state of the wooden polygon.

Red Triangle is the initial state and the green one is the triangle after rotation around (2,0)

.

In the second sample note that the polygon rotates 180

degrees counter-clockwise or clockwise direction (it does not matter), because Hag's father makes sure that the polygon is stable and his son does not trick him.

这个图求重心你是绝对不能用坐标取中的

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define all(a) (a).begin(),(a).end()
#define pll pair<ll,ll>
#define vi vector<int>
#define pb push_back
const int inf=0x3f3f3f3f;
ll rd(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
const int N=1e4+10;
double x[N],y[N],r[N],a[N];
double D;
double sx,sy;
int main(){
#ifdef happy
    freopen("in.txt","r",stdin);
#endif
    int n=rd(),q=rd();
    rep(i,1,n)
    x[i]=rd(),y[i]=rd();
    double sa=0;
    rep(i,2,n-1){
        double px=(x[1]+x[i]+x[i+1])/3.0;
        double py=(y[1]+y[i]+y[i+1])/3.0;
        double a=abs((x[i]-x[1])*(y[i+1]-y[1])-(x[i+1]-x[1])*(y[i]-y[1]));
        sx+=a*px;
        sy+=a*py;
        sa+=a;
    }
    sx/=sa;
    sy/=sa;
    rep(i,1,n){
        r[i]=hypot(x[i]-sx,y[i]-sy);
        a[i]=atan2(y[i]-sy,x[i]-sx);
        while(a[i]<a[i-1])a[i]+=atan(1)*8;
    }
    int p[2]={1,2};
    double px[2]={x[1],x[2]};
    double py[2]={y[1],y[2]};

    while(q--){
        int k=rd();
        if(k==1){
            int i;
            int f=rd(),t=rd();
            if(p[0]==f)i=1,p[0]=t;
            else i=0,p[1]=t;
            sx=px[i];
            sy=py[i]-r[p[i]];
            D=atan(1)*2-a[p[i]];
            px[i^1]=sx+r[t]*cos(D+a[t]);
            py[i^1]=sy+r[t]*sin(D+a[t]);
        }else{
            int i=rd();
            double tx=sx+r[i]*cos(D+a[i]);
            double ty=sy+r[i]*sin(D+a[i]);
            printf("%.12lf %.12lf\n",tx,ty);
        }
    }
}

1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。、资源 5来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。、资 5源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值