1334.Jason's Water Problem
Description
Calculus is the first lesson Jason had. It is tedious, so an interesting idea occurred to Jason. He took out his mobile phone and open the HDUOJ and found a water problem. He said to himself, “I must solve this f**king easy water problem in ten minutes! ”.
You were invited to compete with him online. Don’t be defeated.
Multiple test cases, Each test first contains an integer N(3<=N<=100000) indicating the number of vertices of the polygon. The i-th of the following N lines contains two integers xi and yi (0<=xi,yi<=10^9) separated by a blank. (xi,yi) is the i-th vertex of the polygon, and (x1,y1),...,(xn,yn) will be in counterclockwise order.
For each test case, output a number as the answer which is the area of the polygon be multiplied by 2. In case the answer is greater than 1000000006, please modulo the answer with 1000000007.
3
0 0
1 0
0 1
4
0 0
1 0
1 1
0 1
Sample Output
1
2
逆时针顺序给出一个多边形的顶点,求这个多边形的面积,直接套用公式,向量叉积来求就可,即S=x1*y2-x2*y1+...+xn*y1-x1*yn,不过不知道SDNU的OJ是什么情况,最后一步的时候不mod就能过,mod就过不了.....不应该没什么区别么= =
下面AC代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<math.h>
using namespace std;
const long long mod=1000000007;
struct point
{
long long x;
long long y;
};
point p[100005];
long long f(point a,point b)
{
return a.x*b.y-a.y*b.x;
}
int main()
{
int n;
int i;
long long s;
while(scanf("%d",&n)!=EOF)
{
scanf("%lld%lld",&p[1].x,&p[1].y);
s=0;
for(i=2;i<=n;i++)
{
scanf("%lld%lld",&p[i].x,&p[i].y);
s=s+f(p[i-1],p[i])%mod;
s=s%mod;
}
s=s+f(p[n],p[1]);
s=abs(s)%mod;
cout<<s<<endl;
}
return 0;
}