tjut 4643
来源:互联网 发布:高中教学视频 淘宝网 编辑:程序博客网 时间:2024/06/10 18:36
#include <cstdio>#include <cmath>const double eps = 1e-8;inline int dcmp(double x) { if(fabs(x) < eps) return 0; return x > eps ? 1 : -1;}struct point { double x, y; point(double x, double y) : x(x), y(y) { } point() { } point operator+(const point &t) const { return point(x + t.x, y + t.y); } point operator-(const point &t) const { return point(x - t.x, y - t.y); } point operator*(const double &t) const { return point(x*t, y*t); } inline void in() { scanf("%lf%lf", &x, &y); }} sta[55], city[55], tt, tp;struct line { point a, b; line(point a, point b) : a(a), b(b) { } line() { }} l[50][50];int n, m, k;inline line getMidLine(const point &a, const point &b) { point mid = (a + b) *0.5; point tp = b-a; return line(mid, mid+point(-tp.y, tp.x));}inline double cross(const point &a, const point &b) { return a.x*b.y-a.y*b.x;}inline point intersect(const point &a, const point &b, const point &l, const point &r) { point ret = a; double t = ((a.x - l.x) * (l.y - r.y) - (a.y - l.y) * (l.x - r.x)) / ((a.x - b.x) * (l.y - r.y) - (a.y - b.y) * (l.x - r.x)); ret.x += (b.x - a.x) * t; ret.y += (b.y - a.y) * t; return ret;}inline bool dotOnSeg(const point &p, const point &l, const point &r) { //判点在线段上 return (p.x-l.x)*(p.x-r.x) < eps && (p.y-l.y)*(p.y-r.y) < eps;}inline double dis(const point &a, const point &b) { return sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));}inline bool judge(const point &p, int &a) { double d = dis(p, sta[a]); int i; for(i = 0; i < m; i++) if(i != a) if(d > dis(p, sta[i])+eps) return 0; return 1;}int a, b, ans;int main() { int i, j; while (~scanf("%d%d", &n, &m)) { for (i = 0; i < n; i++) city[i].in(); for (i = 0; i < m; i++) sta[i].in(); for (i = 0; i < m; i++) for (j = i + 1; j < m; j++) l[i][j] = getMidLine(sta[i], sta[j]); scanf("%d", &k); while(k--) { ans = 0; scanf("%d%d", &a, &b); a--; b--; tt = city[a]-city[b]; for(i = 0; i < m; i++) for(j = i+1; j < m; j++) { if(!dcmp(cross(tt, l[i][j].a-l[i][j].b))) continue; tp = intersect(city[a], city[b], l[i][j].a, l[i][j].b); if(dotOnSeg(tp, city[a], city[b])) ans += judge(tp, i); } printf("%d\n", ans); } } return 0;}
0 0
- tjut 4643
- tjut 5289
- tjut 5288
- tjut 5294
- tjut 2586
- tjut 5296
- tjut 5297
- tjut 5299
- tjut 5384
- tjut 5387
- tjut 5386
- tjut 5381
- tjut 5400
- tjut 5399
- tjut 5396
- tjut 5398
- tjut 5412
- tjut 5410
- linux下Ping工具的C语言实现
- Android-从音频文件中获取专辑图片
- Web URL中对特殊字符的处理
- 获取网络视频缩略图
- 简单贪心算法问题--找零钱
- tjut 4643
- redis:info详解
- Git git pull error
- C 内存管理详解
- 用file类进行单文件上传
- iOS开发:捕获程序崩溃
- OpenCV3.0.0下的视频稳像代码,效果不错哦!
- SQL Server中用While循环替代游标(Cursor)的解决方案
- python join 和 split方法的使用