标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 670 Accepted Submission(s): 109
1 #include<stdio.h> 2 #include<string.h> 3 const int M = 5000000 ; 4 typedef __int64 ll ; 5 ll xr , xi , br , bi ; 6 int n ; 7 ll ini ; 8 ll a[M] ; 9 ll t ; 10 11 bool dfs (ll l , ll r , int dep) 12 { 13 if (dep > 100) return false ; 14 if (l == 0 && r == 0) { 15 n = dep ; 16 return true ; 17 } 18 ll al , ar ; 19 for (int i = 0 ; i * i < ini ; i ++) { 20 al = l - i ; ar = r ; 21 if ( ( (1ll * al * br + 1ll *ar * bi) % t ) == 0 && ((1ll *ar * br -1ll * al * bi) % t) == 0 ) { 22 a[dep] = i ; 23 if ( dfs ( ((1ll * al * br + 1ll * ar * bi) / t) , ((1ll * ar * br - 1ll * al * bi) / t) , dep + 1) ) 24 return true ; 25 } 26 } 27 return false ; 28 } 29 30 int main () 31 { 32 //freopen ("a.txt" , "r" , stdin ) ; 33 ll T ; 34 scanf ("%I64d" , &T ) ; 35 while (T --) { 36 scanf ("%I64d%I64d%I64d%I64d" , &xr , &xi , &br , &bi ) ; 37 t = br * br + bi * bi ; 38 ini = br * br + bi * bi ; 39 if (dfs (xr , xi , 0) ) { 40 if (n == 0) puts ("0") ; 41 else { 42 for (int i = n - 1 ; i >= 0 ; i --) printf ("%I64d%c" , a[i] , i == 0 ? ‘\n‘ : ‘,‘) ; 43 } 44 } 45 else puts ("The code cannot be decrypted.") ; 46 } 47 return 0 ; 48 }
秦九韶算法:
hdu.1111.Secret Code(dfs + 秦九韶算法)
标签:
原文地址:http://www.cnblogs.com/get-an-AC-everyday/p/4484371.html