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三维点集轮廓凸包提取
碰撞检测问题在虚拟现实.计算机辅助设计与制造.游戏及机器人等领域有着广泛的应用,甚至成为关键技术.而包围盒算法是进行碰撞干涉初步检测的重要方法之一.包围盒算法是一种求解离散点集最优包围空间的方法.基本 ...
随机推荐
- 《Java核心技术》 -- 读书笔记 ② - 类 | 对象 | 接口
对象vs对象变量 “对象” 描述的是一个类的具体实例,他被java虚拟机分配在 "堆" (Heap)中. “对象变量” 为一个对象的引用(对象变量的值=记载着具体对象的位置/地址) ...
- 第十章 Secret & Configmap (上)
敏感信息,直接保存在容器镜像中显然不妥,比如用户名.密码等.K8s提供的解决方案是Secret. Secret会以密文的方式存储数据,避免了在配置文件中保存敏感信息.Secret会以Volume的形式 ...
- 【BZOJ】1913: [Apio2010]signaling 信号覆盖(计算几何+计数)
题目 传送门:QWQ 分析 人类智慧题,不会做...... 详细题解1 详细题解2 总体思路是考虑四边形 讨论凹四边形凸四边形,最后加一个单调性优化省掉个$ O(n) $ 代码 代码感觉好短 ...
- json data 解析demo
json data: demo: JsonObject jsonObject= JsonHandle.getAsJsonObject(city_dataInfo).get("data&quo ...
- Mysql踩过的坑
数据表示例 1.NOT IN 结果集为空 ①SELECT class_no FROM t_student; 结果为: ②SELECT * FROM t_student where class_no n ...
- Linux 调优方案--ulimit命令
可以用ulimit -a 来显示当前的各种用户进程限制.下面把某linux用户的最大进程数设为10000个: ulimit -u 10240 对于需要做许多 socket 连接并使它们 ...
- css/css3实现未知宽高元素的垂直居中和水平居中
题目:.a{ width: 200px; height: 200px; background-color: #ccc;} <body> <div class="a" ...
- [Python] Argparse module
he recommended command-line parsing module in the Python standard library 1. Basic import argparse p ...
- python中的json的基本使用方法
在python中使用json的时候,主要也就是使用json模块,json是以一种良好的格式来进行数据的交互,从而在很多时候,可以使用json数据格式作为程序之间的接口, #!/usr/bin/env ...
- OpenSUSE 安装JAVA环境变量JDK
一.首先卸载虚拟机自带的JDK环境 具体命令: rpm -qa |grep java --查找java信息 rpm –qa|grep jdk --查找jdk信息 如果有依赖关系,提示无法卸载,使 ...