Cows
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 7739   Accepted: 3507

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

题意是给出各个树的位置,用这些树可以围出一块最大的面积,一头牛需要50平方米的面积,问这些树围出的面积可以养多少头牛。

先构造凸包,在求出凸包围成的面积,最后除以50求整。

代码:

  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cmath>
  4. #include <vector>
  5. #include <string>
  6. #include <cstring>
  7. #pragma warning(disable:4996)
  8. using namespace std;
  9.  
  10. struct no
  11. {
  12. int x, y;
  13. }node[10005];
  14.  
  15. int n;
  16. int conbag[10005];
  17.  
  18. no orign;//原点
  19.  
  20. int dis(no n1, no n2)
  21. {
  22. return (n1.x - n2.x)*(n1.x - n2.x) + (n1.y - n2.y)*(n1.y - n2.y);
  23. }
  24.  
  25. int xmult(int x1, int y1, int x2, int y2)
  26. {
  27. return x1*y2 - x2*y1;
  28. }
  29.  
  30. int Across(no n1, no n2, no n3, no n4)
  31. {
  32. return xmult(n2.x - n1.x, n2.y - n1.y, n4.x - n3.x, n4.y - n3.y);
  33. }
  34.  
  35. int cmp(const void* n1, const void* n2)
  36. {
  37. int temp = Across(orign, *(no *)n1, orign, *(no *)n2);
  38.  
  39. if (temp > 0)
  40. {
  41. return -1;
  42. }
  43. else if (temp == 0)
  44. {
  45. return (dis(orign, *(no *)n1) - dis(orign, *(no *)n2));
  46. }
  47. else
  48. {
  49. return 1;
  50. }
  51. }
  52.  
  53. int main()
  54. {
  55.  
  56. int i, j, k, min_x, pos_x;
  57. double sum;
  58. while (scanf("%d", &n) != EOF)
  59. {
  60. min_x = 1005;
  61. for (i = 1; i <= n; i++)
  62. {
  63. cin >> node[i].x >> node[i].y;
  64. if (node[i].x < min_x)
  65. {
  66. min_x = node[i].x;
  67. pos_x = i;
  68. }
  69. else if (min_x == node[i].x&&node[i].y < node[pos_x].y)
  70. {
  71. pos_x = i;
  72. }
  73. }
  74. orign = node[pos_x];
  75. qsort(node + 1, n, sizeof(no), cmp);
  76.  
  77. int pc = 1;
  78. conbag[1] = 1;
  79. conbag[++pc] = 2;
  80. conbag[0] = 2;
  81.  
  82. i = 3;
  83. while (i <= n)
  84. {
  85. if (Across(node[conbag[pc - 1]], node[conbag[pc]], node[conbag[pc]], node[i]) >= 0)
  86. {
  87. conbag[++pc] = i++;
  88. conbag[0]++;
  89. }
  90. else
  91. {
  92. pc--;
  93. conbag[0]--;
  94. }
  95. }
  96.  
  97. if (n < 3 || conbag[0]<3)
  98. {
  99. cout << 0 << endl;
  100. }
  101. else
  102. {
  103. sum = 0;
  104. for (i = 1; i + 1 <= conbag[0]; ++i)
  105. {
  106. sum += abs((node[conbag[i]].x * node[conbag[(i + 1)]].y - node[conbag[i]].y * node[conbag[(i + 1)]].x));
  107. }
  108. sum += abs((node[conbag[i]].x * node[1].y - node[conbag[i]].y * node[1].x));
  109. sum = sum / 2.0;
  110. cout << (int)(sum / 50) << endl;
  111. }
  112. }
  113. return 0;
  114. }

版权声明:本文为博主原创文章,未经博主允许不得转载。

POJ 3348:Cows 凸包+多边形面积的更多相关文章

  1. POJ 3348 Cows 凸包 求面积

    LINK 题意:给出点集,求凸包的面积 思路:主要是求面积的考察,固定一个点顺序枚举两个点叉积求三角形面积和除2即可 /** @Date : 2017-07-19 16:07:11 * @FileNa ...

  2. poj3348 Cows 凸包+多边形面积 水题

    /* poj3348 Cows 凸包+多边形面积 水题 floor向下取整,返回的是double */ #include<stdio.h> #include<math.h> # ...

  3. poj 3348 Cows 凸包 求多边形面积 计算几何 难度:0 Source:CCC207

    Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7038   Accepted: 3242 Description ...

  4. POJ 3348 - Cows 凸包面积

    求凸包面积.求结果后不用加绝对值,这是BBS()排序决定的. //Ps 熟练了template <class T>之后用起来真心方便= = //POJ 3348 //凸包面积 //1A 2 ...

  5. POJ 3348 Cows (凸包模板+凸包面积)

    Description Your friend to the south is interested in building fences and turning plowshares into sw ...

  6. POJ 3348 Cows [凸包 面积]

    Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9022   Accepted: 3992 Description ...

  7. POJ 3348 Cows | 凸包模板题

    题目: 给几个点,用绳子圈出最大的面积养牛,输出最大面积/50 题解: Graham凸包算法的模板题 下面给出做法 1.选出x坐标最小(相同情况y最小)的点作为极点(显然他一定在凸包上) 2.其他点进 ...

  8. POJ 3348 Cows | 凸包——童年的回忆(误)

    想当年--还是邱神给我讲的凸包来着-- #include <cstdio> #include <cstring> #include <cmath> #include ...

  9. poj 3348 Cow 凸包面积

    Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8122   Accepted: 3674 Description ...

随机推荐

  1. 「JSOI2014」矩形并

    「JSOI2014」矩形并 传送门 我们首先考虑怎么算这个期望比较好. 我们不难发现每一个矩形要和 \(n - 1\) 个矩形去交,而总共又有 \(n\) 个矩形,所以我们把矩形两两之间的交全部加起来 ...

  2. 第七届蓝桥杯javaB组真题解析-方格填数(第六题)

    题目 /* 方格填数 如下的10个格子 +--+--+--+ | | | | +--+--+--+--+ | | | | | +--+--+--+--+ | | | | +--+--+--+ (如果显 ...

  3. Nessus忘记用户名和密码

    以管理员身份运行cmd,切换到Nessus的安装目录,执行以下操作.

  4. python 的参数总结

    一.形参和实参 函数参数的作用是传递数据给函数使用 在使用的过程中,参数有两种形式:形式参数和实际参数 形参: 定义函数的参数 实参: 调用函数时的参数 根据实际参数类型不同,将实际参数传递给形参的方 ...

  5. C语言的变量存储方式和生存期

    2020.2.28日,封城一个多月了,紧邻毕业期,我在家抽空学习一下C. 看到了变量的存储方式和生存期这一章节,下面就是我整理的内容 下面是用于理解静态局部变量这个概念所写的代码,主要是需要分析一下函 ...

  6. 执行SQL时出现: ORDER BY clause is not in GROUP BY clause and contains nonaggregated c

    注意: 采用navicat新建数据库时,需要将编码方式设置为,字符集:utf8 -- UTF-8 Unicode ,排序规则:utf8_general_ci 在运行sql语句时,出现以下问题: [Er ...

  7. 好用的log打印类

    package com.huawei.network.ott.weixin.util; import android.util.Log; public final class DebugLog { / ...

  8. 浏览器输入URL后HTTP请求返回的完整过程

    图:

  9. Golang 如何交叉编译

    Golang 支持交叉编译,即在一个平台上生成另一个平台的可执行程序.方法如下: Mac 下编译 Linux 和 Windows 64位可执行程序 CGO_ENABLED=0 GOOS=linux G ...

  10. 3676: [Apio2014]回文串 求回文串长度与出现次数的最大值

    「BZOJ3676」[Apio2014] 回文串   Description 考虑一个只包含小写拉丁字母的字符串s.我们定义s的一个子串t的“出 现值”为t在s中的出现次数乘以t的长度.请你求出s的所 ...