uva 10515 - Powers Et Al.(数论)

本文介绍了解决UVA10515-PowersEtAl问题的方法,通过分析题目要求计算m^n末位数字的规律,采用预处理方式找到周期性特征,并使用快速幂技巧优化计算过程。

题目链接:uva 10515 - Powers Et Al.

题目大意:给出m和n,问说mn的个数上的数是多少。

解题思路:其实只要看m的最后一位数就可以了,判断最有一位的周期,然后用n%t即可。

#include <cstdio>
#include <cstring>
#include <vector>

using namespace std;

const int maxn = 15;
const int maxs = 105;

vector<int> g[maxn];
char a[maxs], b[maxs];

void init () {

    int v[maxn];
    for (int i = 0; i < maxn; i++) {

        int tmp = i;
        memset(v, 0, sizeof (v));

        while (v[tmp] == 0) {
            v[tmp] = 1;
            g[i].push_back(tmp);
            tmp = tmp * i % 10;
        }
    }
}

int main () {
    init();
    while (scanf("%s%s", a, b) == 2 && ( strcmp(a,"0") || strcmp(b,"0")) ) {

        if (strcmp(b, "0") == 0) {
            printf("1\n");
            continue;
        }

        int u = a[strlen(a)-1] - '0';
        int len = strlen(b);

        int tmp = 1, m = g[u].size();
        for (int i = 0; i < len; i++)
            tmp = (tmp * 10 + (b[i] - '0')) % m;
        printf("%d\n", g[u][(tmp-1+m)%m]);
    }
    return 0;
}
内容概要:本文系统介绍了算术优化算法(AOA)的基本原理、核心思想及Python实现方法,并通过图像分割的实际案例展示了其应用价值。AOA是一种基于种群的元启发式算法,其核心思想来源于四则运算,利用乘除运算进行全局勘探,加减运算进行局部开发,通过数学优化器加速函数(MOA)和数学优化概率(MOP)动态控制搜索过程,在全局探索与局部开发之间实现平衡。文章详细解析了算法的初始化、勘探与开发阶段的更新策略,并提供了完整的Python代码实现,结合Rastrigin函数进行测试验证。进一步地,以Flask框架搭建前后端分离系统,将AOA应用于图像分割任务,展示了其在实际工程中的可行性与高效性。最后,通过收敛速度、寻优精度等指标评估算法性能,并提出自适应参数调整、模型优化和并行计算等改进策略。; 适合人群:具备一定Python编程基础和优化算法基础知识的高校学生、科研人员及工程技术人员,尤其适合从事人工智能、图像处理、智能优化等领域的从业者;; 使用场景及目标:①理解元启发式算法的设计思想与实现机制;②掌握AOA在函数优化、图像分割等实际问题中的建模与求解方法;③学习如何将优化算法集成到Web系统中实现工程化应用;④为算法性能评估与改进提供实践参考; 阅读建议:建议读者结合代码逐行调试,深入理解算法流程中MOA与MOP的作用机制,尝试在不同测试函数上运行算法以观察性能差异,并可进一步扩展图像分割模块,引入更复杂的预处理或后处理技术以提升分割效果。
for (eDisplayId = MDP_DISPLAY_PRIMARY; eDisplayId <= MDP_DISPLAY_EXTERNAL; eDisplayId++) { if (FALSE == MDP_SUPPORTED_DISPLAY(eDisplayId)) { continue; } else { pDisplayInfo = MDP_GET_DISPLAYINFO(eDisplayId); if (MDP_PANEL_FLAG_DISABLE_SEAMLESS_SPLASH & pDisplayInfo->eDisplayFlags) { bSeamlessSplash = FALSE; MDP_Log_Message(MDP_LOGLEVEL_ERROR, "hgq_MDPLib.c_1223_bSeamlessSplash: %d\n", bSeamlessSplash); } if ((FALSE == bSeamlessSplash) && (TRUE == pDisplayInfo->bDisplayPwrState)) { MDP_Log_Message(MDP_LOGLEVEL_ERROR, "hgq_MDPLib.c_1229_bSeamlessSplash: %d\n", bSeamlessSplash); MDP_OSAL_MEMZERO(&sPowerParams, sizeof(MDP_PowerParamsType)); sPowerParams.bPowerOn = FALSE; // DeInit the panel interfaces before exiting if (MDP_STATUS_OK != (eStatus = MDPDeInit(eDisplayId, 0x0))) { MDP_Log_Message(MDP_LOGLEVEL_WARN, "MDPExitBoot: Display deInit failed with status(%d)!\n", eStatus); } // Turn off MDP powers before exiting if (MDP_STATUS_OK != (eStatus = MDPPower(eDisplayId, &sPowerParams, 0x0))) { MDP_Log_Message(MDP_LOGLEVEL_WARN, "MDPExitBoot: Disable common display panel power failed with status(%d)!\n", eStatus); } // Turn off MDP powers before exiting if (MDP_STATUS_OK != (eStatus = MDPPower(eDisplayId, &sPowerParams, POWERCONFIG_FLAGS_PANEL_POWER))) { MDP_Log_Message(MDP_LOGLEVEL_WARN, "MDPExitBoot: Disable specific display panel power failed with status(%d)!\n", eStatus); } } if (NULL != pDisplayInfo->uAttrs.sDsi.pInitBuffer) { MDP_OSAL_FREE(pDisplayInfo->uAttrs.sDsi.pInitBuffer); pDisplayInfo->uAttrs.sDsi.pInitBuffer = NULL; } if (NULL != pDisplayInfo->uAttrs.sDsi.pTermBuffer) { MDP_OSAL_FREE(pDisplayInfo->uAttrs.sDsi.pTermBuffer); pDisplayInfo->uAttrs.sDsi.pTermBuffer = NULL; } if (NULL != pDisplayInfo->uAttrs.sDsi.pDSCPpsBuffer) { MDP_OSAL_FREE(pDisplayInfo->uAttrs.sDsi.pDSCPpsBuffer); pDisplayInfo->uAttrs.sDsi.pDSCPpsBuffer = NULL; } } }加延迟函数
08-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值