live archive 5984 - Save the Students!
来源:互联网 发布:软件开发分为几个阶段 编辑:程序博客网 时间:2024/05/21 07:04
题意:给出多个三角形,圆,正方形,问他们覆盖的点的个数。点的横纵坐标都是整数
思路:从-50到100.枚举每一个点。看是否被覆盖:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <queue>using namespace std;const double PI = acos(-1.0);const double INF = 1e20 , EPS = 1E-6;bool zero(double x){ return -EPS<x&&x<EPS;}///向量struct cvector{ double x,y; cvector() {} cvector(double x,double y){ this->x=x,this->y=y; }};cvector operator +(cvector p,cvector q){ return cvector(p.x+q.x,p.y+q.y);}cvector operator -(cvector p,cvector q){ return cvector(p.x-q.x,p.y-q.y);}cvector operator *(double k,cvector p){ return cvector(k*p.x,k*p.y);}double operator *(cvector p,cvector q){ return p.x*q.x+p.y*q.y;}double operator^(cvector p,cvector q){ ///叉积 return p.x*q.y-q.x*p.y;}double length(cvector p){ ///向量的模 return sqrt(p*p);}cvector unit(cvector p){ ///单位化 return 1/length(p)*p;}double project(cvector p,cvector n){ ///p在n上投影(可负) return p*unit(n);}///点线struct cpoint{ double x,y; cpoint(){} cpoint(double x,double y){ this->x = x;this->y =y; }};struct cline{ cpoint a,b; cline(){} cline(cpoint a,cpoint b){ this->a=a;this->b=b; }};cvector operator -(cpoint a, cpoint b){ ///向量ab return cvector(b.x-a.x, b.y-a.y);}cpoint operator +(cpoint a, cvector p){ ///点a 沿向量p移动 return cpoint(a.x+p.x,a.y+p.y);}double dist(cpoint p, cpoint q){ ///两点间距离 return length(p-q);}double dist(cpoint p, cline l){ ///点与线的距离 return fabs((p-l.a)^(l.b-l.a))/length(l.b-l.a);}bool parallel(cline u,cline v){ ///线线平行或共线 return zero((u.a.x-u.b.x)*(v.a.y-v.b.y)-(v.a.x-v.b.x)*(u.a.y-u.b.y));}bool perpendicular(cline u,cline v){ ///线线垂直 return zero((u.b-u.a)^(v.b-v.a)) ;}bool dots_inline(cpoint p1,cpoint p2,cpoint p3){///判三点共线return zero((p2-p1)^(p3-p1));}cline parrllel(cpoint p, cline l){ ///过p点 作l平行线 return cline(p, p+(l.b-l.a));}cpoint rotate(cpoint b, cpoint a,double alpha){ ///a绕b旋转alpha角(弧度) cvector p=b-a; return cpoint(a.x+(p.x*cos(alpha)-p.y*sin(alpha)), a.y+(p.x*sin(alpha)+p.y*cos(alpha)));}cpoint foot(cpoint p, cline l){ ///过p点 作l垂足 return l.a+project(p-l.a,l.b-l.a)*unit(l.b-l.a);}cline vertical(cpoint p, cline l){ ///过p点 作l垂线 return cline(p,p+(rotate(l.b,l.a,PI/2)-l.a));}cpoint intersection(cline u,cline v){ ///线与线的交点 cpoint 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;}bool dot_onseg(cpoint p,cline ll){ /// 点在线段上 if(!dots_inline(p,ll.a,ll.b)) return false; cvector v1=ll.b-ll.a,v2=p-ll.a; cvector v3=ll.a-ll.b,v4=p-ll.b; if(v1*v2>-EPS&&v3*v4>-EPS) return true; return false;}bool same_side(cpoint p1,cpoint p2,cline l){ ///两点在线段同侧 cvector v0=l.b-l.a; cvector v1=p1-l.a,v2=p2-l.a; return (v1^v0)*(v2^v0)>EPS;}bool opposite_side(cpoint p1,cpoint p2,cline l){ ///两点在线段异侧 cvector v0=l.b-l.a; cvector v1=p1-l.a,v2=p2-l.a; return (v1^v0)*(v2^v0)<-EPS;}bool intersect_in(cline u,cline v){ ///线段相交,包括交点和重合 if(!dots_inline(u.a,u.b,v.a)||!dots_inline(u.a,u.b,v.b)) return !same_side(u.a,u.b,v)&&!same_side(v.a,v.b,u); return dot_onseg(u.a,v)||dot_onseg(u.b,v) ||dot_onseg(v.a,u)||dot_onseg(v.b,u);}bool intersect_ex(cline u,cline v){ ///线段相交,不包括交点和重合 return opposite_side(u.a,u.b,v)&&opposite_side(v.a,v.b,u);}cpoint ptoseg(cpoint p,cline l){ ///点到线段的最近点 cvector pt=l.b-l.a; cvector pa=l.a-p,pb=l.b-p; if((pt^pa)*(pt*pb)>EPS) return dist(p,l.a)<dist(p,l.b)?l.a:l.b; return foot(p,l);}double distptoseg(cpoint p,cline l){ ///点到线段的距离 cvector pt=l.b-l.a; cvector pa=l.a-p,pb=l.b-p; if((pt^pa)*(pt*pb)>EPS) return min(dist(p,l.a),dist(p,l.b)); return dist(p,l);}double length(double k){ if(k<0) return -k; return k;}int n;struct T{ cpoint a[3]; bool in(cpoint t) { // cout<<">> "<<length((a[2]-a[1])^(a[2]-a[0]))<<endl; if(length((a[1]-a[0])^(t-a[0]))+length((a[2]-a[0])^(t-a[0]))+length((a[1]-a[2])^(t-a[2]))-length((a[2]-a[1])^(a[2]-a[0]))>EPS) return false; return true; }}t[59];struct C{ cpoint a; double len; bool in(cpoint t) { if(length(a-t)-len>EPS) return false; return true; }} c[59];struct S{ cpoint a; double len; bool in(cpoint t) { if(t.x<a.x||t.x>a.x+len) return false; if(t.y<a.y||t.y>a.y+len) return false; return true; }} s[59];int ts=0,tt=0,tc=0;bool oor(int x,int y){ cpoint a = cpoint(x,y); for(int i=0;i<tt;i++) if(t[i].in(a)) return true; for(int i=0;i<ts;i++) if(s[i].in(a)) return true; for(int i=0;i<tc;i++) if(c[i].in(a)) return true; return false;}int main(){ //freopen("in.txt","r",stdin); int cas; scanf("%d",&cas); int x1,y1,l; char ch[3]; while(cas--) { int n; scanf("%d",&n); ts=0,tt=0,tc=0; for(int i=0;i<n;i++) { scanf("%s",ch); if(ch[0]=='C') { scanf("%d%d%d",&x1,&y1,&l); c[tc].a=cpoint(x1,y1); c[tc].len = l; tc++; } else if(ch[0]=='S') { scanf("%d%d%d",&x1,&y1,&l); s[ts].a=cpoint(x1,y1); s[ts].len = l; ts++; } else if(ch[0]=='T') { for(int j =0;j<3;j++) { scanf("%d%d",&x1,&y1); t[tt].a[j] = cpoint(x1,y1); }tt++; } } int ans=0; for(int i=-50;i<101;i++) for(int j=-50;j<101;j++) { if(oor(i,j)) ans++; } printf("%d\n",ans); } return 0;}
- live archive 5984 - Save the Students!
- UVA 5984 - Save the Students!
- UVALive 5984 Save the Students!(几何)
- Save the Students! UVALive
- 【点的定位】Save the Students! UVALive
- Live Archive 5659 The Last Puzzle
- uva 1401 && Live Archive 3942 Remember the Word
- Live archive 3938 "Ray,Pass me the Dishes"
- ACM/ICPC 2011 Asia-Amritapuri Site / B Save the Students!(判断点在三角形中)
- live archive 4212 - Candy
- live archive 4215 - Feynman
- live archive 3708
- Live Archive 2678 Subsequence
- Live Archive 6657
- Live Archive 6655
- Live Archive 3983 Robotruck
- Live Archive 4256 Salesmen
- Live Archive 4253 Archery
- XML学习笔记(一)
- shell 函数的返回值和退出状态
- ConcurrentModificationException(源码学习 Util包 集合)
- arch/arm/include/asm/io.h
- 无法获得锁 /var/lib/dpkg/lock - open (11: Resource temporarily unavailable) 解决办法
- live archive 5984 - Save the Students!
- C语言----函数和应用
- 使用 Crash 工具分析 Linux dump 文件
- 打开Word并插入图片
- http协议详解
- 中国制造VS国际品牌 耳熟能详游戏引擎比拼
- CStringList不完全用法
- 项目的js库只加载一次
- 右键打开方式无法添加程序