CF306D Polygon *2300

Portal

题意:给定一个 \(n\),构造一个边长两两不等,内角两两相同的 \(n\) 边形。。

发现可以构造一个正 \(n\) 边形,然后对每条边加以不同且很小的边长偏扰,比如逆时针考虑,对第 \(i\) 条边加上 \(i\epsilon\)。但是这样多边形无法闭合,否则角度不同。所以可以特殊考虑最后一个点位置。令第一个点在原点上,多边形始终在 \(x\) 轴之上,最后一条边在 \(x\) 轴上,那么最后一个点就直接按照角度求与 \(x\) 轴交点。

那为什么这个构造方案他不会出现边长相同呢?首先前 \(n-2\) 条边是递增的。把这些边分为左右两边,因为边长递增,所以右边除去第一条边的向上长度短于左边,所以第 \(n-1\) 条边短于第 \(1\) 条边,也短于其他所有边。同理,把这些边分成上下两部分,本来应该是边长相近的,但是第 \(n-1\) 条边遥遥落后于其他边,所以第 \(n\) 条边就要遥遥长于其他边。

代码非常好写。

// STOOOOOOOOOOOOOOOOOOOOOOOOO hzt CCCCCCCCCCCCCCCCCCCCCCCORZ
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;
using LL = long long;
using PII = pair<int, int>;

int n;
int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n;
  if (n < 5) {
    cout << "No solution\n";
    return 0;
  }
  double agl = 0, c = acos(-1) * 2 / n, len = 500;
  double x = 0, y = 0;
  cout << fixed << setprecision(3);
  for (int i = 1; i < n; i++) {
    cout << x << ' ' << y << '\n';
    agl += c, len += 1e-2;
    i < n - 1 && (x += len * cos(agl), y += len * sin(agl));
  }
  cout << x - y / tan(agl) << ' ' << 0 << '\n';
  return 0;
}
posted @ 2024-02-26 17:16  Lightwhite  阅读(36)  评论(0)    收藏  举报