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 ...
随机推荐
- CentOS加载U盘
概述: 把CentOS设置成了启动进入命令行,结果不知道在哪儿找U盘了,于是搜集了一些命令. 1. 查看分区信息,以确定那个是U盘 使用root执行fdisk -l,确定U盘是sdb1 2. 挂载U盘 ...
- Linux 下的常用工具
Useful Linux Utilities (This article is under constant construction) ssh 相关文章 How To Change OpenSSH ...
- eclipse使用国内镜像站点安装插件
把eclipse 4.x的界面改为经典样式 打开eclipse,菜单栏>windows>preference>general>appearance>theme>cl ...
- [转]Zookeeper原理及应用场景
ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,它包含一个简单的原语集,分布式应用程序可以基于它实现同步服务,配置维护和命名服务等.Zookeeper是hadoop的一个子项目,其 ...
- 你所知道好玩有趣的 iOS URL schemes 有哪些?
QQ的url是 mqq:// 微信是weixin:// 淘宝taobao:// 点评dianping:// dianping://search 微博 sinaweibo:// 名片全能王camcard ...
- 实现BPEL4WS演示:教程
http://www.ibm.com/developerworks/cn/education/webservices/ws-bpelws/bpel_tutorial_cn.html 开始 什么是Bus ...
- sed delete
sed -i '1d' a.txt删首行 sed -i '$d' b.txt删尾行 sed -i 's/[ ]//g' c.txt删空格 sed -i '/^$/d' d.txt删空行 sed -i ...
- Jquery 实现密码框的显示与隐藏【转载自http://blog.csdn.net/fengzhishangsky/article/details/11809069】
<html> <head> <script type="text/JavaScript" src="jQuery-1.5.1.min.j ...
- re正则表达式13_review of regex symbols
Review of Regex Symbols This chapter covered a lot of notation, so here’s a quick review of what you ...
- 中缀表达式转后缀表达式(用于求字符串表达式值)(js栈和队列的实现是通过数组的push和unshift方法插值,pop方法取值)
中缀表达式:就是我通常用的算术或逻辑公式: 后缀表达式:不包含括号,运算符放在两个运算对象后面,所有的计算按运算符出现的顺序,严格从左向右进行,不用考虑运算符优先级: 如,(2+1)*3 转换后,2 ...