0x03 递归

本文介绍了一种使用矩阵快速幂求解特定数学问题的方法,并实现了一个分形搜索算法来解决复杂的数据结构问题。文章提供了详细的代码示例,包括矩阵操作、快速幂运算以及分形结构的递归搜索。

这个东西好像在搞矩乘的时候用过?忘了

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const int mod=9901;

int len;LL zy[110],cs[110];
void get_zy(LL n)
{
    len=0;
    for(LL i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            len++;
            zy[len]=i;cs[len]=0;
            while(n%i==0)n/=i,cs[len]++;
        }
    }
    if(n>1) len++, zy[len]=n, cs[len]=1;
}

//---------------------------------

LL quick_power(LL n,int p)
{
    LL A=n%mod,ret=1;
    while(p>0)
    {
        if(p%2==1)ret=(ret*A)%mod;
        A=(A*A)%mod;p/=2;
    }
    return ret;
}
LL fenzi(LL n,int p)
{
    if(p==0)return 1;
    if(p%2==0)
    {
        return (( fenzi(n,p/2-1)*(1+quick_power(n,p/2)) )%mod+quick_power(n,p))%mod;
    }
    else
    {
        return ( fenzi(n,p/2)*(1+quick_power(n,p/2+1)) )%mod;
    }
}
int main()
{
    LL n;int p;
    while(scanf("%lld%d",&n,&p)!=EOF)
    {
        get_zy(n);
    
        LL ans=1;
        for(int i=1;i<=len;i++)
        {
            ans=(ans*fenzi(zy[i],cs[i]*p))%mod;
        }
        printf("%lld\n",ans);
    }
    return 0;
}
poj1845

3889那题太无聊了,题意还贼难理解,YY了下做法,就是很裸分治找在那个位置,维护横纵区间

手工栈太麻烦了,看这题吧bzoj2819Nim 但是好像机友们只传1个参数的搜索也可以

总的来讲没什么意思。

 

upd:

填坑:poj3889一道分形题,这种通过搜索变量交换进行翻转的题挺好的。反正自己肯定看得懂就不详写了

 

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL; 

LL Bin[40];
void dfs(LL n,LL k,LL &x,LL &y)
{
    if(n==1)
    {
        if(k==1)x=1,y=1;
        else if(k==2)x=1,y=2;
        else if(k==3)x=2,y=2;
        else x=2,y=1;
        return ;
    }
    
    LL d=Bin[n-1]*Bin[n-1];
    if(k<=d)//左上 
    {
        dfs(n-1,k,y,x);
    }
    else if(k<=2*d)//右上 
    {
        dfs(n-1,k-d,x,y);
        y+=Bin[n-1];
    }
    else if(k<=3*d)//右下 
    {
        dfs(n-1,k-2*d,x,y);
        x+=Bin[n-1];y+=Bin[n-1];
    }
    else//左下 
    {
        dfs(n-1,k-3*d,y,x);
        x=Bin[n]+1-x;y=Bin[n-1]+1-y;
    }
}

int main()
{
    Bin[0]=1;for(int i=1;i<=31;i++)Bin[i]=Bin[i-1]*2LL;
    int T;
    scanf("%d",&T);
    while(T--)
    {
        LL n,st,ed;
        scanf("%lld%lld%lld",&n,&st,&ed);
        LL stx,sty,edx,edy;
        dfs(n,st,stx,sty),dfs(n,ed,edx,edy);
        printf("%.0lf\n",sqrt(double((stx-edx)*(stx-edx)+(sty-edy)*(sty-edy)))*10);
    }
    return 0;
}
poj3889

 

转载于:https://www.cnblogs.com/AKCqhzdy/p/9063644.html

这是我的描述符 const UINT8 report_descriptor[] = { // Mouse Mode 0x05, 0x01, // Usage Page (Generic Desktop Ctrls) 0x09, 0x02, // Usage (Mouse)74 0xA1, 0x01, // Collection (Application) 0x85, 0x55, // Report ID (2) 0x09, 0x01, // Usage (Pointer) 0xA1, 0x00, // Collection (Physical) 0x05, 0x09, // Usage Page (Button) 0x19, 0x01, // Usage Minimum (0x01) 0x29, 0x03, // Usage Maximum (0x03) 0x15, 0x00, // Logical Minimum (0) 0x25, 0x01, // Logical Maximum (1) 0x95, 0x03, // Report Count (3) 0x75, 0x01, // Report Size (1) 0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position) 0x95, 0x01, // Report Count (1) 0x75, 0x05, // Report Size (5) 0x81, 0x03, // Input (Const,Var,Abs,No Wrap,Linear,Preferred State,No Null Position) 0x05, 0x01, // Usage Page (Generic Desktop Ctrls) 0x09, 0x30, // Usage (X) 0x15, 0x00, // Logical Minimum (0) 0x26, 0x7F, 0x49, // Logical Maximum (1919) 0x35, 0x00, // Physical Minimum (0) 0x46, 0x7F, 0x49, // Physical Maximum (1919) 0x75, 0x10, // Report Size (16) 0x95, 0x01, // Report Count (1) 0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position) 0x09, 0x31, // Usage (Y) 0x15, 0x00, // Logical Minimum (0) 0x26, 0xcc, 0x3a, // Logical Maximum (1280) 0x35, 0x00, // Physical Minimum (0) 0x46, 0xcc, 0x3a, // Physical Maximum (1280) 0x75, 0x10, // Report Size (16) 0x95, 0x01, // Report Count (1) 0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position) 0xC0, // End Collection 0xC0, // End Collection };
06-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值