codeforces #306D Polygon 构造

题目大意:给定n,要求构造一个凸n边形,使得每个内角都相同,每条边长度都不同

膜拜题解

其实我一开始想的是构造一个正n边形然后把每条边微移一下……不过似乎不是很好写的样子= =

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define M 110
#define PI 3.1415926535897932
using namespace std;
struct Point{
    double x,y;
    Point() {}
    Point(double _,double __):
        x(_),y(__) {}
    friend Point operator + (const Point &p1,const Point &p2)
    {
        return Point(p1.x+p2.x,p1.y+p2.y);
    }
    friend Point operator - (const Point &p1,const Point &p2)
    {
        return Point(p1.x-p2.x,p1.y-p2.y);
    }
    friend double operator * (const Point &p1,const Point &p2)
    {
        return p1.x*p2.y-p1.y*p2.x;
    }
    friend Point operator * (const Point &p,double rate)
    {
        return Point(p.x*rate,p.y*rate);
    }
    friend Point Rotate (const Point &p,double alpha)
    {
        return Point(p.x*cos(alpha)-p.y*sin(alpha),p.x*sin(alpha)+p.y*cos(alpha) );
    }
}ans[M];
struct Line{
    Point p,v;
    Line() {}
    Line(const Point &_,const Point &__):
        p(_),v(__) {}
    friend Point Get_Intersection(const Line &l1,const Line &l2)
    {
        Point u=l1.p-l2.p;
        double temp=(l2.v*u)/(l1.v*l2.v);
        return l1.p+l1.v*temp;
    }
};
int n;
int main()
{
    int i;
    cin>>n;
    if(n<=4)
        return cout<<"No solution"<<endl,0;
    Point v(-1,0);
    double len=450.0,delta=0.005;
    double alpha=2.0*PI/n;
    for(i=1;i<n;i++)
    {
        ans[i]=ans[i-1]+v*len;
        len+=delta;
        v=Rotate(v,-alpha);
    }
    ans[n]=Get_Intersection(Line(ans[n-1],v),Line(Point(0,0),Point(1,0)));
    for(i=n;i;i--)
        printf("%.10lf %.10lf\n",ans[i].x,ans[i].y);
    return 0;
}
时间: 2024-08-08 15:46:30

codeforces #306D Polygon 构造的相关文章

CodeForces 26C Parquet 构造题

题目链接:点击打开链接 #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <math.h> #include <set> using namespace std; #define N 105 int n,m,a,b,c; char s[N][N]; set<char>myset; bool inm

Codeforces 1030D 【构造】

LINK 题目大意:给你n,m,k,让你在一个n*m的点阵里构造出一个面积为\(\frac{n*m}{k}\)的三角形 思路 首先要有一个结论是整点三角形的面积分母最多为2,然后就可以判断不存在的情况了 接下来就直接进行构造就可以了 #include<bits/stdc++.h> using namespace std; #define LL long long #define IL inline #define fu(a,b,c) for(LL a=b;a<=c;++a) #defin

New Roads CodeForces - 746G (树,构造)

大意:构造n结点树, 高度$i$的结点有$a_i$个, 且叶子有k个. 先确定主链, 然后贪心放其余节点. #include <iostream> #include <algorithm> #include <cstdio> #include <math.h> #include <set> #include <map> #include <queue> #include <string> #include &l

CodeForces 520C 水构造

//520C - DNA Alignment 1 #include "iostream" 2 #include "cstdio" 3 using namespace std; 4 const __int64 mod = 1e9 + 7; 5 int n; 6 char str[100010]; 7 int Count[5]; 8 9 __int64 bin(__int64 n, __int64 k) 10 { 11 __int64 res = 1; 12 while

codeforces 589a(构造的字符串后,最后要加终止符,,,)

模拟注意细节,没什么好说的#include <cstdio> #include <cstring> #include <vector> #include <algorithm> #include <iostream> #include <map> #include <queue> #include <stack> #include <cmath> //#pragma comment(linker,

Codeforces 534D Handshakes 构造 模拟 贪心

题意:人们依次进大厅,后进来的人会和里面所有的人都握手, 大厅里面有三个人就 其中丧二恩就可以结伴走出大厅.给你每个人进大厅时候握手的次数.让你求一个进场顺序. 解题思路:比赛的时候是用的从后往前推.比较难,发现从前往后直接模拟就行了 . 解题代码: 1 // File Name: d.cpp 2 // Author: darkdream 3 // Created Time: 2015年04月13日 星期一 01时30分17秒 4 5 #include<vector> 6 #include&l

codeforces 1037E-Trips 【构造】

题目:戳这里 题意:n个点,每天早上会在这n个点中加一条边,每天晚上最大的子图满足子图中每个点都有k条或以上的边. 解题思路:看了官方题解,先把所有的点都连上,再从最后一天往前减边,用set维护最大的子图,注意每减去一条边时,更新该边两端点的状态. 1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int maxn = 2e5 + 10; 5 int ans[maxn]; 6 st

Codeforces 922F Divisibility 构造

Divisibility 我们考虑删数字 首先我们可以发现有一类数很特殊就是大于 n / 2的素数, 因为这些素数的贡献只有1, 并且在n大的时候, 这些素数的个数不是很少, 我们可以最后用这些数去调整, 并且删掉一个数的时候删掉的是它的因子个数, 所以可以用素数去控制最后的数量.当n小的时候直接状压枚举. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk mak

Vasya And Array CodeForces - 1187C (构造)

Vasya And Array 题意: 给你一个序列,再给你一些区间 t = 1时说明这些区间时非递减的 t = 0 时说明这些区间至少有一对数字 arr[i] > arr[i - 1] 思路: 只要左边的区间必然右边的区间大就好了 , 非递减区间中的数字都赋值为一样的数字 因为n只有1000 , 把初值cnt赋值为1e6 , 每次给区间赋值的时候 -1000 把第一种情况的区间赋值完成之后,剩下的还没有赋值的部分,都赋值为单调递减序列就可以了 1 #include<cstdio> 2