JD_Source Code for problem 1259

题目链接: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. }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值