标签:
神题......
还是大神讲得比较清晰~orz
http://dffxtz.logdown.com/posts/197950-noi2013-vector-inner-product
启发题:poj3318
#include<cstdio> #include<cstdlib> #include<iostream> #include<fstream> #include<algorithm> #include<cstring> #include<string> #include<cmath> #include<queue> #include<stack> #include<map> #include<utility> #include<set> #include<bitset> #include<vector> #include<functional> #include<deque> #include<cctype> #include<climits> #include<complex> //#include<bits/stdc++.h>适用于CF,UOJ,但不适用于poj #include<ctime> using namespace std; typedef long long LL; typedef double DB; typedef pair<int,int> PII; typedef complex<DB> CP; #define mmst(a,v) memset(a,v,sizeof(a)) #define mmcy(a,b) memcpy(a,b,sizeof(a)) #define re(i,a,b) for(i=a;i<=b;i++) #define red(i,a,b) for(i=a;i>=b;i--) #define fi first #define se second #define m_p(a,b) make_pair(a,b) #define SF scanf #define PF printf #define two(k) (1<<(k)) template<class T>inline T sqr(T x){return x*x;} template<class T>inline void upmin(T &t,T tmp){if(t>tmp)t=tmp;} template<class T>inline void upmax(T &t,T tmp){if(t<tmp)t=tmp;} const DB EPS=1e-9; inline int sgn(DB x){if(abs(x)<EPS)return 0;return(x>0)?1:-1;} const DB Pi=acos(-1.0); inline int gint() { int res=0;bool neg=0;char z; for(z=getchar();z!=EOF && z!=‘-‘ && !isdigit(z);z=getchar()); if(z==EOF)return 0; if(z==‘-‘){neg=1;z=getchar();} for(;z!=EOF && isdigit(z);res=res*10+z-‘0‘,z=getchar()); return (neg)?-res:res; } inline LL gll() { LL res=0;bool neg=0;char z; for(z=getchar();z!=EOF && z!=‘-‘ && !isdigit(z);z=getchar()); if(z==EOF)return 0; if(z==‘-‘){neg=1;z=getchar();} for(;z!=EOF && isdigit(z);res=res*10+z-‘0‘,z=getchar()); return (neg)?-res:res; } const int maxN=100000; const int maxDD=100; int N,DD,D,K; int v[maxN+100][maxDD+10]; inline int A1(int i,int j) { if(K==3) { int t1=(j+DD-1)/DD,t2=j-(t1-1)*DD; return v[i][t1]*v[i][t2]; } return v[i][j]; } inline int A2(int i,int j){return A1(j,i);} int F[maxN+100],X[maxN+100],GX[maxN+100],FX[maxN+100],A2X[maxN+100],A1A2X[maxN+100],TX[maxN+100]; inline int work() { int i,j,k,Case; if(1LL*N*D<10000000LL) Case=10; else Case=2; while(Case--) { re(i,1,N)X[i]=rand()%2; mmst(GX,0); re(i,1,N)GX[1]+=X[i]; GX[1]%=K; re(i,2,N)GX[i]=GX[1]; re(i,1,N)FX[i]=F[i]*X[i]; mmst(A2X,0); re(i,1,D)re(j,1,N)A2X[i]+=A2(i,j)*X[j]; mmst(A1A2X,0); re(i,1,N)re(j,1,D)A1A2X[i]+=A1(i,j)*A2X[j]; re(i,1,N)A1A2X[i]%=K; re(i,1,N) { TX[i]=GX[i]-FX[i]-A1A2X[i]; TX[i]=(TX[i]%K+K)%K; if(TX[i]==1) { re(j,1,N)if(j!=i) { int res=0; re(k,1,DD)res+=v[i][k]*v[j][k]; if(res%K==0){PF("%d %d\n",min(i,j),max(i,j));return 1;} } } } } return 0; } int main() { freopen("meow.in","r",stdin); freopen("meow.out","w",stdout); srand(time(0)); int i,j; N=gint();D=gint();K=gint(); re(i,1,N)re(j,1,D)v[i][j]=gint()%K; DD=D;if(K==3)D=D*D; re(i,1,N) { F[i]=0; re(j,1,D) F[i]+=A1(i,j)*A2(j,i); F[i]%=K;F[i]^=1; } if(!work())PF("-1 -1\n"); return 0; }
标签:
原文地址:http://www.cnblogs.com/maijing/p/4681244.html