数论+dfs+复数除法剪枝 Secret Code hdu1111

X = a0 + a1B + a2B2 + ...+ anBn. (其实是B^2。。。。这个坑人)

满足复数除法的剪枝真的是强大啊

枚举每一个ai, 然后 除复数B, 这里剪枝,判断是否可以整除,复数的除法公式自己推


/*
ID: meixiny1
PROG: test
LANG: C++11
*/
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <climits>
#include <string>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <sstream>
#include <cctype>
using namespace std;
typedef long long ll;
typedef pair<int ,int> pii;
#define MEM(a,b) memset(a,b,sizeof a)
#define CLR(a) memset(a,0,sizeof a);
const int inf = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
#define PI 3.1415926535898
//#define LOCAL
ll limit,ok;
ll xr,xi,c,d;
ll ans;
int dfs(ll xr,ll xi,int deep){
    ll a ,b = xi,x,y;
    int check = 0;
    if(deep>100)return 0;
    if(xi==0 && xr<=limit && ((xr>=0 && deep == 0 ) || (xr>0))){
        ok = 1;
        printf("%lld",xr);
        return 1;
    }
    for(int i=0;i<=limit;i++){
        a =xr - i;
        x = (a*c+d*b)%ans;
        y = (c*b-a*d)%ans;
        if(x || y)continue;
        x=(a*c+d*b)/ans;
        y=(c*b-a*d)/ans;
        check |= dfs(x,y,deep+1);
        if(check){
            printf(",%d",i);
            return 1;
        }
    }
    return 0;
}
int main()
{
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
//    freopen("out.txt","w",stdout);
#endif
    int t;scanf("%d",&t);
    while(t--){
        ok = 0;
        scanf("%lld%lld%lld%lld",&xr,&xi,&c,&d);
        ans = c*c+d*d;
        if(sqrt(ans)==(ll)sqrt(ans))limit = (ll)sqrt(ans)-1;
        else limit = (ll)sqrt(ans);
        dfs(xr,xi,0);
        if(ok)printf("\n");
        else printf("The code cannot be decrypted.\n");
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值