"BZOJ1132" "POI2008" Tro calculate the area of geometric cross product

Source: Internet
Author: User

Link:
#include <stdio.h>int main(){    puts("转载请注明出处[辗转山河弋流歌 by 空灰冰魂]谢谢");    puts("网址:blog.csdn.net/vmurder/article/details/46605807");}
Exercises

First, violence is O ( n 3 ) Ask for each triangle area!
But how do you ask for triangular area? In general, we use cross-product ... Wait a minute? That one cross product is not to be counted many times?

Well, it is solved, first ordered order to ensure that the order is not heavy, and then calculate the contribution of each cross product, that is, the contribution of each side, and then because of the order of what, the complexity of time O( n 2 Log N) 。

And then this problem. Uh, card accuracy ...?!
To cross the product, the last thing to be divided by 2,, first, not to divide, to the end of a special sentence qwq

Code:
#include <cmath>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define N 3010using namespace STD;structpoint{Long Longx, y;voidRead () {scanf("%lld%lld", &x,&y);}} Now,p[n],tp[n];inline Long LongXmul (Point b,point c,point a=now) {return(C.Y-A.Y) * (b.x-a.x)-(B.Y-A.Y) * (c.x-a.x);}BOOLCmpxy (Point A,point B) {returnA.x==b.x? a.y<b.y:a.x<b.x;}BOOLCMPMU (Point A,point B) {returnXmul (b) >0;}intNLong LongAnsintMain () {Freopen ("Test.in","R", stdin);intI,j,k;Long LongSumx,sumy;scanf("%d", &n); for(i=1; i<=n;i++) P[i].read (); Sort (p+1, p+n+1, CMPXY); for(i=1; i<=n-2; i++) {now=p[i]; sumx=sumy=0; for(j=i+1; j<=n;j++) Tp[j]=p[j]; Sort (tp+i+1, tp+n+1, CMPMU); for(j=i+1; j<=n;j++) {sumx+=tp[j].x-now.x;        SUMY+=TP[J].Y-NOW.Y; } for(j=i+1; J <n;j++) {sumx-=tp[j].x-now.x;            SUMY-=TP[J].Y-NOW.Y;            ans+= (tp[j].x-now.x) *sumy;        ans-= (TP[J].Y-NOW.Y) *sumx; }    }if(ans&1)printf("%lld.5\n",ans>>1);Else printf("%lld.0\n",ans>>1);return 0;}

"BZOJ1132" "POI2008" Tro calculate the area of geometric cross product

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.