JD_Source Code for problem 1259

来源:互联网 发布:海盗湾电影源码 编辑:程序博客网 时间:2024/06/06 16:48

题目链接:http://acm.jlu.edu.cn/joj/showproblem.php?pid=1259

  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. struct Point
  5. {
  6. double x;
  7. double y;
  8. };
  9.  
  10. struct Figure
  11. {
  12. char type;
  13. Point p1;
  14. Point p2;
  15. double r;
  16. };
  17.  
  18. Figure fig[11];
  19. Point pt[100];
  20.  
  21.  
  22. bool In(const Point& p,const Figure& f)
  23. {
  24. if(f.type == 'r')
  25. {
  26. if(p.x > f.p1.x && p.x < f.p2.x && p.y > f.p2.y && p.y < f.p1.y)
  27. return true;
  28. return false;
  29. }
  30. else
  31. {
  32. if(sqrt((p.x -f.p1.x) * (p.x -f.p1.x) + (p.y - f.p1.y) * (p.y - f.p1.y)) < f.r)
  33. return true;
  34. return false;
  35. }
  36. }
  37.  
  38. int main(int argc, char* argv[])
  39. {
  40. int f_count,p_count;
  41. f_count = 0;
  42. while(true)
  43. {
  44. if(scanf("%c",&fig[f_count].type) == EOF)
  45. return 0;
  46. else if(fig[f_count].type == '*')
  47. break;
  48. else if(fig[f_count].type == 'r')
  49. scanf("%lf%lf%lf%lf",&fig[f_count].p1.x,&fig[f_count].p1.y,
  50. &fig[f_count].p2.x,&fig[f_count].p2.y);
  51. else
  52. scanf("%lf%lf%lf",&fig[f_count].p1.x,&fig[f_count].p1.y,&fig[f_count].r);
  53. getchar();
  54. f_count++;
  55. }
  56.  
  57. p_count = 0;
  58. while(true)
  59. {
  60. if(scanf("%lf%lf",&pt[p_count].x,&pt[p_count].y) == EOF)
  61. return 0;
  62. else if(fabs(pt[p_count].x - 9999.9) < 1e-6 && fabs(pt[p_count].y - 9999.9) < 1e-6)
  63. break;
  64. p_count++;
  65. }
  66.  
  67. int i,j;
  68. bool in;
  69. for(i = 0;i < p_count;i++)
  70. {
  71. in = false;
  72. for(j = 0;j < f_count;j++)
  73. if(In(pt[i],fig[j]))
  74. {
  75. printf("Point %d is contained in figure %d/n",i + 1,j + 1);
  76. in = true;
  77. }
  78. if(!in)
  79. printf("Point %d is not contained in any figure/n",i + 1);
  80. }
  81. return 0;
  82. }
原创粉丝点击