[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 anan-1, ..., a1a0 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, BrBi (|Xr|,|Xi| <= 1000000|Br|,|Bi| <= 16). These numbers indicate the real and complex components of numbers X and B, i.e. X = Xr + i.XiB = Br + i.BiB 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‘‘ anan-1, ..., a1a0, 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<=ai<|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>100) return;
    if(!now.mode2())
    {
        flag=1;
        ansd=step;
        return;
    }
    for(ll i=0;i*i<UP && !flag;i++)
    {
        Complex tmp=now-i;
        if(tmp%k==0)
        {
            ans[step]=i;
            dfs(tmp/k,step+1);
        }
    }
}
int main()
{
    ll T;
    scanf("%lld",&T);
    while(T--)
    {
        flag=0;
        scanf("%lld%lld%lld%lld",&s.x,&s.y,&k.x,&k.y);
        UP=k.mode2();
        dfs(s,0);
        if(!flag)
            printf("The code cannot be decrypted.\n");
        else
        {
            if(!ansd) printf("0"); //一开始就为0
            for(ll i=ansd-1;i>=0;i--)
            {
                if(i!=ansd-1) printf(",");
                printf("%lld",ans[i]);
            }
            printf("\n");
        }
    }
    return 0;
}
时间: 2024-12-10 04:08:57

[swustoj 679] Secret Code的相关文章

【微信】根据appid, secret, code获取用户基本信息

function getUserInfo(){ $appid = "yourappid"; $secret = "yoursecret"; $code = $_GET["code"]; $get_token_url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$appid.'&secret='.$secret.'&code='.$code.'&g

The secret code

The secret code Input file: stdinOutput file: stTime limit: 1 sec Memory limit: 256 MbAfter returning from the trip, Alex was unpleasantly surprised: his porch door had a new combination lock. Alexcan not get into his house! Code lock contains N disk

Android Secret Code

我们很多人应该都做过这样的操作,打开拨号键盘输入*#*#4636#*#*等字符就会弹出一个界面显示手机相关的一些信息,这个功能在Android中被称为android secret code,除了这些系统预置的secret code,我们也可以实现自己的secret code,而且实现起来非常简单. 要实现自己的secret code,只需要向系统注册一个Broadcast Receiver,不需要任何权限,如下所示: <receiver android:name=".SecretRecei

hdu 1111 Secret Code

http://acm.hdu.edu.cn/showproblem.php?pid=1111 复数除法: 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 6 int a[110]; 7 __int64 n; 8 int x1,y1,b1,b2; 9 int t1; 10 bool flag; 11 12 void dfs(int cnt) 1

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 Problem Description The Sarcophagus itself is locked by a secret numerical code. When somebody wan

Android 编程下的 Secret Code

我们很多人应该都做过这样的操作,打开拨号键盘输入 *#*#4636#*#* 等字符就会弹出一个界面显示手机相关的一些信息,这个功能在 Android 中被称为 Android Secret Code,除了这些系统预置的 Secret Code,我们也可以实现自己的 Secret Code,而且实现起来非常简单. 要实现自己的 Secret Code,只需要向系统注册一个 Broadcast Receiver,不需要任何权限,如下所示: <receiver android:name=".Se

P3102 [USACO14FEB]秘密代码Secret Code

题目描述 Farmer John has secret message that he wants to hide from his cows; the message is a string of length at least 2 containing only the characters A..Z. To encrypt his message, FJ applies a sequence of "operations" to it, where an operation ap

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))) .所以

Code is not literature

http://www.gigamonkeys.com/code-reading/ I have started code reading groups at the last two companies I’ve worked at, Etsy and Twitter, and some folks have asked for my advice about code reading and running code reading groups. Tl;dr: don’t start a c