[关闭]
@994495jj 2017-07-23T01:48:47.000000Z 字数 1922 阅读 755

cfgym100729I

201707 (ACM)计算几何


题意

题解

代码

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define fi first
  4. #define se second
  5. #define pb push_back
  6. #define sz(a) (int)a.size()
  7. #define mp make_pair
  8. #define rep(i, a, b) for(int i=(a); i<(b); i++)
  9. typedef long long ll;
  10. typedef pair<int, int> pii;
  11. typedef vector<int> vi;
  12. //--------
  13. struct TPoint {
  14. ll x,y;
  15. };
  16. TPoint operator - (const TPoint &a,const TPoint &b) {
  17. TPoint res={a.x-b.x,a.y-b.y};
  18. return res;
  19. }
  20. bool operator < (const TPoint &a,const TPoint &b) {
  21. if(a.x==b.x) return a.y<b.y;
  22. return a.x<b.x;
  23. }
  24. double len(const TPoint &a) {
  25. return sqrt(a.x*a.x+a.y*a.y);
  26. }
  27. double dis(const TPoint &a,const TPoint &b) {
  28. return len(b-a);
  29. }
  30. ll cross(const TPoint &a,const TPoint &b,const TPoint &c) {
  31. return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
  32. }
  33. bool seg_inter(TPoint &a,TPoint &b,TPoint &c,TPoint &d) {
  34. return
  35. max(a.x,b.x)>=min(c.x,d.x) && max(c.x,d.x)>=min(a.x,b.x) &&
  36. max(a.y,b.y)>=min(c.y,d.y) && max(c.y,d.y)>=min(a.y,b.y) &&
  37. cross(a,b,c)*cross(a,b,d)<=0 &&
  38. cross(c,d,a)*cross(c,d,b)<=0;
  39. }
  40. set<int> s[20007];
  41. TPoint wl[15],wr[15];
  42. vector<TPoint> ans;
  43. int main() {
  44. int T;scanf("%d",&T);
  45. while(T--) {
  46. ///
  47. int n,r,w,m;scanf("%d%d%d%d",&n,&r,&w,&m);
  48. ///init
  49. rep(i,0,20007) s[i].clear();
  50. ///read
  51. rep(i,0,n) {
  52. int x,y;scanf("%d%d",&x,&y);
  53. s[x+10000].insert(y);
  54. }
  55. rep(i,0,w) {
  56. int a,b,c,d;scanf("%d%d%d%d",&a,&b,&c,&d);
  57. wl[i]={a,b};
  58. wr[i]={c,d};
  59. }
  60. ///solve
  61. while(m--) {
  62. ///init
  63. ans.clear();
  64. ///read
  65. int x,y;scanf("%d%d",&x,&y);
  66. ///solve
  67. TPoint p1={x,y};
  68. rep(i,-r,r+1) {
  69. int xx=x+i,yy=ceil(y-sqrt(r*r-i*i));
  70. int k=xx+10000;
  71. if(k<0||k>20000) continue;
  72. set<int>::iterator it = s[k].lower_bound(yy);
  73. while(it!=s[k].end()) {
  74. TPoint p2={xx,*it++};
  75. if(dis(p1,p2)>r) break;
  76. int x=0;
  77. rep(j,0,w) {
  78. if(seg_inter(p1,p2,wl[j],wr[j])) ++x;
  79. }
  80. if(dis(p1,p2)<=r-x) ans.pb(p2);
  81. }
  82. }
  83. sort(ans.begin(),ans.end());
  84. printf("%d ",sz(ans));
  85. rep(i,0,sz(ans)) {
  86. printf("(%lld,%lld) ",ans[i].x,ans[i].y);
  87. }
  88. puts("");
  89. }
  90. }
  91. return 0;
  92. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注