杭州地区赛的遗憾 Rotational Painting

本文介绍了一种结合重心和凸包算法解决特定几何问题的方法。通过使用Graham扫描算法求解凸包,并计算多边形的重心来解决题目。代码实现了凸包计算及判断重心是否位于由凸包顶点构成的线段上。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目其实稍微注意一下就知道怎么搞了。

重心+凸包!

然后枚举相邻凸点就行

 

#include <iostream>
#include <algorithm>
using namespace std;

#define N 50005
/*==================================================*/
| Graham 求凸包 O(N * logN)
| CALL: nr = graham(pnt, int n, res); res[]为凸包点集;
/*==================================================*/
struct point { double x, y; };
bool mult(point sp, point ep, point op){
 return (sp.x - op.x) * (ep.y - op.y)
  >= (ep.x - op.x) * (sp.y - op.y);
}
bool operator < (const point &l, const point &r){
 return l.y < r.y || (l.y == r.y && l.x < r.x);
}

int graham(point pnt[], int n, point res[]){
 int i, len, k = 0, top = 1;
 sort(pnt, pnt + n);
 if (n == 0) return 0; res[0] = pnt[0];
 if (n == 1) return 1; res[1] = pnt[1];
 if (n == 2) return 2; res[2] = pnt[2];
 for (i = 2; i < n; i++) {
  while (top && mult(pnt[i], res[top], res[top-1]))
   top--;
  res[++top] = pnt[i];
 }
 len = top; res[++top] = pnt[n - 2];
 for (i = n - 3; i >= 0; i--) {
  while (top!=len && mult(pnt[i], res[top],
   res[top-1])) top--;
  res[++top] = pnt[i];
 }
 return top;       // 返回凸包中点的个数
}

/*==================================================*/
| 求多边形重心
| INIT: pnt[]已按顺时针(或逆时针)排好序;
| CALL: res = bcenter(pnt, n);
/*==================================================*/

point bcenter(point pnt[], int n){
 point p, s;
 double tp, area = 0, tpx = 0, tpy = 0;
 p.x = pnt[0].x; p.y = pnt[0].y;
 for (int i = 1; i <= n; ++i) {   // point: 0 ~ n-1
  s.x = pnt[(i == n) ? 0 : i].x;
  s.y = pnt[(i == n) ? 0 : i].y;
  tp = (p.x * s.y - s.x * p.y); area += tp / 2;
  tpx += (p.x + s.x) * tp; tpy += (p.y + s.y) * tp;
  p.x = s.x; p.y = s.y;
 }
 s.x = tpx / (6 * area); s.y = tpy / (6 * area);
 return s;
}
point pnt[N],res[N];
point core;
bool gao(int c)
{
 point dir1;
 dir1.x=res[c+1].x-res[c].x;
 dir1.y=res[c+1].y-res[c].y;
 if(dir1.x==0)
 {
  if( (core.y-res[c].y)*(core.y-res[c+1].y) < 0)
   return true;
  return false;
 }
 else if(dir1.y==0)
 {
  if( (core.x-res[c].x)*(core.x-res[c+1].x) < 0)
   return true;
  return false;
 }
 else
 {
  double a=dir1.x,b=dir1.y;
  double k=b/a;
  double cc=res[c].y-k*res[c].x;
  double xx=(a*core.x-b*cc+b*core.y);
   xx/=(a+b*k);
  if( (xx-res[c].x)*(xx-res[c+1].x) < 0)
   return true;
  return false;
 }
}

int main()
{
 int n,i,j;
 
 int T;
 scanf("%d",&T);
 while(T --)
 {
  scanf("%d",&n);
  for(i=0;i<n;i++)
   scanf("%lf%lf",&pnt[i].x,&pnt[i].y);
  core = bcenter(pnt,n);
  //cout<<core.x<<" "<<core.y<<endl;
  n = graham(pnt,n,res);
  res[n]=res[0];
  //for(i=0;i<=n;i++)
  // cout<<res[i].x<<" "<<res[i].y<<endl;
  //printf("%d/n",n);
  int ans=0;
  for(i=0;i<n;i++)
   if(gao(i))
    ans++;
  printf("%d/n",ans);

 }
 return 0;
}

/*
10
4
0 0
1 0
2 2
1 2
*/

### 信号参数估计中的旋转不变技术 在信息技术领域,特别是无线通信和雷达系统中,基于旋转不变性的信号参数估计算法被广泛应用。这类方法利用了多天线阵列接收到的数据之间的空间特性来提高参数估计精度。 #### ESPRIT算法简介 ESPRIT (Estimation of Signal Parameters via Rotational Invariance Techniques) 是一种经典的子空间分解型高分辨率谱分析方法[^1]。该算法的核心在于构建两个观测向量之间存在的特定关系矩阵,并从中提取出所需的频率或其他物理量的信息。具体来说: - **数据模型建立**:假设存在 \(N\) 个传感器组成的均匀线性阵列接收来自远场源的窄带信号,则可以得到如下形式的数据矢量 \(\mathbf{x}(t)\),其中包含了所有时刻 t 的采样值。 \[ \mathbf{x}(t)=\sum_{i=1}^{d}\alpha_i(t)e^{-j2\pi f_itT_s}\mathbf{a}(\theta_i)+\mathbf{n}(t), \] 这里 \(\alpha_i(t)\) 表示第 i 路信号幅度;\(f_i\) 和 \(\theta_i\) 分别代表对应的频率分量以及入射角度;而 \(\mathbf{a}(\cdot)\) 则定义为方向矢量函数;最后加上噪声项 \(\mathbf{n}(t)\)。 - **构造旋转不变结构**:为了实现这一点,在实际应用中通常会选择相邻两组不同位置上的传感单元所构成的小阵列来进行处理。设第一个小阵列为 A 组,第二个为 B 组,那么就可以形成一对具有相似特性的测量方程: \[ [\mathbf{X}_A,\mathbf{X}_B]=[\mathbf{\Phi},\mathbf{T}\mathbf{\Phi}] \] 这里的 \(\mathbf{\Phi}\) 称作特征模式矩阵,它由各个信道的方向矢量组成;而转移算子 \(\mathbf{T}\) 描述的是由于几何位移造成的相位变化规律。 - **求解过程**:通过对上述表达式的进一步变换可得广义本征值问题的形式,进而采用奇异值分解(SVD) 或者其他数值优化手段找到最优解路径,最终完成对未知参量的有效辨识工作。 ```matlab % MATLAB Code Example for Basic Steps in ESPRIT Algorithm Implementation function [freq_estimates, angle_estimates] = esprit_algorithm(x, d, N) % Input: x - Received signal matrix with dimensions LxM where L is number of snapshots and M is array elements. % d - Number of sources/signals present. % N - Total length of the data record. % Step 1: Formulate covariance matrices from received signals Rxx = cov(x); % Step 2: Perform eigenvalue decomposition on Rxx to separate noise subspace from signal subspace [~, ~, V] = svd(Rxx); U_signal = V(:, end-d+1:end); % Step 3: Construct shift-invariant subarrays' observation vectors X_A & X_B based on U_signal X_A = U_signal(1:N-d,:); X_B = U_signal(d+1:end,:); % Step 4: Solve generalized eigenproblem between shifted versions of observations T_hat = inv(X_A'*X_A)*X_A'*X_B; % Step 5: Estimate frequencies through diagonalization of T_hat or its complex conjugate transpose freq_estimates = sort(abs(angle(eig(T_hat)))/(2*pi)); % For simplicity this example does not cover DOA estimation part which would involve additional steps involving steering vector calculations etc. end ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值