HDU5572 2015上海现场赛A题1001

  1 #include<iostream>
  2 #include<cstdio>
  3 #include<cstring>
  4 #include<queue>
  5 #include<map>
  6 #include<set>
  7 #include<cmath>
  8 using namespace std;
  9 typedef long long LL;
 10 const double eps = 1e-8;
 11 int sgn(double x) {
 12     if(fabs(x) < eps) return 0;
 13     if(x < 0) return -1;
 14     else return 1;
 15 }
 16 struct Point {
 17     double x, y;
 18     Point(double x = 0, double y = 0) : x(x), y(y) {}
 19     Point operator - (const Point& t) const {
 20         return Point(x - t.x, y - t.y);
 21     }
 22     double operator ^ (const Point& t) const {
 23         return x * t.y - y * t.x;
 24     }
 25     double operator * (const Point& t) const {
 26         return x * t.x + y * t.y;
 27     }
 28     Point operator * (const double& k) const {
 29         return Point(x * k, y * k);
 30     }
 31     Point operator / (const double& k) const {
 32         return Point(x / k, y / k);
 33     }
 34     Point operator + (const Point& t) const {
 35         return Point(x + t.x, y + t.y);
 36     }
 37     double distance(Point p) {
 38         return hypot(x - p.x, y - p.y);
 39     }
 40     double len() {
 41         return hypot(x, y);
 42     }
 43     double len2() {
 44         return x * x + y * y;
 45     }
 46     Point trunc(double r) {
 47         double l = len();
 48         if(!sgn(l)) return *this;
 49         r /= l;
 50         return Point(x * r, y * r);
 51     }
 52 };
 53 struct Line {
 54     Point s, e;
 55     Line() {}
 56     Line(Point s, Point e) {
 57         this->s = s; this->e = e;
 58     }
 59     double length() {
 60         return sqrt((s.x - e.x) * (s.x - e.x) + (s.y - e.y) * (s.y - e.y));
 61     }
 62     int relation(Point p) {
 63         int c = sgn((p - s) ^ (e - s));
 64         if(c < 0) return 1;
 65         else if(c > 0) return 2;
 66         else return 3;
 67     }
 68     double dispointtoline(Point p) {
 69         return fabs((p - s) ^ (e - s)) / length();
 70     }
 71     double dispointtoseg(Point p) {
 72         if(sgn((p - s) * (e - s)) < 0 || sgn((p - e) * (s - e)) < 0)
 73             return min(p.distance(s), p.distance(e));
 74         return dispointtoline(p);
 75     }
 76     Point lineprog(Point p) {
 77         return s + (((e - s) * ((e - s) * (p - s))) / ((e - s).len2()));
 78     }
 79     Point symmetrypoint(Point p) {
 80         Point q = lineprog(p);
 81         return Point(2 * q.x - p.x, 2 * q.y - p.y);
 82     }
 83 };
 84 struct Circle {
 85     Point p;
 86     double r;
 87     Circle(double x, double y, double r) {
 88         p  = Point(x, y);
 89         this->r = r;
 90     }
 91     int relationline(Line v) {
 92         double dst = v.dispointtoline(p);
 93         if(sgn(dst - r) < 0) return 2;
 94         else if(sgn(dst - r) == 0) return 1;
 95         else return 0;
 96     }
 97     int relationseg(Line v) {
 98         double dst = v.dispointtoseg(p);
 99         if(sgn(dst - r) < 0) return 2;
100         else if(sgn(dst - r) == 0) return 1;
101         else return 0;
102     }
103     int pointcrossline(Line v, Point& p1, Point& p2) {
104         if(!(*this).relationline(v)) return 0;
105         Point a = v.lineprog(p);
106         double d = v.dispointtoline(p);
107         d = sqrt(r * r - d * d);
108         if(sgn(d) == 0) {
109             p1 = a; p2 = a;
110             return 1;
111         }
112         p1 = a + (v.e - v.s).trunc(d);
113         p2 = a - (v.e - v.s).trunc(d);
114         return 2;
115     }
116 };
117 int main() {
118     int T; scanf("%d", &T);
119     int ca(1);
120     while(T--) {
121         int ox, oy, r;
122         int ax, ay, vx, vy;
123         int bx, by;
124         scanf("%d%d%d", &ox, &oy, &r);
125         scanf("%d%d%d%d", &ax, &ay, &vx, &vy);
126         scanf("%d%d", &bx, &by);
127         Line l(Point(ax, ay), Point(ax + vx, ay + vy));
128         Circle c(ox, oy, r);
129         Point d(bx, by);
130         Line t(Point(ax, ay), Point(bx, by));
131         if(l.relation(d) == 3 && c.relationseg(t) <= 1 && sgn(Point(bx - ax, by - ay) ^ Point(vx, vy)) == 0) printf("Case #%d: Yes\n", ca++);
132         else {
133             Point a, b;
134             if(c.pointcrossline(l, a, b) != 2) printf("Case #%d: No\n", ca++);
135             else {
136                 Point cut;
137                 if(a.distance(Point(ax, ay)) > b.distance(Point(ax, ay))) cut = b;
138                 else cut = a;
139                 Line mid(cut, c.p);
140                 Point en = mid.symmetrypoint(Point(ax, ay));
141                 Line aft(cut, en);
142                 if(aft.e.distance(d) > aft.s.distance(d)) swap(aft.s, aft.e);
143                 if(sgn((aft.e - aft.s) ^ Point(d.x - cut.x, d.y - cut.y)) == 0) printf("Case #%d: Yes\n", ca++);
144                 else printf("Case #%d: No\n", ca++);
145             }
146         }
147     }
148     return 0;
149 }

醉了,,现场读错题了,分反弹和不反弹两种情况讨论就好了,加点特判

时间: 2024-11-18 00:24:37

HDU5572 2015上海现场赛A题1001的相关文章

ACM学习历程—HDU5476 Explore Track of Point(平面几何)(2015上海网赛09题)

Problem Description In Geometry, the problem of track is very interesting. Because in some cases, the track of point may be beautiful curve. For example, in polar Coordinate system,ρ=cos3θ is like rose, ρ=1−sinθ is a Cardioid, and so on. Today, there

ACM/ICPC2015上海现场赛B题题解

给你一棵完全二叉树,初始能量为0,根节点编号为1(也就是说最左边那条路上节点的编号分别是2^0,2^1,2^2…2^(h-1)).从根节点开始往下走k-1步,走到每个节点选择加上或减去这个节点的编号,问走完这k个节点时能量恰好为n的方案.Special Judge. 在队友的提醒下(TAT我真是讨厌鹰语)看明白了数据范围,很明显是一个考二进制性质的题.于是一上手我先把样例改成了走最左路线的情况.样例出的蛮良心,一个奇数一个偶数,刚好对应两条路线:一直走左儿子或者走k-2个左儿子最后一个走右儿子.

hdu 5475 模拟计算器乘除 (2015上海网赛F题 线段树)

给出有多少次操作 和MOD 初始值为1 操作1 y 表示乘上y操作2 y 表示除以第 y次操作乘的那个数 线段树的叶子结点i 表示 第i次操作乘的数 将1替换成y遇到操作2 就把第i个结点的值 替换成1利用线段树的性质,对整个1~n的区间进行维护,每次输出sum[1]的值即可 Sample Input110 10000000001 22 11 21 102 32 41 61 71 122 7 Sample OutputCase #1:2122010164250484 1 # include <i

ACM学习历程—HDU5475 An easy problem(线段树)(2015上海网赛08题)

Problem Description One day, a useless calculator was being built by Kuros. Let's assume that number X is showed on the screen of calculator. At first, X = 1. This calculator only supports two types of operation. 1. multiply X with a number. 2. divid

HDUOJ-------2493Timer(数学 2008北京现场赛H题)

Timer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 445    Accepted Submission(s): 90 Problem Description Recently, some archaeologists discovered an ancient relic on a small island in the Pa

HDU 4791 Alice&#39;s Print Service(2013长沙区域赛现场赛A题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4791 解题报告:打印店提供打印纸张服务,需要收取费用,输入格式是s1 p1 s2 p2 s3 p3...表示打印区间s1到s2张纸的单价是p1,打印区间s2 到s3的单价是p2....最后是sn到无穷大的单价是pn,让你求打印k张纸的总费用最少是多少?有m次查询. 因为s1*p1 > s2 * p2 > s3*p3......,很显然,加入k所在的那个区间是第x个区间,那么最低费用要么是k * p

zoj 3819(牡丹江现场赛A题)

马上要去上海了,刷刷现场赛的题找找感觉~~~ 这题.......额,没什么好说的,太水.. ZOJ Problem Set - 3819 Average Score Time Limit: 2 Seconds      Memory Limit: 65536 KB Bob is a freshman in Marjar University. He is clever and diligent. However, he is not good at math, especially in Mat

2013 ACM/ICPC 长沙现场赛 A题 - Alice&#39;s Print Service (ZOJ 3726)

Alice's Print Service Time Limit: 2 Seconds      Memory Limit: 65536 KB Alice is providing print service, while the pricing doesn't seem to be reasonable, so people using her print service found some tricks to save money. For example, the price when

2015北京网络赛A题The Cats&#39; Feeding Spots

题意:给你一百个点,找个以这些点为中心的最小的圆,使得这个圆恰好包含了n个点,而且这个圆的边界上并没有点 解题思路:暴力枚举每个点,求出每个点到其他点的距离,取第n大的点,判断一下. 1 #include<cstdio> 2 #include<cmath> 3 #include<algorithm> 4 #include<iostream> 5 #include<memory.h> 6 using namespace std; 7 const i