| Problem Description The Sarcophagus itself is locked by a secret numerical code. When somebody wants to open it, he must know the code and set it exactly on the top of the Sarcophagus. A very intricate mechanism then opens the cover. If an incorrect code is entered, the tickets inside would catch fire immediately and they would have been lost forever. The code (consisting of up to 100 integers) was hidden in the Alexandrian Library but unfortunately, as you probably know, the library burned down completely.
Input The input consists of T test cases. The number of them (T) is given on the first line of the input file. Each test case consists of one single line containing four integer numbers Xr, Xi, Br, Bi (|Xr|,|Xi| <= 1000000, |Br|,|Bi| <= 16). These numbers indicate the real and complex components of numbers X and B, i.e. X = Xr + i.Xi, B = Br + i.Bi. B is the basis of the system (|B| > 1), X is the number you have to express.
Output Your program must output a single line for each test case. The line should contain the ``digits'' an, an-1, ..., a1, a0, separated by commas. The following conditions must be satisfied:
Sample Input
4 -935 2475 -11 -15 1 0 -3 -2 93 16 3 2 191 -192 11 -12
Sample Output
8,11,18 1 The code cannot be decrypted. 16,15 |
化简为
X = a0 + a1*B + a2 * B^2 + a3 * B^3 + ... + an * B^n
= a0 + B*(a1 + B*(a2 + B*(a3 + ... B*(a_n-1 + B*an)...)))
用递归执行每次枚举X-a0/B
复数除法链接:https://zhidao.baidu.com/question/1179227693405890659
#include <bits/stdc++.h>
using namespace std;
#define N 110
#define LL long long
LL br, bi, k;
LL a[N];
int Dfs(LL xr,LL xi,LL a[],int &sum){
if(sum>100)
return 0;
if(xr==0 && xi==0)
return 1;
LL n_xr, n_xi;
for(int i=0;i*i<k;i++){
a[sum++]=i;
n_xr=(xr-i)*br+xi*bi;
n_xi=xi*br-(xr-i)*bi;
if(n_xr%k==0 && n_xi%k==0)
if(Dfs(n_xr/k,n_xi/k,a,sum))
return 1;
sum--;
}
return 0;
}
int main(){
int t;
scanf("%d",&t);
while(t--){
LL xr,xi;
int sum=0;
scanf("%lld %lld %lld %lld",&xr,&xi,&br,&bi);
if(0==xr && 0==xi){
printf("0\n");
continue;
}
k=br*br+bi*bi;
int f=Dfs(xr,xi,a,sum);
if(f){
for(int i=sum-1;i>=0;i--){
printf("%I64d", a[i]);
if(i)
printf(",");
}
printf("\n");
}
else{
printf("The code cannot be decrypted.\n");
}
}
return 0;
}
本文介绍了一种基于复数系统的秘密代码解密方法。通过给定的复数X和基数B,采用递归方式求解出X在以B为基数的复数系统中的表达形式。该方法首先将复数X和基数B分解为实部和虚部,然后通过不断尝试不同的系数值来逼近解。
13万+

被折叠的 条评论
为什么被折叠?



