UVALive 7749 Convex Contour (计算几何)
题意:给定上正方形,圆,三角形,让你求出包围它的最短的路径。
析:首先,如果是这种情况 三角形 三角形 三角形 正方形(圆) 三角形 三角形 三角形 。。这一种就是直接从左边直接连到正方形(圆),也就是相切,剩下的情况都是直接是直线,只要处理一下边界就好。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#include <assert.h>
#include <bitset>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a, b, sizeof a)
//#define sz size()
#define pu push_up
#define pd push_down
#define cl clear()
#define all 1,n,1
#define FOR(x,n) for(int i = (x); i < (n); ++i)
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;
typedef double lb;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e15;
const double inf = 1e20;
const lb PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 50;
const int mod = 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c) {
return r >= 0 && r < n && c >= 0 && c < m;
} char str[maxn];
double Pow(double x){ return x * x; } int main(){
while(scanf("%d", &n) == 1){
scanf("%s", str);
int len = strlen(str);
int change_pos = len + 1;
int pre_T = 0, last_T = 0;
for(int i = 0; i < n; i++){
if(str[i] == 'T') pre_T++;
else break;
}
for(int i = n - 1; i >= 0; i--){
if(str[i] == 'T') last_T++;
else break;
}
bool all_T = false;
lb ans = 0.0;
if(pre_T){
lb nn = pre_T;
int cur = pre_T;
if(cur >= n){
all_T = true;
goto TT;
}
if(str[cur] == 'S')
ans += sqrt(Pow(nn - 0.5) + Pow(2 - sqrt(3)) / 4) + 0.5;
else if(str[cur] == 'C'){
lb A = (4 * Pow(nn)) / Pow(sqrt(3) - 1.0) + 1.0;
lb B = -(2 * nn) / Pow(sqrt(3) - 1);
lb C = (1.0 / 4.0) / Pow(sqrt(3) - 1.0) - 1.0 / 4.0;
lb delta = Pow(B) - 4 * A * C;
lb x1 = (-B - sqrt(delta)) / (2 * A);
lb y = sqrt(1.0 / 4.0 - Pow(x1));
lb t2 = Pow(x1) + Pow(1 / 2.0 - y);
lb ct = (1/2.0 - t2) * 2;
lb alf = acos(ct);
lb L = alf / 2.0 + sqrt(Pow(x1 - nn) + Pow(y - (sqrt(3) - 1.0) / 2.0));
ans += L;
}
} if(last_T){
lb nn = last_T;
int cur = n - 1 - last_T;
if (cur < 0){
all_T = true;
goto TT;
}
if (str[cur] == 'S')
ans += sqrt(Pow(nn - 0.5) + Pow(2 - sqrt(3)) / 4) + 0.5;
else if (str[cur] == 'C'){
lb A = (4 * Pow(nn)) / Pow(sqrt(3) - 1.0) + 1.0;
lb B = -(2 * nn) / Pow(sqrt(3) - 1);
lb C = (1.0 / 4.0) / Pow(sqrt(3) - 1.0) - 1.0 / 4.0;
lb delta = Pow(B) - 4 * A * C;
lb x1 = (-B - sqrt(delta)) / (2 * A);
lb y = sqrt(1.0 / 4.0 - Pow(x1));
lb t2 = Pow(x1) + Pow(1 / 2.0 - y);
lb ct = (1/2.0 - t2) * 2;
lb alf = acos(ct);
lb L = alf / 2.0 + sqrt(Pow(x1 - nn) + Pow(y - (sqrt(3) - 1.0) / 2.0));
ans += L;
}
}
TT:
if(all_T) ans += n - 1;
else ans += n - pre_T - last_T - 1;
ans += n;
if (str[0] == 'S') ans += 1.5;
if (str[len - 1] == 'S') ans += 1.5;
if (str[0] == 'C') ans += PI / 2.0 - 0.5;
if (str[len - 1] == 'C') ans += PI / 2.0 - 0.5;
if (str[0] == 'T') ans += 1;
if (str[len - 1] == 'T') ans += 1;
printf("%.10f\n", (double)ans);
}
return 0;
}
UVALive 7749 Convex Contour (计算几何)的更多相关文章
- [CERC2016]:凸轮廓线Convex Contour(模拟+数学)
题目描述 一些几何图形整齐地在一个网格图上从左往右排成一列.它们占据了连续的一段横行,每个位置恰好一个几何图形.每个图形是以下的三种之一:$1.$一个恰好充满单个格子的正方形.$2.$一个内切于单个格 ...
- 【计算几何】【分类讨论】Gym - 101173C - Convex Contour
注意等边三角形的上顶点是卡不到边界上的. 于是整个凸包分成三部分:左边的连续的三角形.中间的.右边的连续的三角形. 套个计算几何板子求个三角形顶点到圆的切线.三角形顶点到正方形左上角距离啥的就行了,分 ...
- HDU 5979 Convex【计算几何】 (2016ACM/ICPC亚洲区大连站)
Convex Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- 2018牛客网暑假ACM多校训练赛(第三场)I Expected Size of Random Convex Hull 计算几何,凸包,其他
原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round3-I.html 题目传送门 - 2018牛客多校赛第三场 I ...
- UVALive 4428 Solar Eclipse --计算几何,圆相交
题意:平面上有一些半径为R的圆,现在要在满足不与现有圆相交的条件下放入一个圆,求这个圆能放的位置的圆心到原点的最短距离. 解法:我们将半径扩大一倍,R = 2*R,那么在每个圆上或圆外的位置都可以放圆 ...
- UVaLive 6693 Flow Game (计算几何,线段相交)
题意:给个棋盘,你可以在棋盘的边缘处放2个蓝色棋子2个黄色棋子,问连接2组同色棋子的最小代价,如果线路交叉,输-1. 析:交叉么,可以把它们看成是两条线段,然后如果相交就是不行的,但是有几种特殊情况, ...
- Codeforces 101173 C - Convex Contour
思路: 如果所有的图形都是三角形,那么答案是2*n+1 否则轮廓肯定触到了最上面,要使轮廓线最短,那么轮廓肯定是中间一段平的 我们考虑先将轮廓线赋为2*n+2,然后删去左右两边多余的部分 如果最左边或 ...
- 2017ACM/ICPC亚洲区沈阳站 C Hdu-6219 Empty Convex Polygons 计算几何 最大空凸包
题面 题意:给你一堆点,求一个最大面积的空凸包,里面没有点. 题解:红书板子,照抄完事,因为题目给的都是整点,所以最后答案一定是.5或者.0结尾,不用对答案多做处理 #include<bits/ ...
- VTK三维点集轮廓凸包提取
碰撞检测问题在虚拟现实.计算机辅助设计与制造.游戏及机器人等领域有着广泛的应用,甚至成为关键技术.而包围盒算法是进行碰撞干涉初步检测的重要方法之一.包围盒算法是一种求解离散点集最优包围空间的方法.基本 ...
随机推荐
- 在单板上使用WIFI网卡的固件问题
(在单板上使用WIFI网卡的固件问题)(我的wifi网卡是RT3070) (一般买的网卡说是支持LINUX免驱的话,那么在/lib/firmware/ 下一定有相应的固件) 我将USB网卡接入UBUN ...
- Confluence 5.4.2安装
默认安装路径 /opt/atlassian/confluence/bin Confluence是Atlassian公司出品的团队协同与知识管理工具. Confluence是一个专业的企业知识管理与协同 ...
- Cacti监控服务器配置教程(基于CentOS+Nginx+MySQL+PHP环境搭建)
Cacti监控服务器配置教程(基于CentOS+Nginx+MySQL+PHP环境搭建) 具体案例:局域网内有两台主机,一台Linux.一台Windows,现在需要配置一台Cacti监控服务器对这两台 ...
- linux编辑器使用记录
超强大vim配置文件: wget http://files.cnblogs.com/ma6174/vimrc.zip unzip -f vimrc.zip -d ~/ 一.vim编辑器 进入 ...
- 初识python(python的安装与运行)
python--“优雅”.“明确”.“简单”的哲学定位 一.python的安装(Windows环境下) 1.在python官网下载安装文件 python的官方网址:https://www.python ...
- CentOS7.6安装稳定版Nginx
官网地址:http://nginx.org/en/linux_packages.html#RHEL-CentOS 需先安装依赖:sudo yum install -y yum-utils 安装开始: ...
- U盘安装centos7.1出现dracut问题的超简单解决方法
恰好今天有空,于是抽空回忆一下之前U盘安装CENTOS7时遇到的一个大坑.U盘装系统习惯了,就顺手用大白菜工具刻了一个CentOS 7.1的minimun ISO镜像到U盘,于是噩梦开始了.如果有人像 ...
- Android MVP模式简单易懂的介绍方式 (一)
Android MVP模式简单易懂的介绍方式 (一) Android MVP模式简单易懂的介绍方式 (二) Android MVP模式简单易懂的介绍方式 (三) 最近正在研究Android的MVP模式 ...
- Linux 如何杀死僵尸进程
问题描述: shell > top top - :: up days, :, user, load average: 0.23, 0.81, 1.07 Tasks: total, running ...
- 关于IP4上WIFI设置静态IP的一点经验
一开始我设置IP4的WIFI的"静态"IP地址后,又查看了一下"BootP"或者"DHCP"选项,然后保存退出(关键错误,后有说明),再进W ...