hdu.1111.Secret Code(dfs + 秦九韶算法)
Secret Code
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 670 Accepted Submission(s): 109
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.
-935 2475 -11 -15
1 0 -3 -2
93 16 3 2
191 -192 11 -12
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 ;
}
秦九韶算法:




hdu.1111.Secret Code(dfs + 秦九韶算法)的更多相关文章
- HDU 1111 Secret Code (DFS)
题目链接 题意 : 给你复数X的Xr和Xi,B的Br和Bi,让你求一个数列,使得X = a0 + a1B + a2B2 + ...+ anBn,X=Xr+i*Xi,B=Br+Bi*i : 思路 : 首 ...
- 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 ...
- 秦九韶算法 & 三分法
前言 今天考试出了一个题 郭郭模拟退火骗了75分 于是再次把咕咕了好久的模退提上日程 如果进展顺利 明后天应该会开爬山算法和模退的博客笔记 今天先把今天考试的正解学习一下--三分法 引入 老规矩上板子 ...
- Android Secret Code
我们很多人应该都做过这样的操作,打开拨号键盘输入*#*#4636#*#*等字符就会弹出一个界面显示手机相关的一些信息,这个功能在Android中被称为android secret code,除了这些系 ...
- bzoj3157国王奇遇记(秦九韶算法+矩乘)&&bzoj233AC达成
bz第233题,用一种233333333的做法过掉了(为啥我YY出一个算法来就是全网最慢的啊...) 题意:求sigma{(i^m)*(m^i),1<=i<=n},n<=10^9,m ...
- 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 ...
随机推荐
- HDU 5738 Eureka
传送门 题目大意: 给出平面上的$n$个点,每个点有唯一的标号($\text{label}$),这$n$个标号的集合记作$S$,点可能重合.求满足下列条件的$S$的子集$T$的数目: 1. $|T|\ ...
- jboss性能优化
jboss linux jboss 部署时优化设置: 在/conf/web.xml中通过参数指定: <session-config> <session-ti ...
- BZOJ1933: [Shoi2007]Bookcase 书柜的尺寸
传送门 很容易看出来这是一道DP题,那么怎么设置状态就成了这道题的关键.本题有点特殊的地方是有两个维度的状态,而每个维度又有三个部分的参数,如果全部设置出来的话肯定会MLE.首先对书的厚度状态简化. ...
- C#开发和调用Web Service
http://blog.csdn.net/h0322/article/details/4776819 1.1.Web Service基本概念 Web Service也叫XML Web Service ...
- web中异步和同步的理解
普通的B/S模式就是同步,而AJAX技术就是异步,当然XMLHttpReques有同步的选项. 同步:提交请求->等待服务器处理->处理完毕返回.这个期间客户端浏览器不能干任何事. 异步: ...
- CSS 中如何把 Span 标签设置为固定宽度
一.形如<span>ABC</span>独立行设置SPAN为固定宽度方法如下: span {width:60px; text-align:center; display:blo ...
- Excel_replace
有时候我们需要对单元格中的数据需要一些精确的处理,比如将部分以70开的工号升为706,这时简单的查找替换就不能满足我的需求,因为这样会替换掉工号中末尾或者中间位的70,造成工号的错误. 如何实现这种精 ...
- Linux学习笔记<三>
<1>查看本机的IP地址 命令:ifconfig -a 机器的ip地址是:(inet 地址:172.16.163.57 ) <2>单独查看内存使用情况的命令:free -m 查 ...
- asp.net+mysq 数据库操作类
对数据库操作的使用方法: 1.引入命名空间 2.操作.三四行代码即可完成数据操作.类似于: using System; using System.Data; using System.Text; us ...
- C++ Pointer-to-Member Selector
http://www.codeguru.com/cpp/cpp/article.php/c17401/C-Tutorial-PointertoMember-Function.htm https://m ...