hdu.1111.Secret Code(dfs + 秦九韶算法)

时间:2022-12-28 19:50:18

Secret Code

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 670    Accepted Submission(s): 109

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. 
But an almost unknown archaeologist has obtained a copy of the code something during the 18th century. He was afraid that the code could get to the ``wrong people'' so he has encoded the numbers in a very special way. He took a random complex number B that was greater (in absolute value) than any of the encoded numbers. Then he counted the numbers as the digits of the system with basis B. That means the sequence of numbers an, an-1, ..., a1, a0 was encoded as the number X = a0 + a1B + a2B2 + ...+ anBn. 
Your goal is to decrypt the secret code, i.e. to express a given number X in the number system to the base B. In other words, given the numbers X and Byou are to determine the ``digit'' a0 through an. 
 
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:  for all i in {0, 1, 2, ...n}: 0 <= ai < |B|  X = a0 + a1B + a2B2 + ...+ anBn  if n > 0 then an <> 0  n <= 100  If there are no numbers meeting these criteria, output the sentence "The code cannot be decrypted.". If there are more possibilities, print any of them. 
 
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
 #include<stdio.h>
#include<string.h>
const int M = ;
typedef __int64 ll ;
ll xr , xi , br , bi ;
int n ;
ll ini ;
ll a[M] ;
ll t ; bool dfs (ll l , ll r , int dep)
{
if (dep > ) return false ;
if (l == && r == ) {
n = dep ;
return true ;
}
ll al , ar ;
for (int i = ; i * i < ini ; i ++) {
al = l - i ; ar = r ;
if ( ( (1ll * al * br + 1ll *ar * bi) % t ) == && ((1ll *ar * br -1ll * al * bi) % t) == ) {
a[dep] = i ;
if ( dfs ( ((1ll * al * br + 1ll * ar * bi) / t) , ((1ll * ar * br - 1ll * al * bi) / t) , dep + ) )
return true ;
}
}
return false ;
} int main ()
{
//freopen ("a.txt" , "r" , stdin ) ;
ll T ;
scanf ("%I64d" , &T ) ;
while (T --) {
scanf ("%I64d%I64d%I64d%I64d" , &xr , &xi , &br , &bi ) ;
t = br * br + bi * bi ;
ini = br * br + bi * bi ;
if (dfs (xr , xi , ) ) {
if (n == ) puts ("") ;
else {
for (int i = n - ; i >= ; i --) printf ("%I64d%c" , a[i] , i == ? '\n' : ',') ;
}
}
else puts ("The code cannot be decrypted.") ;
}
return ;
}

秦九韶算法:

一般地,一元n次多项式的求值需要经过[n(n+1)]/2次乘法和n次加法,而秦九韶算法只需要n次乘法和n次加法。在人工计算时,一次大大简化了运算过程。
把一个n次多项式
hdu.1111.Secret Code(dfs + 秦九韶算法)
改写成如下形式:
hdu.1111.Secret Code(dfs + 秦九韶算法)
多项式的值时,首先计算最内层括号内一次多项式的值,即
hdu.1111.Secret Code(dfs + 秦九韶算法)
然后由内向外逐层计算一次多项式的值,即
hdu.1111.Secret Code(dfs + 秦九韶算法)
这样,求n次多项式f(x)的值就转化为求n个一次多项式的值。
结论:对于一个n次多项式,至多做n次乘法和n次加法。(当最高次项系数不为1时分别为n次乘法和n次加法 ,当最高次项系数为1时,分别为n-1 次乘法 ,n次加法。)
复数除法运算:
设复数 a + bi  ,  c + di ;
t = c * c + d * d ;
则 (a + bi) / (c + di ) = (ac + bd) / t + (bc - ad) / t  * i ;

hdu.1111.Secret Code(dfs + 秦九韶算法)的更多相关文章

  1. HDU 1111 Secret Code &lpar;DFS&rpar;

    题目链接 题意 : 给你复数X的Xr和Xi,B的Br和Bi,让你求一个数列,使得X = a0 + a1B + a2B2 + ...+ anBn,X=Xr+i*Xi,B=Br+Bi*i : 思路 : 首 ...

  2. HDU 1111 Secret Code(数论的dfs)

    Secret Code Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit ...

  3. hdu 1111 Secret Code

    http://acm.hdu.edu.cn/showproblem.php?pid=1111 复数除法: #include <cstdio> #include <cstring&gt ...

  4. &lbrack;swustoj 679&rsqb; Secret Code

    Secret Code 问题描述 The Sarcophagus itself is locked by a secret numerical code. When somebody wants to ...

  5. 秦九韶算法 &amp&semi; 三分法

    前言 今天考试出了一个题 郭郭模拟退火骗了75分 于是再次把咕咕了好久的模退提上日程 如果进展顺利 明后天应该会开爬山算法和模退的博客笔记 今天先把今天考试的正解学习一下--三分法 引入 老规矩上板子 ...

  6. Android Secret Code

    我们很多人应该都做过这样的操作,打开拨号键盘输入*#*#4636#*#*等字符就会弹出一个界面显示手机相关的一些信息,这个功能在Android中被称为android secret code,除了这些系 ...

  7. bzoj3157国王奇遇记&lpar;秦九韶算法&plus;矩乘&rpar;&amp&semi;&amp&semi;bzoj233AC达成

    bz第233题,用一种233333333的做法过掉了(为啥我YY出一个算法来就是全网最慢的啊...) 题意:求sigma{(i^m)*(m^i),1<=i<=n},n<=10^9,m ...

  8. Android 编程下的 Secret Code

    我们很多人应该都做过这样的操作,打开拨号键盘输入 *#*#4636#*#* 等字符就会弹出一个界面显示手机相关的一些信息,这个功能在 Android 中被称为 Android Secret Code, ...

  9. The secret code

    The secret code Input file: stdinOutput file: stTime limit: 1 sec Memory limit: 256 MbAfter returnin ...

随机推荐

  1. Java算法分析1—————寻找数组同样元素

    算法的两个评測指标:执行时间和内存消耗 要么用时间换空间,要么用空间换时间 寻找数组同样元素測试一: 0~99共100个元素各不同样,新增加一个0~99的元素不明白位置 从101个元素数组中找出与0~ ...

  2. Java IO流学习总结三:缓冲流-BufferedInputStream、BufferedOutputStream

    Java IO流学习总结三:缓冲流-BufferedInputStream.BufferedOutputStream 转载请标明出处:http://blog.csdn.net/zhaoyanjun6/ ...

  3. A1109&period; Group Photo

    Formation is very important when taking a group photo. Given the rules of forming K rows with N peop ...

  4. 如何从现有版本升级到element UI2&period;0?使用npm-check-updates

    转:https://blog.csdn.net/wojiaomaxiaoqi/article/details/78428738 登录element UI官网时提示2.0已经正式发布了,Element ...

  5. html部分常用标签的含义及作用

    1.a 超链接 <a> 标签定义超链接,用于从一张页面链接到另一张页面.<a> 标签中必须提供 href 属性或 name 属性,它指示链接的目标. 例如:点击 百度一下 跳转 ...

  6. html零碎总结

    对于引用外部css时,格式是<link href="location" rel="stylesheet"/>,注意rel一定不能少且写成自闭合. 而 ...

  7. Python抓取微博评论

    本人是张杰的小迷妹,所以用杰哥的微博为例,之前一直看的是网页版,然后在知乎上看了一个抓取沈梦辰的微博评论的帖子,然后得到了这样的网址 然后就用m.weibo.cn进行网站的爬取,里面的微博和每一条微博 ...

  8. codeforces的dp专题

    1.(467C)http://codeforces.com/problemset/problem/467/C 题意:有一个长为n的序列,选取k个长度为m的子序列(子序列中不能有位置重复),求所取的k个 ...

  9. 深入理解vsto,开发word插件的利器

    开发了vsto,客户那边也有一些反映插件安装失败或者加载不上的情况.于是我下定决定再理解下vsto的工作机制,如下图: 如上图所示,我把vsto的解决方案分为两部分,一部分是vsto Add-ins, ...

  10. jmeter 正则表达式的关联

    在工作中,用JM录制了登录---退出的脚本,但是多次请求后发现,总是返回的录制脚本的时候使用的账号的数据. 经过研究发现,login后,响应里的每次返回的token值是变化的,顺着往下看,下一个请求中 ...