题目大意就是求n边形最小外接正方形

被卡了好久:听说是结论题:

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<cmath>
#include<map>
#include<string>
#include<queue>
#include<functional>
using namespace std;
int n,t;
int  a,b,c,d;double sum=0;
#define pi acos(-1.0)
int main()
{scanf("%d",&n);while(n--){scanf("%d",&a);sum=1/sin(pi/(2*a))*cos(pi/(4*a));printf("%.7lf\n",sum);}
}

下面来看大佬的二分解法
我们知道正方形最大是L多边形内部半径。我们可以二分一下这个正方形可以缩小最大是多少

#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cstring>
#include <string>
#include <deque>
#include <cmath>
#include <iomanip>
#include <cctype>#define endl '\n'
#define IOS std::ios::sync_with_stdio(0);
#define FILE freopen("..//data_generator//in.txt","r",stdin),freopen("res.txt","w",stdout)
#define FI freopen("..//data_generator//in.txt","r",stdin)
#define FO freopen("res.txt","w",stdout)
#define md make_pair
#define pb push_back
#define mp make_pair
#define seteps(N) fixed << setprecision(N) typedef long long ll;ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
inline ll qmul(ll a, ll b, ll m) {ll res = 0;while(b) {if(b & 1) res = (res + a) % m;a = (a << 1) % m;b = b >> 1;}return res;
}
inline ll qpow(ll a, ll b, ll m) {ll res = 1;while(b) {if(b & 1) res = (res * a) % m;a = (a * a) % m;b = b >> 1;}return res;
}
inline ll inv(ll x, ll q) {return qpow(x, q - 2, q);
}using namespace std;
/*-----------------------------------------------------------------*/#define INF 0x3f3f3f3fconst int N = 3e6 + 10;
const double eps = 1e-10;char s[N];const long double PI = 3.14159265358979323846;int main() {IOS;int t;cin >> t;while(t--) {int n;cin >> n;long double o = PI / n;long double L = (long double)0.5 / sin(o / 2);//求出多边形的内部半径long double l = 0, r = L - cos(o / 2) * L;//二分正方形可以缩短的长度最多是delta//通过画图我们可以发现一定会有一个点落在差不多就是这两条边放得下,对应的多边形也就放得下了while(r - l > eps) {long double deL = (l + r) / 2;long double deo = acos((L - deL) / L);//返回弧度制if(L * cos(o / 2 - deo) <= L - deL) l = deL;//你就求出与这点相邻的边的另一个点是否在正方形。else r = deL;}cout << seteps(10) << 2 * (L - l) << endl;}
}

Educational Codeforces Round 87 (Rated for Div. 2)C2. Not So Simple Polygon Embedding【几何题】相关推荐

  1. Educational Codeforces Round 73 (Rated for Div. 2) E. Game With String 思维博弈 好题(2500)

    传送门 文章目录 题意: 思路: 题意: 思路: 我们将每一段...拿出来看成若干段,将其分成以下四种情况: (1)len<b(1)len<b(1)len<b (2)b≤len< ...

  2. Educational Codeforces Round 87 (Rated for Div. 2) F. Summoning Minions

    题目链接 Polycarp plays a computer game. In this game, the players summon armies of magical minions, whi ...

  3. Educational Codeforces Round 87 (Rated for Div. 2) C1+C2(几何图形/找规律)

    C1传送门 C2传送门 给出一个正2n边形,求出其最小外接正方形的边长 当n为偶数时 不难发现正多边形刚好有四条边和正方形的四条边重合,观察发现该正多边形的边长刚好为内接圆的直径 当n为奇数时 第一眼 ...

  4. Educational Codeforces Round 50 (Rated for Div. 2)的A、B、C三题AC代码

    A题链接:https://codeforces.com/contest/1036/problem/A A题AC代码: 1 #include <stdio.h> 2 #include < ...

  5. 贪心 ---- Educational Codeforces Round 90 (Rated for Div. 2)E. Sum of Digits[数位贡献+思维题+贪心]

    题目链接 题目大意:就是给你nnn和kkk然后再定义一个函数f(x)是十进制数x各个位数之和f(x)是十进制数x各个位数之和f(x)是十进制数x各个位数之和 叫你求出最小的x使得f(x)+f(x+1) ...

  6. Educational Codeforces Round 90 (Rated for Div. 2)(A, B, C, D, E)

    Educational Codeforces Round 90 (Rated for Div. 2) Donut Shops 思路 分三种情况: a==c/ba == c / ba==c/b这个时候两 ...

  7. Educational Codeforces Round 114 (Rated for Div. 2) (A ~ F)全题解

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Educational Codeforces Round 114 (Rated for Div. 2) ...

  8. Educational Codeforces Round 106 (Rated for Div. 2)(A ~ E)题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 Educational Codeforces Round 106 (Rated for Div. ...

  9. Educational Codeforces Round 37 (Rated for Div. 2) 1

    Educational Codeforces Round 37 (Rated for Div. 2) A.Water The Garden 题意:Max想给花园浇水.花园可被视为长度为n的花园床,花园 ...

最新文章

  1. oracle按时间导出,如何为Oracle导出文件加上时间戳
  2. android AsyncTask介绍(转)
  3. C++ POD与结构体声明
  4. c++可以做什么项目_上班做下班后可以做的兼职项目
  5. Okhttp之RealConnection建立链接简单分析
  6. GUID和UUID、CLSID、IID 区别及联系
  7. 评侯捷的《深入浅出MFC》和李久进的《MFC深入浅出》
  8. Chorme AXURE 插件无效
  9. android百度地图导航功能开发,Android百度地图应用开发基础知识
  10. 偏心率计算公式matlab,结构计算整体指标(3)——扭转位移比及楼层偏心率
  11. 全国计算机等级考试 二级C语言考前复习资料(笔试)
  12. 图形学初步--裁剪算法之Liang-Barsky算法
  13. 30天自制操作系统第二天
  14. 二柱子卖的西瓜上315啦!一个故事读懂315危机公关
  15. GO语言开发天天生鲜项目第三天 用户模块开发
  16. www.51zzl.com
  17. 【python】python内置函数——print()打印输出信息
  18. 电子小制作:一个远程温度湿度监控方案
  19. 【我的Android进阶之旅】 Android Studio插件之Jenkins插件介绍
  20. OpenGL SuperBible中的glew和GLTools库

热门文章

  1. 线阵相机和面阵相机的区别及应用
  2. 归一化 vs 标准化 定量的分析
  3. 巨大的需求之下 人工智能如何更快落地?
  4. ElasticSearch性能优化策略【转】
  5. 王立飞:专注己之长 跨界求发展
  6. 如何查找Authorization object在哪些ABAP代码里使用到
  7. Linux中mmap与munmap函数系统调用
  8. The ECDSA host key for XXX has changed
  9. php设计模式 - 建造者模式
  10. 集成服务入门(实验9)日志记录和邮件通知