poj 3348 Cows

Bertha 。 2023-10-09 12:40 191阅读 0赞

题目衔接:http://poj.org/problem?id=3348














Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 12485   Accepted: 5418

Description

Your friend to the south is interested in building fences and turning plowshares into swords. In order to help with his overseas adventure, they are forced to save money on buying fence posts by using trees as fence posts wherever possible. Given the locations of some trees, you are to help farmers try to create the largest pasture that is possible. Not all the trees will need to be used.

However, because you will oversee the construction of the pasture yourself, all the farmers want to know is how many cows they can put in the pasture. It is well known that a cow needs at least 50 square metres of pasture to survive.

Input

The first line of input contains a single integer, n (1 ≤ n ≤ 10000), containing the number of trees that grow on the available land. The next n lines contain the integer coordinates of each tree given as two integers x and y separated by one space (where -1000 ≤ x, y ≤ 1000). The integer coordinates correlate exactly to distance in metres (e.g., the distance between coordinate (10; 11) and (11; 11) is one metre).

Output

You are to output a single integer value, the number of cows that can survive on the largest field you can construct using the available trees.

Sample Input

  1. 4
  2. 0 0
  3. 0 101
  4. 75 0
  5. 75 101

Sample Output

  1. 151

题目大意:给你n个点,问你这n个点中的其中某些点所能组成的最大的多边形的面积

思路:凸包模板题,扫一下发现是哪些点作为顶点,然后使用三角形叉积求面即可

代码:

  1. /*
  2. 题目大意:现在给你n个点,让你使用这些点构成一个面积尽可能大的多边形,注意这些点不是会被全部使用
  3. 思路:凸包,直接求面积即可
  4. */
  5. #include<set>
  6. #include<map>
  7. #include<ctime>
  8. #include<stack>
  9. #include<queue>
  10. #include<cmath>
  11. #include<string>
  12. #include<vector>
  13. #include<cstdio>
  14. #include<cstring>
  15. #include<cstdlib>
  16. #include<iostream>
  17. #include<algorithm>
  18. using namespace std;
  19. typedef long long ll;
  20. #define inf 0x3f3f3f
  21. #define bug printf("bug\n")
  22. const int maxn=1e6+10;
  23. const double pi=acos(-1.0);
  24. const double esp=1e-6;
  25. const int N=2e2+10;
  26. struct point
  27. {
  28. int x,y;
  29. };
  30. struct line
  31. {
  32. point st,ed;
  33. double k,b;
  34. };
  35. int sign(double x)
  36. {
  37. if(fabs(x)<esp)
  38. return 0;
  39. return x>0?1:-1;
  40. }
  41. double getk(line l)
  42. {
  43. if(l.st.x==l.ed.x)///斜率不存在
  44. return inf;
  45. return (l.ed.y-l.st.y)/(l.ed.x-l.st.x);
  46. }
  47. double getb(line l)
  48. {
  49. return l.ed.y-l.k*l.ed.x;
  50. }
  51. double dis(point a,point b)
  52. {
  53. return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
  54. }
  55. int cmult(point a,point b,point c)///叉积
  56. {
  57. return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
  58. }
  59. point p[maxn];
  60. int cmp(point a,point b)
  61. {
  62. int ju=cmult(p[0],a,b);
  63. if(ju>0)return 1;
  64. else if(ju==0&&dis(a,p[0])<dis(b,p[0]))return 1;
  65. return 0;
  66. }
  67. int n;
  68. int Stack[maxn],top;
  69. void tb()
  70. {
  71. point p0;
  72. int k=0;
  73. p0=p[0];
  74. for(int i=1;i<n;i++)
  75. {
  76. if(p0.y>p[i].y||(p0.y==p[i].y&&p0.x==p[i].x))
  77. {
  78. p0=p[i];
  79. k=i;
  80. }
  81. }
  82. swap(p[k],p[0]);
  83. sort(p+1,p+n,cmp);
  84. if(n==1)
  85. {
  86. top=0;
  87. Stack[0]=0;
  88. return ;
  89. }
  90. if(n==2)
  91. {
  92. top=1;
  93. Stack[0]=0;
  94. Stack[1]=1;
  95. return;
  96. }
  97. if(n>2)
  98. {
  99. top=1;
  100. for(int i=0;i<=1;i++)
  101. Stack[i]=i;
  102. for(int i=2;i<n;i++)
  103. {
  104. while(top>0&&cmult(p[Stack[top-1]],p[Stack[top]],p[i])<=0)
  105. top--;
  106. top++;
  107. Stack[top]=i;
  108. }
  109. }
  110. }
  111. int main()
  112. {
  113. while(scanf("%d",&n)!=EOF)
  114. {
  115. for(int i=0;i<n;i++)
  116. {
  117. scanf("%d%d",&p[i].x,&p[i].y);
  118. }
  119. tb();
  120. int ans=0;
  121. for(int i=1;i<top;i++)
  122. {
  123. ans+=abs(cmult(p[Stack[0]],p[Stack[i]],p[Stack[i+1]]));
  124. }
  125. printf("%d\n",ans/100);
  126. }
  127. return 0;
  128. }

发表评论

表情:
评论列表 (有 0 条评论,191人围观)

还没有评论,来说两句吧...

相关阅读