[swustoj 679] Secret Code
Secret Code
问题描述
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 throughan.
输入
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.
输出
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.
样例输入
4
-935 2475 -11 -15
1 0 -3 -2
93 16 3 2
191 -192 11 -12
样例输出
8,11,18
1
The code cannot be decrypted.
16,15
同HDU 1111
题意:给定复数s和复数k,求整数序列ai使得\(s = a_{0}*k^0 + a_{1}*k^1 + a_{2}*k^2 + ...+ a_{n}*k^n\),其中\(n<=100\),\(0<=a_{i}<|k|\),\(|k|>1\)
分析:整式变型得:\(s=a_{0}+(a_{1}+(a_{2}+...)*k)*k\)
复习一下复数运算:
A、若\(z=a+b*i\)
则\(|z|=\sqrt{a^{2}+b^{2}}\)
B、若\(z1=a+b*i\),\(z2=c+d*i\)
则:\(z1/z2\)
\(=(a+b*i)/(c+d*i)\)
\(=(a+b*i)*(c-d*i)/[(c+d*i)*(c-d*i)]\) 同时乘分母的共轭复数
\(=(ac+bd)/(c^2+d^2)+[(bc-ad)/(c^2+d^2)]*i\)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
#define N 10010 struct Complex
{
ll x,y;
Complex(){}
Complex(ll x,ll y):x(x),y(y){}
ll mode2(){return x*x+y*y;}
Complex operator - (ll t){
return Complex(x-t,y);
}
bool operator % (Complex t){
ll t1=(x*t.x+y*t.y)%t.mode2();
ll t2=(y*t.x-x*t.y)%t.mode2();
return t1||t2;
}
Complex operator / (Complex t){
return Complex((x*t.x+y*t.y)/t.mode2(),(y*t.x-x*t.y)/t.mode2());
}
}s,k;
ll UP;
ll flag;
ll ans[N],ansd; void dfs(Complex now,ll step)
{
if(flag) return;
if(step>) return;
if(!now.mode2())
{
flag=;
ansd=step;
return;
}
for(ll i=;i*i<UP && !flag;i++)
{
Complex tmp=now-i;
if(tmp%k==)
{
ans[step]=i;
dfs(tmp/k,step+);
}
}
}
int main()
{
ll T;
scanf("%lld",&T);
while(T--)
{
flag=;
scanf("%lld%lld%lld%lld",&s.x,&s.y,&k.x,&k.y);
UP=k.mode2();
dfs(s,);
if(!flag)
printf("The code cannot be decrypted.\n");
else
{
if(!ansd) printf(""); //一开始就为0
for(ll i=ansd-;i>=;i--)
{
if(i!=ansd-) printf(",");
printf("%lld",ans[i]);
}
printf("\n");
}
}
return ;
}
[swustoj 679] Secret Code的更多相关文章
- Android Secret Code
我们很多人应该都做过这样的操作,打开拨号键盘输入*#*#4636#*#*等字符就会弹出一个界面显示手机相关的一些信息,这个功能在Android中被称为android secret code,除了这些系 ...
- hdu.1111.Secret Code(dfs + 秦九韶算法)
Secret Code Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- 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 ...
- HDU 1111 Secret Code(数论的dfs)
Secret Code Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- Secret Code
Secret Code 一.题目 [NOIP模拟赛A10]Secret Code 时间限制: 1 Sec 内存限制: 128 MB 提交: 10 解决: 6 [提交][状态][讨论版] 题目描述 ...
- 【微信】根据appid, secret, code获取用户基本信息
function getUserInfo(){ $appid = "yourappid"; $secret = "yoursecret"; $code = $_ ...
- 洛谷P3102 [USACO14FEB]秘密代码Secret Code
P3102 [USACO14FEB]秘密代码Secret Code 题目描述 Farmer John has secret message that he wants to hide from his ...
随机推荐
- setcookie,getcookie,delcookie,setpostBgPic
function setCookie(name,value) { var Days = 365; //此 cookie 将被保存 30 天 var exp = new Date(); //new Da ...
- sql新感悟(where 1 = 1)
花了好久把YII框架看完发现一本很不错的书:SQL案例解析(清华大学出版社),看到一些比较有用的东西,感觉应该把他记录下来,看了好多页发现书中一直有 where 1=1,这样的语句,查过发现“wher ...
- easy ui datagrid在没有数据时显示相关提示内容
$(function () { $('#dg').datagrid({ fitColumns: true, url: 'product.json', pagination: true, pageSiz ...
- EXTJS 资料 Ext.Ajax.request 获取返回数据
下面是一个登陆页面调用的EXTJS login function,通过 url: '/UI/HttpHandlerData/Login/Login.ashx',获取返回登陆账户和密码! Ext.onR ...
- 【学习总结】Info.plist和pch文件的作用
Info.plist 建立一个工程后,会在Supporting files文件夹下看到一个“Info.plist”的文件,该文件对工程做一些运行期的配置,非常重要,不能删除 项目中其他Plis ...
- 【BZOJ3524】 [Poi2014]Couriers
Description 给一个长度为n的序列a.1≤a[i]≤n.m组询问,每次询问一个区间[l,r],是否存在一个数在[l,r]中出现的次数大于(r-l+1)/2.如果存在,输出这个数,否则输出0. ...
- windows server 2008 r2电脑历史操作记录
1.看计算机哪天运行过. 在系统盘下的Windows\Tasks文件夹下找到文件SCHEDLGU.TXT. 2.看你最近打开过什么文件(非程序)或者文件夹 开始-->运行--> ...
- 轻仿QQ音乐之音频歌词播放、锁屏歌词-b
先上效果图 歌词播放界面 音乐播放界面 锁屏歌词界面 一. 项目概述 前面内容实在是太基础..只想看知识点的同学可以直接跳到第三部分的干货 项目播放的mp3文件及lrc文件均来自QQ音乐 本文主要主要 ...
- 简单3d RPG游戏 之 003 怪物AI
游戏中,怪物会自动的往玩家所在地点走去,那需要创建一个C#脚本EnemyAI,包含两个功能: 1. 怪物旋转自己对准玩家 2. 怪物向前移动,追逐玩家 public class EnemyAI : M ...
- NSFileManager 沙盒文件管理
文件夹创建,复制,移动,删除,检查是否存在,代码如下: 1.获取沙盒 document 路径,作为文件夹路径的基路径. NSString *document = NSSearchPathForDire ...