昨天用vim练了一道大水题,今天特地找了道稍难一点的题。不过也不是很难,简单的计算几何而已。练习用vim编码,用gdb调试,结果居然1A了,没调试。。。囧。。。

做法很简单,无非就是两种情况:①三个巫师构成一个钝角(极限情况是直角)三角形,那么所画的圆应该是钝角所对边为直径的圆;②三个巫师构成一个锐角三角形,那么所画的圆应该是三角形的外接圆。

就这样纸,上了点模板,代码如下:

/*
* Author : ben
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <functional>
#include <numeric>
#include <cctype>
using namespace std;
typedef struct MyPoint {
double x;
double y;
MyPoint(double xx, double yy) {
x = xx;
y = yy;
}
MyPoint() {
x = y = ;
}
}MyPoint; typedef struct MyLine {
MyPoint a, b;
} MyLine;
MyPoint intersection(MyLine u, MyLine v) {
MyPoint ret = u.a;
double t = ((u.a.x - v.a.x) * (v.a.y - v.b.y)
- (u.a.y - v.a.y) * (v.a.x - v.b.x))
/ ((u.a.x - u.b.x) * (v.a.y - v.b.y)
- (u.a.y - u.b.y) * (v.a.x - v.b.x));
ret.x += (u.b.x - u.a.x) * t;
ret.y += (u.b.y - u.a.y) * t;
return ret;
}
//外心
MyPoint circumcenter(MyPoint a, MyPoint b, MyPoint c) {
MyLine u, v;
u.a.x = (a.x + b.x) / ;
u.a.y = (a.y + b.y) / ;
u.b.x = u.a.x - a.y + b.y;
u.b.y = u.a.y + a.x - b.x;
v.a.x = (a.x + c.x) / ;
v.a.y = (a.y + c.y) / ;
v.b.x = v.a.x - a.y + c.y;
v.b.y = v.a.y + a.x - c.x;
return intersection(u, v);
}
typedef struct MyCircle {
MyPoint p;
double r;
}MyCircle; inline double dis(const MyPoint &p1, const MyPoint &p2) {
return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y);
} MyCircle getCircle(MyPoint ps[]) {
MyCircle ret;
ret.r = -;
for(int i = ; i < ; i++) {
MyPoint a = ps[i % ];
MyPoint b = ps[(i + ) % ];
MyPoint c = ps[(i + ) % ];
double x = (a.x + b.x) / ;
double y = (a.y + b.y) / ;
MyPoint t = MyPoint(x, y);
double r = dis(a, b) / ;
double temp = dis(t, c);
if(temp <= r) {
ret.r = r;
ret.p = t;
}
}
if(ret.r != -) {
return ret;
}
ret.p = circumcenter(ps[], ps[], ps[]);
ret.r = dis(ret.p, ps[]);
return ret;
} int main() {
// freopen("data.in", "r", stdin);
int T;
double x, y;
scanf("%d", &T);
MyPoint wizards[];
MyPoint muggle;
for(int t = ; t <= T; t++) {
for(int i = ; i < ; i++) {
scanf("%lf%lf", &x, &y);
wizards[i] = MyPoint(x, y);
}
scanf("%lf%lf", &x, &y);
muggle = MyPoint(x, y);
MyCircle c = getCircle(wizards);
double d = dis(muggle, c.p);
if(d <= c.r) {
printf("Case #%d: Danger\n", t);
} else {
printf("Case #%d: Safe\n", t);
}
}
return ;
}

hdu 4720 计算几何简单题的更多相关文章

  1. HDOJ/HDU 2568 前进(简单题)

    Problem Description 轻松通过墓碑,进入古墓后,才发现里面别有洞天. 突然,Yifenfei发现自己周围是黑压压的一群蝙蝠,个个扇动翅膀正准备一起向他发起进攻! 形势十分危急! 好在 ...

  2. HDU 1753 大明A+B(字符串模拟,简单题)

    简单题,但要考虑一些细节: 前导0不要,后导0不要,小数长度不一样时,有进位时,逆置处理输出 然后处理起来就比较麻烦了. 题目链接 我的代码纯模拟,把小数点前后分开来处理,写的很繁杂,纯当纪念——可怜 ...

  3. (hdu 简单题 128道)平方和与立方和(求一个区间的立方和和平方和)

    题目: 平方和与立方和 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  4. HDU 6106 17多校6 Classes(容斥简单题)

    Problem Description The school set up three elective courses, assuming that these courses are A, B, ...

  5. HDU 6463.超级无敌简单题-卡边界的暴力 (“字节跳动-文远知行杯”广东工业大学第十四届程序设计竞赛)

    超级无敌简单题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  6. Least Common Multiple (HDU - 1019) 【简单数论】【LCM】【欧几里得辗转相除法】

    Least Common Multiple (HDU - 1019) [简单数论][LCM][欧几里得辗转相除法] 标签: 入门讲座题解 数论 题目描述 The least common multip ...

  7. BZOJ 2683: 简单题

    2683: 简单题 Time Limit: 50 Sec  Memory Limit: 128 MBSubmit: 913  Solved: 379[Submit][Status][Discuss] ...

  8. 【BZOJ-1176&2683】Mokia&简单题 CDQ分治

    1176: [Balkan2007]Mokia Time Limit: 30 Sec  Memory Limit: 162 MBSubmit: 1854  Solved: 821[Submit][St ...

  9. Bzoj4066 简单题

    Time Limit: 50 Sec  Memory Limit: 20 MBSubmit: 2185  Solved: 581 Description 你有一个N*N的棋盘,每个格子内有一个整数,初 ...

随机推荐

  1. hdu 1275 两车追及或相遇问题

    思路:这里有2种情况: 一种是相遇:满足关系是 (va+vb)*t=L*(2*n-1) 一种是追及: 满足关系是 |va-vb|*t=L*(2*n-1) 这样求出2种情况的时间,在排序就可以了…… 链 ...

  2. Android 通过程序添加桌面快捷方式

    原理:通过代码向 Launcher 中的广播接收者发送广播来创建快捷图标. 首先要声明的权限是: <!--添加图标的权限--> <uses-permission android:na ...

  3. java 追加写入代码一例

    最近最项目参数化的时候用到,场景是这样的,需要测试A和B两个接口,其中B接口传入的参数必须是传递给A接口过的,所以整理一个思路就是: 1. 正常调用A接口,但是将传递给A接口的参数保存到文本里,此处要 ...

  4. 套题T4

    Problem 1 无聊的gcd(gcd.c/cpp/pas) 话说出题人不会被查水表吧. 简单的问题描述:从N个正整数里面取出K个数的最大公因数最大是多少.(请将答案乘上k之后输出哦,谢谢合作.) ...

  5. Apache 下SVN项目管理使用说明

    Apache 下SVN项目管理使用说明 (1)Apaceh和SVN先要装好. (2)在apache的目录下找到httpd.conf文件,在最后一行增加如下配置 Include conf/svn.pro ...

  6. 如何配置svn服务器

    如果你已经安装好了VisualServer服务器,现在让我们一起来配置svn服务器吧. 工具/原料 VisualServer 配置VisualServer 找到VisualServer Manager ...

  7. *windows文件显示后缀名

  8. HotSwap和JRebel原理

    HotSwap和JRebel原理 HotSwap和Instrumentation 在2002年的时候,Sun在Java 1.4的JVM中引入了一种新的被称作HotSwap的实验性技术,这一技术被合成到 ...

  9. PHP文件下载原理

    1.php下载原理图 2.文件下载源码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 <?php $ ...

  10. PHP比你想象的好得多

    有很多对于PHP的抱怨,甚至这些抱怨也出自很多聪明的人.当Jeff Atwood写下对于PHP的另一篇抱怨文章之后,我思考了下PHP的好的方面. 这些抱怨最大的问题是他们出自很多仍在使用旧版本PHP的 ...