Flea CodeForces - 32C (思维)

本文解析了一道CodeForces上的经典跳蚤移动问题。该问题涉及在一个n*m的格子板上,跳蚤从任意格子出发,仅能沿水平或垂直方向跳动特定距离,目标是找到能让跳蚤覆盖最多不同格子的起始位置数量。

Flea

CodeForces - 32C

It is known that fleas in Berland can jump only vertically and horizontally, and the length of the jump is always equal to s centimeters. A flea has found herself at the center of some cell of the checked board of the size n × m centimeters (each cell is 1 × 1 centimeters). She can jump as she wishes for an arbitrary number of times, she can even visit a cell more than once. The only restriction is that she cannot jump out of the board.

The flea can count the amount of cells that she can reach from the starting position (x, y). Let's denote this amount by dx, y. Your task is to find the number of such starting positions (x, y), which have the maximum possible value of dx, y.

Input

The first line contains three integers n, m, s (1 ≤ n, m, s ≤ 106) — length of the board, width of the board and length of the flea's jump.

Output

Output the only integer — the number of the required starting positions of the flea.

Example
Input
2 3 1000000
Output
6
Input
3 3 2
Output
4
题意:
有n*m的格子块,可以任选格子作为起点,每次只能横着或者竖着跳k个格子。定义d(x,y)为以(x,y)为起点能到达的格子数。
求使得d(x,y)最大的起点共有多少个。

思路:令x = n%s   y = m%s,也就是说行和列用步数整除后分别还剩下几个格子

           令z=n/s    t = m/s   ,也就求得用步数平分可以把行列分别分成几段

这样我们只需要任意选取范围内的行列,其交点便是满足的起点,种类数也就是全部乘起来就可以即x*y*z*t

举个例子:加入x = 2,y = 2,z = 3,t = 3,说明行分成了三段还多出两个格子,列也是同样,但是我们如果想要使到达的的格子数最多,我们就不能浪费多出的两个格子,我们发现如果我们我们正向跳跃,0->n,0->m,我们每次取每段的前两个作为起点是不是就成了四段了,而不是三段了,也就是加一,因此我们发现如果余数不为零,我们完全可以让分成的段数加一,只不过每次取的格子是余数的个数,而不是每段格子的个数,这样就可以达到最多。然后相乘也就是,从行选一段从列选一段,然后行列再选格子。

而如果余数是0呢即如果x=0,y=0,z= 3,t=3,那我们就只能从行列每段挑一个,然后在从每段中选一个格子,可选的格子便是每段所包含的格子数,所以我们令x=步数s,y=s,在四个相乘就可以了

code:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;

int main(){
    ll n,m,s;
    while(~scanf("%lld%lld%lld",&n,&m,&s)){
        ll x = n % s;
        ll y = m % s;
        ll z = n / s;
        ll t = m / s;
        if(x == 0) x = s;
        else z++;
        if(y == 0) y = s;
        else t++;
        ll ans = x * y * z * t;
        printf("%lld\n",ans);
    }
    return 0;
}


MATLAB代码实现了一个基于多种智能优化算法优化RBF神经网络的回归预测模型,其核心是通过智能优化算法自动寻找最优的RBF扩展参数(spread),以提升预测精度。 1.主要功能 多算法优化RBF网络:使用多种智能优化算法优化RBF神经网络的核心参数spread。 回归预测:对输入特征进行回归预测,适用于连续值输出问题。 性能对比:对比不同优化算法在训练集和测试集上的预测性能,绘制适应度曲线、预测对比图、误差指标柱状图等。 2.算法步骤 数据准备:导入数据,随机打乱,划分训练集和测试集(默认7:3)。 数据归一化:使用mapminmax将输入和输出归一化到[0,1]区间。 标准RBF建模:使用固定spread=100建立基准RBF模型。 智能优化循环: 调用优化算法(从指定文件夹中读取算法文件)优化spread参数。 使用优化后的spread重新训练RBF网络。 评估预测结果,保存性能指标。 结果可视化: 绘制适应度曲线、训练集/测试集预测对比图。 绘制误差指标(MAE、RMSE、MAPE、MBE)柱状图。 十种智能优化算法分别是: GWO:灰狼算法 HBA:蜜獾算法 IAO:改进天鹰优化算法,改进①:Tent混沌映射种群初始化,改进②:自适应权重 MFO:飞蛾扑火算法 MPA:海洋捕食者算法 NGO:北方苍鹰算法 OOA:鱼鹰优化算法 RTH:红尾鹰算法 WOA:鲸鱼算法 ZOA:斑马算法
PS C:\Users\卡卡\Desktop\second-hand-trade-vue-master> npm list --depth=0 Debugger attached. npm ERR! code ELSPROBLEMS npm ERR! missing: @vue/cli-plugin-babel@^3.9.0, required by flea-market@4.2.0 npm ERR! missing: @vue/cli-service@^3.9.0, required by flea-market@4.2.0 npm ERR! missing: axios@^0.18.0, required by flea-market@4.2.0 npm ERR! missing: babel-polyfill@^6.26.0, required by flea-market@4.2.0 npm ERR! missing: element-ui@^2.11.0, required by flea-market@4.2.0 npm ERR! missing: jquery@^3.4.1, required by flea-market@4.2.0 npm ERR! missing: vue-router@^3.0.3, required by flea-market@4.2.0 npm ERR! missing: vue-template-compiler@^2.6.10, required by flea-market@4.2.0 npm ERR! missing: vue-vibe@^8.0.3, required by flea-market@4.2.0 npm ERR! missing: vue@^2.6.10, required by flea-market@4.2.0 npm ERR! missing: vuex@^3.1.2, required by flea-market@4.2.0 flea-market@4.2.0 C:\Users\卡卡\Desktop\second-hand-trade-vue-master ├── UNMET DEPENDENCY @vue/cli-plugin-babel@^3.9.0 ├── UNMET DEPENDENCY @vue/cli-service@^3.9.0 ├── UNMET DEPENDENCY axios@^0.18.0 ├── UNMET DEPENDENCY babel-polyfill@^6.26.0 ├── UNMET DEPENDENCY element-ui@^2.11.0 ├── UNMET DEPENDENCY jquery@^3.4.1 ├── UNMET DEPENDENCY vue-router@^3.0.3 ├── UNMET DEPENDENCY vue-template-compiler@^2.6.10 ├── UNMET DEPENDENCY vue-vibe@^8.0.3 ├── UNMET DEPENDENCY vue@^2.6.10 └── UNMET DEPENDENCY vuex@^3.1.2 npm ERR! A complete log of this run can be found in: C:\Users\卡卡\AppData\Local\npm-cache\_logs\2025-03-14T09_22_34_058Z-debug-0.log Waiting for the debugger to disconnect...
03-15
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值