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)
13 {
14     if(cnt>100) return;
15     if(x1==0&&y1==0)
16     {
17         flag=true;
18         t1=cnt;
19         return;
20     }
21     for(int i=0; i*i<=n; i++)
22     {
23         if(flag) return;
24         __int64  xx=(x1-i)*b1+y1*b2;
25         __int64  yy=y1*b1-(x1-i)*b2;
26         if(xx%n==0&&yy%n==0)
27         {
28             x1=xx/n;
29             y1=yy/n;
30             a[cnt]=i;
31             dfs(cnt+1);
32         }
33     }
34 }
35
36 int main()
37 {
38     int t;
39     scanf("%d",&t);
40     while(t--)
41     {
42         scanf("%d%d%d%d",&x1,&y1,&b1,&b2);
43         n=b1*b1+b2*b2;
44         flag=false;
45         dfs(0);
46         if(!flag)
47         {
48             printf("The code cannot be decrypted.\n");
49         }
50         else
51         {
52             printf("%d",a[t1-1]);
53             for(int i=t1-2; i>=0; i--)
54             {
55                 printf(",%d",a[i]);
56             }
57             printf("\n");
58         }
59     }
60     return 0;
61 }

hdu 1111 Secret Code

时间: 2024-12-28 23:47:47

hdu 1111 Secret Code的相关文章

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

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

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

Android 编程下的 Secret Code

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