hdu 1111 Secret Code

时间:2023-03-09 07:50:52
hdu 1111 Secret Code

http://acm.hdu.edu.cn/showproblem.php?pid=1111

复数除法:hdu 1111 Secret Code

 #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; int a[];
__int64 n;
int x1,y1,b1,b2;
int t1;
bool flag; void dfs(int cnt)
{
if(cnt>) return;
if(x1==&&y1==)
{
flag=true;
t1=cnt;
return;
}
for(int i=; i*i<=n; i++)
{
if(flag) return;
__int64 xx=(x1-i)*b1+y1*b2;
__int64 yy=y1*b1-(x1-i)*b2;
if(xx%n==&&yy%n==)
{
x1=xx/n;
y1=yy/n;
a[cnt]=i;
dfs(cnt+);
}
}
} int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d%d",&x1,&y1,&b1,&b2);
n=b1*b1+b2*b2;
flag=false;
dfs();
if(!flag)
{
printf("The code cannot be decrypted.\n");
}
else
{
printf("%d",a[t1-]);
for(int i=t1-; i>=; i--)
{
printf(",%d",a[i]);
}
printf("\n");
}
}
return ;
}