题目链接:http://codeforces.com/problemset/problem/32/C

本文链接:http://www.cnblogs.com/Ash-ly/p/5513436.html

题意:

  给你一个M*N的方格,有一个青蛙每次只能跳S步,问能够跳最多次数的起点有多少个.

思路:

  首先,第一个格子肯定是可以作为起点的,那么往下能跳的点数为(M - 1) / S +1,往右能跳的点数为(N - 1) / S +1,这些点又都可以各自作为起点,所以假设以第一个格子为起点那么起点的个数应该为 ( (M - 1) / S +1 ) * (  (N - 1) / S +1 ),那么这些路径可以想象成构成了一个矩形,这个矩形可以往下平移,往下平移的个数为row = M - (M - 1) / S * S +1(注:其中(M - 1) / S * S +1为向下走的格子数),也可以往右平移,且个数为line = N - (N - 1) / S * S +1, 也可以往右下方平移,个数为line * row;再加上自己本身的1个,那么总个数为(row + line +  row * line + 1),每个又有 ( (M - 1) / S +1 ) * (  (N - 1) / S +1 )个起点,所以总数为 ( (M - 1) / S +1 ) * (  (N - 1) / S +1 ) * (row + line +  row * line + 1).当N和M都不大于S时,答案为N*M.

代码:

 #include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <map>
using namespace std;
typedef long long LL;
int main()
{
//freopen("input.txt", "r", stdin);
LL m, n, s;
while(cin >> m >> n >> s){
LL row = m - ( + (m - ) / s * s);//向下平移的种类数
LL line = n - ( + (n - ) / s * s );//向右平移的种类数
LL Rpoint = (n - ) / s + ;
LL Lpoint = (m - )/ s + ;//Rpoint * Lpoint为以第一个格子为起点时起点的个数
if(s >= max(m, n)) {cout << n * m <<endl;continue;}//这种情况特判
cout << (row + line + (row * line) + ) * (Rpoint * Lpoint) << endl;
}
return ;
}

CodeForces 32C Flea的更多相关文章

  1. CodeForces 32C. Flea 水题

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

  2. CodeForces 32C

    额  找找规律吧  要用long long 才过. #include <cstdio> #include <algorithm> using namespace std; in ...

  3. Codeforces Beta Round #51 A. Flea travel 水题

    A. Flea travel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/problem ...

  4. D. Frets On Fire 【二分,前缀和】 (Codeforces Global Round 2)

    题目传送门:http://codeforces.com/contest/1119/problem/D D. Frets On Fire time limit per test 1.5 seconds ...

  5. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  6. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  7. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  8. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  9. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

随机推荐

  1. BZOJ4320 ShangHai2006 Homework(分块+并查集)

    考虑根号分块.对于<√3e5的模数,每加入一个数就暴力更新最小值:对于>√3e5的模数,由于最多被分成√3e5块,查询时对每一块找最小值,这用一些正常的DS显然可以做到log,但不太跑得过 ...

  2. hdu 1695 GCD (欧拉函数+容斥原理)

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  3. JAVA 异常处理的认知学习过程

    没有异常处理 学生时代,我编写的java代码中,很少会有try catch.最主要的原因如下: 应用的规模很小 没有不确定因素 代码可控性高 如果规模小,往往就没有复杂的逻辑链路,整个软件的分层也很浅 ...

  4. [UOJ #48]【UR #3】核聚变反应强度

    题目大意:给你一串数$a_i$,求$sgcd(a_1,a_i)$,$sgcd(x,y)$表示$x,y$的次大公约数,若没有,则为$-1$ 题解:即求最大公约数的最大约数,把$a_1$分解质因数,求出最 ...

  5. [ZJOI2005]沼泽鳄鱼 矩阵乘法

    ---题面--- 题解: 乍一看还是挺懵逼的.和HH去散步很像,思路也是类似的. 复制一段我在HH去散步的题解里面写的一段话吧: 考虑f[i][j]表示i和j是否右边相连,有为1,否则为0,那么f同时 ...

  6. c++(类) this指针

    this指针的相关概念: this只能在成员函数中使用.全局函数,静态函数都不能使用this.实际上,成员函数默认第一个参数为T* const register this. 为什么this指针不能再静 ...

  7. (转)Notepad++

    包括notepad++的详细的安装过程,插件使用说明,技巧…… crifan http://www.crifan.com/files/doc/docbook/rec_soft_npp/release/ ...

  8. ViewPager使用--文章集锦

    viewpager中彻底性动态添加.删除Fragment Android ViewPager使用详解 fragment中嵌套viewpager,vierpager中有多个fragment,不显示 .. ...

  9. Codeforces 542C - 漫长艰辛的解题历程

    尽管在下面的一部分解题的方法都有问题... 但是每一次重新提交都是打了一个有意义的补丁的呢 可见在我做题的过程中有多少问题存在... 现在想想,类似于是变量没有开int64,过程函数忘开int64.. ...

  10. 河南省第十届省赛 Binary to Prime

    题目描述: To facilitate the analysis of  a DNA sequence,  a DNA sequence is represented by a binary  num ...