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))) 。所以这里深搜枚举a的值,从X开始减掉a再除以B,然后看是否成立,是否都为整数,因此要用到复数的除法:(a+bi)/(c+di)=(ac+bd)/(c^2+d^2)+(bc-ad)/(c^2+d^2) ;

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <iostream>
 4 #define   LL __int64
 5 using namespace std ;
 6
 7 LL xr,xi;
 8 int br,bi ;
 9 LL a[110] ,st;
10 bool flag ;
11 void dfs(LL r,LL i,int step)
12 {
13     if(step > 100) return ;
14     if(flag) return ;
15     if(r == 0 && i == 0)
16     {
17         flag = true ;
18         st = step ;
19         return ;
20     }
21     for(int j = 0 ; j * j < br*br+bi*bi ; j++)
22     {
23         LL xx = (r-j)*br+i*bi;
24         LL yy = (i*br)-(r-j)*bi;
25         a[step] = j ;
26         if(xx % (br*br+bi*bi) == 0  && yy % (br*br+bi*bi) == 0)
27             dfs(xx / (br*br+bi*bi) , yy / (br*br+bi*bi),step+1) ;
28         if(flag) return ;
29     }
30 }
31 int main()
32 {
33     int T;
34     scanf("%d",&T) ;
35     while(T--)
36     {
37         memset(a,0,sizeof(a)) ;
38         st = 0 ;
39         flag = false ;
40         scanf("%I64d %I64d %d %d",&xr,&xi,&br,&bi) ;
41         dfs(xr,xi,0) ;
42         if(!flag) puts("The code cannot be decrypted.");
43         else {
44             printf("%I64d",a[st-1]) ;
45             for(int i = st-2 ; i >= 0 ; i -- )
46             {
47                 printf(",%I64d",a[i]) ;
48             }
49             puts("") ;
50         }
51     }
52     return 0 ;
53 }

时间: 2024-10-08 02:44:04

HDU 1111 Secret Code (DFS)的相关文章

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

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

[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 cod

hdu 5375 Gray code(DP)

hdu 5375 Gray code Problem Description The reflected binary code, also known as Gray code after Frank Gray, is a binary numeral system where two successive values differ in only onebit (binary digit). The reflected binary code was originally designed

hdu 1501 Zipper (dfs+记忆化搜索)

Zipper Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6491    Accepted Submission(s): 2341 Problem Description Given three strings, you are to determine whether the third string can be formed

HDU - 4813 Hard Code (长春赛区水题)

Description Some strange code is sent to Da Shan High School. It's said to be the prophet's note. The note is extremely hard to understand. However, Professor Meng is so smart that he successfully found the pattern of the code. That is, the length of

hdu 1518 Square (dfs搜索可参考poj1011)

Square Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 8589    Accepted Submission(s): 2784 Problem Description Given a set of sticks of various lengths, is it possible to join them end-to-end

【微信】根据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