CCF CSP-Problemlösung: Koordinatentransformation (Teil 2) (202309-2)

Links und Ideen

ABl.-Link:Portal

Für Koordinaten im flachen kartesischen Koordinatensystem ( x , y ) (x,y) (x,y),definiert als die folgenden 2 Arten von Operationen:

  1. 拉伸 k k k mal: horizontale Sitzposition x x x变为 k x kx kx, 纵弐标 y y y 变为 k y ky ky
  2. Drehen θ \theta θ :Shoza 标 ( x , y ) (x,y) (x,y) Ursprung ( 0 , 0 ) (0,0) (0,0) Umgekehrte Zeitrotation θ \theta θ 弧度( 0 ≤ θ < 2 π 0 \le \theta < 2 \pi 0ich<2π). Leicht verständliche horizontale Position x cos ⁡ θ − y sin ⁡ θ x \cos \theta - y \sin \theta XcosichUndSündeθ,definition x sin ⁡ θ + y cos ⁡ θ x \sin \theta + y\cos \theta a>XSündeich+Undcosθ

Diese Frage erfordert die Ebenenkoordinaten ( x , y ) (x, y) (x,y),经过 n n n个操作 ( t 1 , t 2 , ⋯   , t n ) (t_1, t_2, \cdots, t_n) (t1,T2,,Tn), berechnen Sie für eine bestimmte Folge von Operationen m m m die folgenden Abfragen:

  • i j x y:坐标 ( x , y ) (x,y) (x,y)经过操作 t i , ⋯   , t j t_i, \cdots, t_j Ti,,Tj 1 ≤ i ≤ j ≤ n 1 \le i \le j \le n 1ichJDie neuen Koordinaten nach n).

Im Untersuchungsraum stellte der Autor fest, dass es sich bei dieser Frage um ein Intervallabfrageproblem handelte, daher dachte ich zunächst über die Verwendung eines Baumarrays nach. Allerdings beträgt die zeitliche Komplexität beim Aufbau eines Baumarrays O ( n ) O(n) O(n), aber das ist das nächste Zielzeit und Leistungsrate O ( l o g n ) O(log\ n) O(log n) . Diese Frage beinhaltet keine Änderung der Intervallwerte, daher besteht keine Notwendigkeit, ein Baumarray zu verwenden. Sie müssen nur k k kVorderseite der Welt θ \theta Das Präfixprodukt von θ reicht aus. Die zeitliche Komplexität der Erstellung des Präfixsummenvektors und des Präfixproduktvektors beträgt O ( n ) O(n) O(n),Jedes Mal Stationsüberprüfung Sollzeit Leistung erhöhen O ( 1 ) O(1) O(1)

Da insbesondere die beiden Verhaltensweisen der Streckung und Drehung unabhängig voneinander sind, müssen wir nur die jeweiligen Prozesse finden n n n个操作 ( t 1 , t 2 , ⋯   , t n ) (t_1, t_2, \cdots, t_n) (t1,T2,,Tn), der Gesamtdrehwinkel und das Streckungsmultiplikator. Wir müssen nur 2 Vektoren pflegen:

  1. Gestreckter Präfixproduktvektor k = { k 0 , k 1 , k 2 , ⋯ , k n } \mathbf k = \{k_0,k_1, k_2,\cdots, k_n \} k={ k0,k1,k2,,kn}, innen k 0 = 1 k_0=1 k0=1 k i k_i kivor i i Das Vielfache der Gesamtstrecke von i-Operationen, also das Präfixprodukt;
  2. Konsolidierungsbetrag vor der Rotationθ = { θ 0 , θ 1 , θ 2 , ⋯ , θ n } = \{\theta_0 , \theta_1, \theta_2,\cdots,\theta_n\} ={ θ0,ich1,ich2,,ichn}, innen θ 0 = 0 \theta_0=0 ich0=0 θ i \theta_i ichivor i i Der Gesamtdrehwinkel von i-Operationen, also die Präfixsumme.

beantworte die Nachricht ( x , y ) (x, y) (x,y)经过 t i , ⋯   , t j t_i, \cdots, t_j Ti,,Tj 1 ≤ i ≤ j ≤ n 1 \le i \le j \le n 1ichJn) Danach ist das Erweiterungsmultiplikator 为 k j / k i − 1 k_j / k_{i-1} kj/ki1, Winkel 为 θ j − θ i − 1 \theta_j-\theta_{i-1} ichjichi1

AC-Code

#include <bits/stdc++.h>

using namespace std;

int n, m;

vector<double> xita(100005);
vector<double> k(100005, 1);


int main() {
    
    
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
    
    
        int type;
        double value;
        cin >> type >> value;
        if (type == 1) {
    
    
            k[i] = k[i - 1] * value;
            xita[i] = xita[i - 1];
        } else {
    
    
            k[i] = k[i - 1];
            xita[i] = xita[i - 1] + value;
        }
    }

    for (int i = 0; i < m; ++i) {
    
    
        int l, r;
        double x, y;
        cin >> l >> r >> x >> y;

        double sum_xita = xita[r] - xita[l - 1];
        double pro_k = k[r] / k[l - 1];

        cout << fixed << setprecision(3) << (x * cos(sum_xita) - y * sin(sum_xita)) * pro_k << " "
             << (x * sin(sum_xita) + y * cos(sum_xita)) * pro_k << endl;
    }

    return 0;
}

Supongo que te gusta

Origin blog.csdn.net/weixin_46655675/article/details/133781804
Recomendado
Clasificación