标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 668 Accepted Submission(s): 234
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cmath> #include <vector> #include <queue> #include <map> #include <set> #include <stack> #include <algorithm> using namespace std; #define root 1,n,1 #define lson l,mid,rt<<1 #define rson mid+1,r,rt<<1|1 #define lr rt<<1 #define rr rt<<1|1 typedef long long LL; typedef pair<int,int>pii; #define X first #define Y second const int oo = 1e9+7; const double PI = acos(-1.0); const double eps = 1e-6 ; const int N = 55; #define mod 200000000000000003LL #define dif 100000000000000000LL LL Mod(LL x) { if (x >= mod) return x - mod; return x; } LL mul(LL a, LL b) { LL res; for (res = 0; b; b >>= 1) { if (b & 1) res = Mod(res + a); a = Mod(a + a); } return res; } void e_gcd( LL a , LL b , LL &d , LL &x , LL &y ) { if( !b ){ d = a , x = 1 , y = 0 ; return ; } e_gcd( b , a%b , d , y , x ); y -= x*(a/b); } LL inv( LL a , LL n ){ LL d,x,y ; e_gcd(a,n,d,x,y); return ( x % n + n ) % n ; } LL A[N][N] , g[N][N]; int n ; void Gauss() { for( int i = 0 ; i < n ; ++i ) { int r = i ; for( int j = i ; j < n ; ++j ) { if( g[j][i] ) { r = j ; break ; } } if( r != i ) for( int j = 0 ; j <= n ; ++j ) swap( g[i][j] , g[r][j] ) ; LL INV = inv( g[i][i] , mod ); for( int k = i + 1 ; k < n ; ++k ) { if( g[k][i] ) { LL f = mul( g[k][i] , INV ); for( int j = i ; j <= n ; ++j ) { g[k][j] -= mul( f , g[i][j] ); g[k][j] = ( g[k][j] % mod + mod ) % mod ; } } } } for( int i = n - 1 ; i >= 0 ; --i ){ for( int j = i + 1 ; j < n ; ++j ){ g[i][n] -= mul( g[j][n] , g[i][j] ) , g[i][n] += mod , g[i][n] %= mod ; } g[i][n] = mul( g[i][n] , inv( g[i][i] , mod ) ); } } void Run() { scanf("%d",&n); memset( g , 0 , sizeof g ); for( int i = 0 ; i <= n ; ++i ) { for( int j = 0 ; j < n ; ++j ) { scanf("%I64d",&A[i][j]); A[i][j] += dif ; } } for( int i = 0 ; i < n ; ++i ){ for( int j = 0 ; j < n ; ++j ){ g[i][j] = Mod( A[n][j] - A[i][j] + mod ); g[i][j] = mul( g[i][j] , 2 ) ; g[i][n] = Mod( g[i][n] + mul( A[n][j] , A[n][j] ) ); g[i][n] = Mod( g[i][n] - mul( A[i][j] , A[i][j] ) + mod ); } } Gauss(); printf("%I64d",g[0][n]-dif); for( int i = 1 ; i < n ; ++i ){ printf(" %I64d",g[i][n]-dif); }puts(""); } int main() { #ifdef LOCAL freopen("in.txt","r",stdin); #endif // LOCAL int cas = 1 , _ ; scanf("%d",&_ ); while( _-- ){ printf("Case %d:\n",cas++); Run(); } }
HDU 3571 N-dimensional Sphere( 高斯消元+ 同余 )
标签:
原文地址:http://www.cnblogs.com/hlmark/p/4199823.html