2016-2017 Acm-icpc, NEERC, Northern subregional Contest problem I. Integral polygons

Source: Internet
Author: User

Title Source: http://codeforces.com/group/aUVPeyEnI2/contest/229510
Time limit: 2s
Space limit: 256MB
Main topic:
Given a convex polygon, there is a connection of two vertices to divide the polygon into two non-empty plots of an integer area, asking how many lines there are.
Data range:
4≤n≤200 000
? 109≤xi, yi≤109


#include <algorithm> #include <iostream> #include <cstring> #include <vector> #include < cstdio> #include <string> #include <cmath> #include <queue> #include <set> #include <map > #include <complex>using namespace std;typedef long long ll;typedef long double db;typedef pair<int,int> p Ii;typedef vector<int> VI; #define DE (x) cout << #x << "=" << x << endl#define Rep (i,a,b) for (int i=a;i< (b); ++i) #define ALL (x) (x). Begin (), (x). End () #define SZ (x) (int) (x). Size () #define MP Make_pair#define PB Push_back#define fi first#define se second#define pi acos ( -1.0) #define MEM0 (a) memset (A,0,sizeof (a)) #define MEMF (b) Memset (b,false,sizeof (b)) #define MAXN 401010int x[maxn],y[maxn];int va[maxn],pre[maxn],p[maxn][3][3][3];int across ( int A,int B,int C,int d) {return a*d-b*c;}    int main () {freopen ("integral.in", "R", stdin);    Freopen ("Integral.out", "w", stdout);    MEM0 (P);    MEM0 (pre);    int n; Cin>>n;        Rep (i,1,n+1) {cin>>x[i]>>y[i];        x[i]=x[i]&1;        y[i]=y[i]&1;        X[i+n]=x[i];    Y[i+n]=y[i];        } rep (i,1,n<<1|1) {Va[i]=across (x[i-1],y[i-1],x[i],y[i]);    Pre[i]=pre[i-1]+va[i];        } if (pre[n+1]&1) {cout<< "0" <<endl;    return 0;      }//Rep (i,1,n<<1|1)//{//printf ("%5d", X[i]);//}//cout<<endl;//Rep (i,1,n<<1|1)//{// printf ("%5d", Y[i]);//}//cout<<endl;//Rep (i,1,n<<1|1)//{//printf ("%5d", Pre[i]);//}//cout<&    Lt;endl;        Rep (i,1,n<<1|1) Rep (a,0,2) Rep (b,0,2) Rep (c,0,2) {if (x[i]==a&&y[i]==b&& (pre[i]&1) ==c)        p[i][a][b][c]=p[i-1][a][b][c]+1;    else P[i][a][b][c]=p[i-1][a][b][c]; }//cout<<endl;//Rep (i,1,n+1)//REP (a,0,2)//REP (b,0,2)//REP (c,0,2)//{//Prin TF ("%5d", P[i][a][b][c]);//}//cout<<endl;//}cout<<endl;    ll Ans=0;        Rep (i,1,n+1) {int l=i+2,r=n+i-2;            Rep (a,0,2) Rep (b,0,2) Rep (c,0,2) {int t= ((x[i]*b-y[i]*a+c-pre[i]) &1);        if (t==0) ans+=p[r][a][b][c]-p[l-1][a][b][c];//printf ("%5d", ans);    }//cout<<endl;    } cout<<ans/2<<endl; return 0;}

2016-2017 acm-icpc, NEERC, Northern subregional Contest problem I. Integral polygons

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.