昨天用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. 天灵灵,地灵灵,但愿这个一定灵!!!python调用win32api,启动应用程序窗口

    这个是逼到没办法,C#那一套,一点基本没有. 还好,网上找到例程,可以指定帐户启动进程,但愿可以摆脱WIN SERVICE启动产生的SESSION 0 隔离问题. 因为这个问题,以SERVICE启动的 ...

  2. C Primer Plus 第4章 字符串和格式化输入/输出 编程练习

    1. #include <stdio.h> int main(void) { ]; ]; printf("请输入您的名字: "); scanf("%s&quo ...

  3. String与StringBuilder

    package com.wangzhu.string; /** * String类是final类,也就是说String类不能被继承,并且其成员方法都默认为final方法.<br/> * * ...

  4. PKUSC 模拟赛 day2 上午总结

    今天上午考得不是很好,主要还是自己太弱QAQ 开场第一题给的图和题意不符,搞了半天才知道原来是走日字形的 然后BFS即可 #include<cstdio> #include<cstr ...

  5. Ajax省市联动

    以JQuery为JS,写的Ajax省市联动. 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&q ...

  6. newClass a = Func(3)中隐藏的操作

    缘起 #include <iostream> #include <bitset> using namespace std; class A { public: A() { co ...

  7. spring-boot-quartz, 依赖spring-boot-parent

    spring-boot-quartz, 依赖spring-boot-parent spring-boot Easyui Quartz 项目启动后输入:http://localhost/ 数据库文件:  ...

  8. Struts2+JSON+JQUERY DEMO

    看到别人用了Struts2和JSON,自己也想练练手.记录下练习过程中遇到的问题,以便参考. 使用Maven新建项目: 先挂上pom.xml <project xmlns="http: ...

  9. 如何屏蔽LOGD\LOGI等打印输出

    今天被打印信息的去除困扰了,想了想,如果靠一个一个的改动未免太繁琐.因此就仔细的看了下这部分的打印原理.当然下面只是简单的进行了知识罗列不过有需要的朋友可以随便看看.说不准会有些收获呢. Includ ...

  10. NDK(20)JNI的5大性能缺陷及优化技巧

    转自 : http://www.ibm.com/developerworks/cn/java/j-jni/index.html JNI 编程缺陷可以分为两类: 性能:代码能执行所设计的功能,但运行缓慢 ...