lightoj1418Trees on My Island【pick公式】
2015-10-11 01:53
369 查看
Q - Trees on My Island
Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu
Submit Status Practice LightOJ
1418
Description
I have bought an island where I want to plant trees in rows and columns. So, the trees will form a rectangular grid and each of them can be thought of having integer coordinates by taking a suitable grid point as the origin.
But, the problem is that the island itself is not rectangular. So, I have identified a simple polygonal area inside the island with vertices on the grid points and have decided to plant trees on grid points lying strictly inside the polygon.
![](http://7xjob4.com1.z0.glb.clouddn.com/22c3439ced99fabea7ba7f099527fc45)
Figure: A sample of my island
For example, in the above figure, the green circles form the polygon, and the blue circles show the position of the trees.
Now, I seek your help for calculating the number of trees that can be planted on my island.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case starts with a line containing an integer N (3 ≤ N ≤ 10000) denoting the number of vertices of the polygon. Each of the next N lines contains two integers xi yi(-106 ≤ xi,
yi ≤ 106) denoting the co-ordinate of a vertex. The vertices will be given in clockwise or anti-clockwise order. And they will form a simple polygon.
Output
For each case, print the case number and the total number of trees that can be planted inside the polygon.
Sample Input
1
9
1 2
2 1
4 1
4 3
6 2
6 4
4 5
1 5
2 3
Sample Output
Case 1: 8
题意:求多边形内的点数
解题思路:pick公式
Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu
Submit Status Practice LightOJ
1418
Description
I have bought an island where I want to plant trees in rows and columns. So, the trees will form a rectangular grid and each of them can be thought of having integer coordinates by taking a suitable grid point as the origin.
But, the problem is that the island itself is not rectangular. So, I have identified a simple polygonal area inside the island with vertices on the grid points and have decided to plant trees on grid points lying strictly inside the polygon.
Figure: A sample of my island
For example, in the above figure, the green circles form the polygon, and the blue circles show the position of the trees.
Now, I seek your help for calculating the number of trees that can be planted on my island.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case starts with a line containing an integer N (3 ≤ N ≤ 10000) denoting the number of vertices of the polygon. Each of the next N lines contains two integers xi yi(-106 ≤ xi,
yi ≤ 106) denoting the co-ordinate of a vertex. The vertices will be given in clockwise or anti-clockwise order. And they will form a simple polygon.
Output
For each case, print the case number and the total number of trees that can be planted inside the polygon.
Sample Input
1
9
1 2
2 1
4 1
4 3
6 2
6 4
4 5
1 5
2 3
Sample Output
Case 1: 8
题意:求多边形内的点数
解题思路:pick公式
#include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> #include<cmath> using namespace std; struct point{ long long x,y; }A[10010]; long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b); } int main() { long long t,k=1,n,i,j; scanf("%lld",&t); while(t--){ scanf("%lld",&n); for(i=0;i<n;++i){ scanf("%lld%lld",&A[i].x,&A[i].y); } long long dot=0,S=0; for(i=0;i<n;++i){ dot+=gcd(abs(A[(i+1)%n].x-A[i].x),abs(A[(i+1)%n].y-A[i].y)); S+=A[(i+1)%n].y*A[i].x-A[i].y*A[(i+1)%n].x; } printf("Case %lld: %lld\n",k++,(abs(S)+2-dot)/2); } return 0; }
相关文章推荐
- On Error Resume Next 语句
- 简单对比分析Ruby on Rails 和 Laravel
- VBScript中On Error语句用法小结
- 解析sql语句中left_join、inner_join中的on与where的区别
- INSERT INTO .. ON DUPLICATE KEY更新多行记录
- win7安装ruby on rails开发环境
- jQuery事件绑定.on()简要概述及应用
- jQuery中on()方法用法实例详解
- jQuery中delegate与on的用法与区别示例介绍
- mysql ON DUPLICATE KEY UPDATE语句示例
- List all the Databases on a SQL Server
- 用实际代码演示Ruby的容易被误解的6个特性
- 深入Oracle的left join中on和where的区别详解
- jQuery中delegate和on的用法与区别详细解析
- Apache No space left on device: mod_rewrite: could not create rewrite_log_lock Configuration Failed
- apache You don't have permission to access /test.php on this server解决方法
- nginx: [warn] "log_format" directive used only on "http" level 解决方法
- Auto Layout on iOS Versions prior to 6.0 解决办法
- Window7上安装Ruby on Rails
- 编译安装mod_jk on centOS