向量!

· · 算法·理论

概念

维度

一组相互独立的属性的数量

将所有维度的值均为0的点称为原点,用O表示。

即\overrightarrow{𝑂𝑄}到\overrightarrow{𝑂𝑃}的投影长度与\overrightarrow{𝑂𝑃}的长度相乘。

点乘的结果被称为点积,又被称为内积,是标量。 令\overrightarrow{𝑂𝑃}  = (x1, y1), \overrightarrow{𝑂𝑄} = (x2, y2),则\overrightarrow{𝑂𝑃} • \overrightarrow{𝑂𝑄} = x_1 \times x_2 + y_1 \times y_2。

点乘可以判断向量的前后关系

即\overrightarrow{𝑂𝑄}到\overrightarrow{𝑂𝑃}的距离与\overrightarrow{𝑂𝑃}的长度相乘。

叉乘的结果被称为叉积,又被称为外积,是向量。

令\overrightarrow{𝑂𝑃} = (x1, y1), \overrightarrow{𝑂𝑄} = (x2, y2),则|\overrightarrow{𝑂𝑃} \times \overrightarrow{𝑂𝑄}| = x1 \times y2 - y1 \times x2。

叉乘不满足交换律,交换后结果方向相反。

\overrightarrow{𝑂𝑃} \times \overrightarrow{𝑂𝑄} = -(\overrightarrow{𝑂𝑄} \times \overrightarrow{𝑂𝑃}) = \overrightarrow{𝑂𝑄} \times -\overrightarrow{𝑂𝑃}

交换位置或者取反某个向量都会导致叉乘结果反向。

叉乘可以判断向量的左右关系

起点在所有点的左下方,不可能通过左拐绕过, 所以走的每一段路径都要保证剩下点全在左边。

从起点开始,每次走向最靠右的点就能满足要求。

/*

writer:  Luna_Frome_now_pointarry
Problem: 不知名屑题
Knowledge: 垃圾算法
anse: O(过不了)
PS:Hhy don't have dick
*/
/*
Note:

*/
#include<bits/stdc++.h>
#define ll long long
#define Code using
#define by namespace
#define cmy std
#define un unsigned
#define problem signed
#define T1 main
#define PII pair<int, int>
#define fi firnow_point
#define se second
#define un_m unorderd_map
#define un_s unorderd_set
Code by cmy;
const int N = 1005;
const int M = 100005;
const int INF = 1e9;
const int mod = 998244353;
using point = struct ___{int x, y;};
point a[N];
int vis[N], n;
int get(point x, point y){
    return x.x * y.y - y.x * x.y;
}
point get_dis(int x, int y){
    return {a[x].x - a[y].x, a[x].y - a[y].y};
}
void work(){
    //please write your code here
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i].x >> a[i].y;
    }
    int now_point, minn = INF;
    for(int i = 1; i <= n; i++){
        if(a[i].y < minn){
            minn = a[i].y;
            now_point = i;
        }
    }
    cout << n << " " << now_point << " ";
    vis[now_point] = 1;
    for(int ans = 1; ans < n; ans++){
        int now = -1;
        for(int i = 1; i <= n; i++){
            if(vis[i]) continue;
            if(now == -1) now = i;
            point dis_i = get_dis(i, now_point);
            point dis_now = get_dis(now, now_point);
            int c = get(dis_i, dis_now);
            if(c > 0){
                now = i;
            }
            if(c == 0 && abs(dis_i.x) <= abs(dis_now.x) && abs(dis_i.y) <= abs(dis_now.y)){
                now = i;
            }
        }
        vis[now] = 1;
        cout << now << " ";
        now_point = now;
    }
}
problem T1(){
//  freopen(".in","r",stdin);
//  freopen(".out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1; while(t--){work();}
    return 0;
}

独眼兔-时空复杂度

时间复杂度为O(n^2)

空间复杂度为O(n)