标签:log init contain http 遍历 problem ant contains alt
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; typedef long long LL; const int N=40050; const int M=205; int R[M][M],U[M][M]; bool mp[M][M]; int dp[M][M],cnt[M][M]; int t[M][M]; int gcd(int a,int b) { return (b==0)?a:gcd(b,a%b); } void init() { for(int i=1;i<M;i++) for(int j=1;j<M;j++) { dp[i][j]=dp[i][j-1]+((gcd(i,j)==1)?1:0); cnt[i][j]=cnt[i-1][j]+dp[i][j]; } } int main() { init(); int T,Case=1; cin>>T; while(T--) { int n; scanf("%d",&n); memset(mp,0,sizeof(mp)); memset(U,0,sizeof(U)); memset(R,0,sizeof(R)); memset(t,0,sizeof(t)); for(int i=1;i<=n;i++) { int x,y; scanf("%d%d",&x,&y); mp[x][y]=1; } for(int i=200;i>=1;i--) { for(int j=200;j>=1;j--) { if(mp[i][j]){ if(mp[i+1][j]) U[i][j]=U[i+1][j]+1; if(mp[i][j+1]) R[i][j]=R[i][j+1]+1; } } } LL s=0; for(int i=1;i<=200;i++) { for(int j=1;j<=200;j++) { if(mp[i][j]){ s+=cnt[U[i][j]][R[i][j]]; int d=0; for(int k=U[i][j];k>=0;k--) { d+=dp[k][R[i][j]]; t[i+k][j]+=d; } } } } LL ans=0; for(int i=1;i<=200;i++) { for(int j=1;j<=200;j++) { if(mp[i][j]){ LL p=t[i][j]; LL pp=cnt[U[i][j]][R[i][j]]; p-=pp; for(int k=1;k<=R[i][j];k++) { p+=t[i][j+k]; ans+=2*p*dp[k][U[i][j]]; } ans+=pp*pp; } } } s=s*s-ans; printf("Case #%d: %lld\n",Case++,s); } return 0; }
标签:log init contain http 遍历 problem ant contains alt
原文地址:http://www.cnblogs.com/chen9510/p/7098256.html