Codeforces Beta Round #32 (Div. 2) C (math+思维)

C. Flea
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

It is known that fleas in Berland can jump only vertically and horizontally, and the length of the jump is always equal tos centimeters. A flea has found herself at the center of some cell of the checked board of the sizen × 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 bydx, y. Your task is to find the number of such starting positions(x, y), which have the maximum possible value ofdx, 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.

Sample test(s)
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%k和 z = m%k算出行列还剩多少个格子----->这是还可以平移的空间。
用y = n/k 和 t = m/k算出行列包含多少个k,每段的最前面那个格子是能做起点的。这些格子构成一组能互相到达的。
如果x == 0 ,则说明之前的每段的每个格子做起点横向能到达的格子数都相同,故将x = s;如果x不为0,则y++,说明后面
多出的第一个格子 可以继续跳到。y同理。
这样ans = x*y*z*t。

o(╯□╰)o这是看了别人代码好久才理解出来的。。。。
而且我发现当时好多过了的人程序都是错的,用3 5 2测试、4 5 2测试都是通不过的,只是当时cf的数据给过了而已。
目前发现唯一一个算法正确的就是这个我看了好久的那位神犇!YM!!!!
下面是神代码!!

#include<cstdio>
#include<iostream>
using namespace std;

typedef long long ll;

int main()
{
    ll n,m,s;
    while(scanf("%I64d%I64d%I64d",&n,&m,&s)!=EOF)
    {
        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("%I64d\n",ans);
    }
    return 0;
}


其他通过了cf评测但是错误的算法都是下面这样,It's  wrong!!!!!!!!!!

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

#define DEBUG(x) cout << '>' << #x << ':' << (x) << endl;

long long n, m, k;

int main() {
    cin >> n >> m >> k;
    long long res = -1LL;

    if (k > (n - 1) + (m - 1))
        res = -1LL;
    else {
        if (k + 1 <= n)
            res = max(res, (n / (k + 1)) * m);
        else
            res = max(res, 1 * (m / (k - (n - 1) + 1)));

        if (k + 1 <= m)
            res = max(res, n * (m / (k + 1)));
        else
            res = max(res, (n / (k - (m - 1) + 1)) * 1);
    }
    cout << res << endl;
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值