昨天用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. Android 监测手机联网状态 wifi、移动数据流量、无联网状态

    手机当完成联网时会发送一个广播,我们只要创建一个广播接收者即可,代码如下: package com.example.NetworkChangeReceiver2; import android.con ...

  2. 如何在Mininet中修改host的IP地址

    how to update virtual host's IP in mininet? I got it! do like this: mininet> py h1.setIP('10.0.0. ...

  3. spring3.0的jar包详解

    1. spring.jar 是包含有完整发布模块的单个jar 包. 2. org.springframework.aop 包含在应用中使用Spring的AOP特性时所需的类. 3. org.sprin ...

  4. yum工具介绍

    当你的linux处于联网状态时,yum工具能够非常方便的在Linux上安装各种软件.补丁等等,而且最重要的一点是完全不用管包的依赖关系.只需要简单的指定你要安装的软件名称,其他工作几乎都交给yum了, ...

  5. Hibernate逍遥游记-第15章处理并发问题-002悲观锁

    1. 2. hibernate.dialect=org.hibernate.dialect.MySQLDialect hibernate.connection.driver_class=com.mys ...

  6. JRE下的rt.jar、tools.jar

    JRE下的rt.jar: 这个文件是极为重要的一个文件,rt是runtime的缩写,即运行时的意思.是java程序在运行时必不可少的文件. 里面包含了java程序员常用的包,如java.lang,ja ...

  7. C++:对象数组

    对象数组 对象数组:每一个数组元素都是对象的数组,也就是说,若一个类有若干个对象,我们把这 一系列的对象用一个数组来存放.对应数组元素是对象,不仅具有的数据成员,而且还有函数 成员. @定义一个一维数 ...

  8. sudo

    sudo的目的:为非根用户授予根用户的权限: 配置文件:/etc/sudoers visudo命令编辑修改/etc/sudoers配置文件 1.一般用户赋权设置: [root@localhost ~] ...

  9. WPF 用 DataTemplate 合并DataGrid列表列头<类似报表设计>及行头列头样式 - 学习

    WPF中 DataGrid 列头合并,类似于报表设计.效果图如下↓ 1.新建一个WPF项目WpfApplication1,新建一个窗体DataGridTest,前台代码如下: <Window x ...

  10. uva12230Crossing Rivers

    数学期望. 过每条河的时间的可能在[L/v,3*L/v]间均匀分布,数学期望为2*L/v. 然后在加上在陆上走的时间. #include<cstdio> #include<algor ...