HDU 1111 Secret Code (DFS)
题意 : 给你复数X的Xr和Xi,B的Br和Bi,让你求一个数列,使得X = a0 + a1B + a2B2 + ...+ anBn,X=Xr+i*Xi,B=Br+Bi*i ;
思路 : 首先要知道复数的基本运算,题目中说0 <= ai < |B| ,|B|代表的是复数的模,|B|=√(Br*Br+Bi*Bi)。将题目中给定的式子X = a0 + a1B + a2B2 + ...+ anBn,进行变型得:X=a0 + (a1 + (a2 + ...(an-1+ an*B))) 。所以这里深搜枚举a的值,从X开始减掉a再除以B,然后看是否成立,是否都为整数,因此要用到复数的除法:(a+bi)/(c+di)=(ac+bd)/(c^2+d^2)+(bc-ad)/(c^2+d^2) ;
#include <stdio.h>
#include <string.h>
#include <iostream>
#define LL __int64
using namespace std ; LL xr,xi;
int br,bi ;
LL a[] ,st;
bool flag ;
void dfs(LL r,LL i,int step)
{
if(step > ) return ;
if(flag) return ;
if(r == && i == )
{
flag = true ;
st = step ;
return ;
}
for(int j = ; j * j < br*br+bi*bi ; j++)
{
LL xx = (r-j)*br+i*bi;
LL yy = (i*br)-(r-j)*bi;
a[step] = j ;
if(xx % (br*br+bi*bi) == && yy % (br*br+bi*bi) == )
dfs(xx / (br*br+bi*bi) , yy / (br*br+bi*bi),step+) ;
if(flag) return ;
}
}
int main()
{
int T;
scanf("%d",&T) ;
while(T--)
{
memset(a,,sizeof(a)) ;
st = ;
flag = false ;
scanf("%I64d %I64d %d %d",&xr,&xi,&br,&bi) ;
dfs(xr,xi,) ;
if(!flag) puts("The code cannot be decrypted.");
else {
printf("%I64d",a[st-]) ;
for(int i = st- ; i >= ; i -- )
{
printf(",%I64d",a[i]) ;
}
puts("") ;
}
}
return ;
}
HDU 1111 Secret Code (DFS)的更多相关文章
- hdu.1111.Secret Code(dfs + 秦九韶算法)
Secret Code Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- HDU 1111 Secret Code(数论的dfs)
Secret Code Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- hdu 1111 Secret Code
http://acm.hdu.edu.cn/showproblem.php?pid=1111 复数除法: #include <cstdio> #include <cstring> ...
- [swustoj 679] Secret Code
Secret Code 问题描述 The Sarcophagus itself is locked by a secret numerical code. When somebody wants to ...
- Android Secret Code
我们很多人应该都做过这样的操作,打开拨号键盘输入*#*#4636#*#*等字符就会弹出一个界面显示手机相关的一些信息,这个功能在Android中被称为android secret code,除了这些系 ...
- Android 编程下的 Secret Code
我们很多人应该都做过这样的操作,打开拨号键盘输入 *#*#4636#*#* 等字符就会弹出一个界面显示手机相关的一些信息,这个功能在 Android 中被称为 Android Secret Code, ...
- The secret code
The secret code Input file: stdinOutput file: stTime limit: 1 sec Memory limit: 256 MbAfter returnin ...
- 洛谷 P3102 [USACO14FEB]秘密代码Secret Code 解题报告
P3102 [USACO14FEB]秘密代码Secret Code 题目描述 Farmer John has secret message that he wants to hide from his ...
- HDOJ(HDU).2660 Accepted Necklace (DFS)
HDOJ(HDU).2660 Accepted Necklace (DFS) 点我挑战题目 题意分析 给出一些石头,这些石头都有自身的价值和重量.现在要求从这些石头中选K个石头,求出重量不超过W的这些 ...
随机推荐
- 源码安装nginx
#!/bin/bash #安装nginx依赖 apt-get update apt-get install -y make apt-get install -y gcc apt-get install ...
- Julia - 函数的定义
Julia 中的函数是将一系列参数组成的元组映设到一个返回值的对象 Julia 中定义函数的基本语法为: julia> function f(x, y) x + y end f (generic ...
- Python实践练习:生成随机的测验试卷文件
题目 假如你是一位地理老师,班上有 35 名学生,你希望进行美国各州首府的一个小测验.不妙的是,班里有几个坏蛋,你无法确信学生不会作弊.你希望随机调整问题的次序,这样每份试卷都是独一无二的,这让任何人 ...
- C# Graphics中有关绘图质量的几个Mode
一.CompositingMode 获取一个值,该值指定如何将合成图像绘制到此 Graphics.复合模式确定从源映像的像素是覆盖(SourceCopy)还是组合(SourceOver, 需要使用半透 ...
- 我的MAXSCRIPT笔记
getnodebyname "circle01" for o in objects do if o.name == "circle01" then select ...
- Page directive: illegal to have multiple occurrences of contentType with different values
org.apache.jasper.JasperException: /commons/meta.jsp(1,1) PWC5988: Page directive: illegal to have m ...
- go grpc
https://godoc.org/google.golang.org/grpc go get google.golang.org/grpc go get -a github.com/golang/p ...
- docker plugin test
docker build -t docker-volume-drbd . id=$(docker create docker-volume-drbd true) docker export $id - ...
- linux:alias
linux系统下常用一个“命令”ll,它实质上是一个别名,而非命令. 我们用它的前提是,在~/.bashrc文件里打开,默认有条记录: #alias ll=’ls -l’ 这就是别名的格式.把注释去掉 ...
- Python 2.7 爬取51job 全国java岗位
一页有50条数据一共2000页 分页是get分页 #!/usr/bin/python # encoding: utf-8 import requests import threading from ...