I can't do anything about this.
The practice of this question is quite simple.
Points in the lower-left corner of enumerationAs the origin, Sort the remaining points by the Polar Angle ps. is used as the origin. For example, when K is enumerated, for all P [I] (including P [k]) P [I]-= P [k] (this is vector subtraction)
After sorting, the cross product that satisfies the two vectors P [I] and P [J] of I <j is all positive numbers.
Σ p [I] × P [J] = Σ (P [I]. x * P [J]. y-P [I]. y * P [J]. x) = Σ (P [I]. x * Σ p [J]. y)-Σ (P [I]. y * Σ p [J]. x)
The complexity of computing the cross product is reduced from O (n2) to O (n)
With the complexity of enumeration and sorting, the total complexity is O (n2logn)
However, my code seems to be hated by bzoj. % >_< %
The local test is a, and the on-campus OJ is A, but bzoj is handed in for second wa, 55555555
Please instruct me ......
This is the wrong code, asking for advice
1 #include <cstdio> 2 #include <algorithm> 3 const int size=5000; 4 typedef struct point vector; 5 typedef long long llint; 6 7 namespace IOspace 8 { 9 inline int getint()10 {11 register int num=0;12 register char ch;13 do ch=getchar(); while (ch<‘0‘ || ch>‘9‘);14 do num=num*10+ch-‘0‘, ch=getchar(); while (ch>=‘0‘ && ch<=‘9‘);15 return num;16 }17 inline void putint(llint num, char ch=‘\n‘)18 {19 char stack[20];20 register int top=0;21 if (num==0) stack[top=1]=‘0‘;22 for ( ;num;num/=10) stack[++top]=num%10+‘0‘;23 for ( ;top;top--) putchar(stack[top]);24 if (ch) putchar(ch);25 }26 }27 28 struct point29 {30 llint x, y;31 inline point() {}32 inline point(llint _x, llint _y):x(_x), y(_y) {}33 inline vector & operator += (vector v) {x+=v.x; y+=v.y; return *this;}34 inline vector & operator -= (vector v) {x-=v.x; y-=v.y; return *this;}35 };36 point p[size];37 inline llint operator * (vector a, vector b) {return a.x*b.y-a.y*b.x;}38 inline bool operator < (point a, point b) {return a*b>0;}39 inline void swap(point & a, point & b) {point t=a; a=b; b=t;}40 41 int N;42 inline llint count(int);43 44 int main()45 {46 llint ans=0;47 48 N=IOspace::getint();49 for (int i=1;i<=N;i++) p[i].x=IOspace::getint(), p[i].y=IOspace::getint();50 51 for (int i=N;i>=1;i--) ans+=count(i);52 53 bool b=ans&1LL;54 IOspace::putint(ans>>1LL, ‘.‘);55 IOspace::putint(b?5:0);56 57 return 0;58 }59 inline llint count(int n)60 {61 llint ret=0;62 63 int k=1;64 for (int i=1;i<=n;i++)65 if (p[i].x<p[k].x || p[i].x==p[k].x && p[i].y<p[k].y)66 k=i;67 swap(p[k], p[n]);68 69 for (int i=1;i<=n;i++) p[i]-=p[n];70 71 std::sort(p+1, p+n);72 73 vector s(0, 0);74 for (int i=1;i<=n;i++)75 {76 ret+=s*p[i];77 s+=p[i];78 }79 80 return ret;81 }This silly Series
Let me put the correct information to help you understand the problem:
1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 using namespace std; 5 6 #define maxn 30010 7 typedef long long ll; 8 struct xllend3 9 {10 int x,y;11 } orz[maxn];12 13 int n,m;14 ll ans;15 16 bool cmp(const xllend3 &a,const xllend3 &b)17 {18 return a.x*b.y>a.y*b.x;19 }20 ll orzhzw(int n)21 {22 int i=0;23 for (int j=0;j<n;j++)24 if (orz[j].x<orz[i].x||(orz[j].x==orz[i].x && orz[j].y<orz[i].y))25 i=j;26 swap(orz[i],orz[n-1]);27 for (int i=0;i<n-1;i++)28 orz[i].x-=orz[n-1].x,orz[i].y-=orz[n-1].y;29 sort(orz,orz+n-1,cmp);30 ll gui=0;31 ll sx=0,sy=0;32 for (int i=n-2;i>=0;i--)33 {34 gui+=(ll)orz[i].x*sy-(ll)orz[i].y*sx;35 sx+=orz[i].x;36 sy+=orz[i].y;37 }38 return gui;39 }40 41 int main()42 {43 scanf("%d",&n);44 for (int i=0;i<n;i++) scanf("%d%d",&orz[i].x,&orz[i].y);45 for (int i=n;i>2;i--) ans+=orzhzw(i);46 cout<<ans/2;47 if (ans&1) cout<<".5"<<endl;else cout<<".0"<<endl;48 return 0;49 }Orz mxh1999