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三维点集轮廓凸包提取
碰撞检测问题在虚拟现实.计算机辅助设计与制造.游戏及机器人等领域有着广泛的应用,甚至成为关键技术.而包围盒算法是进行碰撞干涉初步检测的重要方法之一.包围盒算法是一种求解离散点集最优包围空间的方法.基本 ...
随机推荐
- python学习(二十一) Python 中的链式赋值
Python的链式赋值如下:
- node+express+ejs搭建一个简单的"页面"
1.建立工程文件夹my_ejs. 2.首先利用npm install express和npm install ejs 下载这两个家伙.至于要不要设置成全局的,看习惯,我习惯性的下载到本项目中的文件夹中 ...
- Java死锁以及命令检测
Java每个对象都有一把锁,当前进程使用对象锁1,没有释放该锁,又想要去获取另一把对象锁2,而对象锁2被另外一个线程持有,没有释放,这就很容易出现死锁 1.死锁实例 public class Dead ...
- B. T-primes
/* PROBLEMSSUBMITSTATUSSTANDINGSCUSTOM TEST B. T-primes time limit per test2 seconds memory limit pe ...
- spring 声明式事务的坑 @Transactional 注解
1.首先环境搭建,jar 我就不写了,什么一些spring-core.jar spring-beans.jar spring-content.jar 等等一些包 省略..... 直接上图: sprin ...
- Jenkins启动报端口被占用,解决办法FAILED ServerConnector@2a265ea9{HTTP/1.1}{0.0.0.0:8080}: java
修改Jenkins端口java -jar jenkins.war --httpPort=8081
- C# 6 与 .NET Core 1.0 高级编程 - C# 6 的新功能
个人原创译文,转载请注明出处.有不对的地方欢迎指出与交流. 英文原文:Professional C# 6 and .NET Core 1.0 - What’s New in C# 6 C# 6 的新功 ...
- struts2 action重定向action中文乱码处理
比如:Action方法productCategorySave()变量message,传递给Action方法productCategoryAdd(),当变量message为中文变量时,要进行编码设置,不 ...
- js对象的几种创建方式和js实现继承的方式[转]
一.js对象的创建方式 1. 使用Object构造函数来创建一个对象,下面代码创建了一个person对象,并用两种方式打印出了Name的属性值. var person = new Object(); ...
- 在zookeeper集群的基础上,搭建伪solrCloud集群
伪集群的搭建:将solrCloud搭建到同一台机器上. 准备工作 1 将在window中部署的单机版solr上传到服务器(虚拟机)中 solr的简单部署:在tomcat中启动slor 的内容 这一次放 ...