题意:给定上正方形,圆,三角形,让你求出包围它的最短的路径。

析:首先,如果是这种情况  三角形 三角形 三角形 正方形(圆) 三角形 三角形 三角形 。。这一种就是直接从左边直接连到正方形(圆),也就是相切,剩下的情况都是直接是直线,只要处理一下边界就好。

代码如下:

#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 (计算几何)的更多相关文章

  1. [CERC2016]:凸轮廓线Convex Contour(模拟+数学)

    题目描述 一些几何图形整齐地在一个网格图上从左往右排成一列.它们占据了连续的一段横行,每个位置恰好一个几何图形.每个图形是以下的三种之一:$1.$一个恰好充满单个格子的正方形.$2.$一个内切于单个格 ...

  2. 【计算几何】【分类讨论】Gym - 101173C - Convex Contour

    注意等边三角形的上顶点是卡不到边界上的. 于是整个凸包分成三部分:左边的连续的三角形.中间的.右边的连续的三角形. 套个计算几何板子求个三角形顶点到圆的切线.三角形顶点到正方形左上角距离啥的就行了,分 ...

  3. HDU 5979 Convex【计算几何】 (2016ACM/ICPC亚洲区大连站)

    Convex Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  4. 2018牛客网暑假ACM多校训练赛(第三场)I Expected Size of Random Convex Hull 计算几何,凸包,其他

    原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round3-I.html 题目传送门 - 2018牛客多校赛第三场 I ...

  5. UVALive 4428 Solar Eclipse --计算几何,圆相交

    题意:平面上有一些半径为R的圆,现在要在满足不与现有圆相交的条件下放入一个圆,求这个圆能放的位置的圆心到原点的最短距离. 解法:我们将半径扩大一倍,R = 2*R,那么在每个圆上或圆外的位置都可以放圆 ...

  6. UVaLive 6693 Flow Game (计算几何,线段相交)

    题意:给个棋盘,你可以在棋盘的边缘处放2个蓝色棋子2个黄色棋子,问连接2组同色棋子的最小代价,如果线路交叉,输-1. 析:交叉么,可以把它们看成是两条线段,然后如果相交就是不行的,但是有几种特殊情况, ...

  7. Codeforces 101173 C - Convex Contour

    思路: 如果所有的图形都是三角形,那么答案是2*n+1 否则轮廓肯定触到了最上面,要使轮廓线最短,那么轮廓肯定是中间一段平的 我们考虑先将轮廓线赋为2*n+2,然后删去左右两边多余的部分 如果最左边或 ...

  8. 2017ACM/ICPC亚洲区沈阳站 C Hdu-6219 Empty Convex Polygons 计算几何 最大空凸包

    题面 题意:给你一堆点,求一个最大面积的空凸包,里面没有点. 题解:红书板子,照抄完事,因为题目给的都是整点,所以最后答案一定是.5或者.0结尾,不用对答案多做处理 #include<bits/ ...

  9. VTK三维点集轮廓凸包提取

    碰撞检测问题在虚拟现实.计算机辅助设计与制造.游戏及机器人等领域有着广泛的应用,甚至成为关键技术.而包围盒算法是进行碰撞干涉初步检测的重要方法之一.包围盒算法是一种求解离散点集最优包围空间的方法.基本 ...

随机推荐

  1. android.support.v4.app.Fragment vs android.app.Fragment 的区别

    android.support.v4.app.Fragment vs android.app.Fragment 的区别 我开过平板相关应用,用了Fragment来处理.后来重新开发另外一个应用,直接引 ...

  2. 修改win7远程桌面端口号

    Windows 7/Vista/XP/2003等系统中的远程终端服务是一项功能非常强大的服务,同时也成了入侵者长驻主机的通道,入侵者可以利用一些手段得到管理员账号和密码并入侵主机.下面,我们来看看如何 ...

  3. LCS(最长公共子序列)动规算法正确性证明

    今天在看代码源文件求diff的原理的时候看到了LCS算法.这个算法应该不陌生,动规的经典算法.具体算法做啥了我就不说了,不知道的可以直接看<算法导论>动态规划那一章.既然看到了就想回忆下, ...

  4. 爬虫验证码处理与IP处理

    引入 相关的门户网站在进行登录的时候,如果用户连续登录的次数超过3次或者5次的时候,就会在登录页中动态生成验证码.通过验证码达到分流和反爬的效果. - 1.对携带验证码的页面数据进行抓取 - 2.可以 ...

  5. SpringMVC关于json、xml自动转换的原理研究[附带源码分析](使用JAXB转换XML)

    前言 SpringMVC是目前主流的Web MVC框架之一. 如果有同学对它不熟悉,那么请参考它的入门blog:http://www.cnblogs.com/fangjian0423/p/spring ...

  6. centos7 端口开放

    CentOS升级到7之后,发现无法使用iptables控制Linuxs的端口,google之后发现Centos 7使用firewalld代替了原来的iptables.下面记录如何使用firewalld ...

  7. linux系统中的变量

    一.定义 所谓的变量,就是就是利用一个特定的"名称"(name)来存取一段可以变化的"值"(value),简单说来就是“用一个名称储存一个数值”.   二.设定 ...

  8. 40 Questions to test your skill in Python for Data Science

    Comes from: https://www.analyticsvidhya.com/blog/2017/05/questions-python-for-data-science/ Python i ...

  9. 快速搭建Wordpress

    1. 下载:ZentaoPMS作为Mysql Apach Php的基础环境: 2. 下载:Wordpress安装包: 3. 将Wordpress解压,放置于ZentaoPMS的Xampp的htdocs ...

  10. String.getBytes()[转]

    在Java中,String的getBytes()方法是得到一个操作系统默认的编码格式的字节数组.这个表示在不通OS下,返回的东西不一样! String.getBytes(String decode)方 ...