题目链接: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. HDU 1556 线段树/树状数组/区间更新姿势 三种方法处理

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  2. [POJ2777] Count Color

    \[Count Color\] Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 50865 Accepted: 15346 Des ...

  3. DES 加密解密

    [概念] 数据加密算法(Data Encryption Algorithm,DEA)是一种对称加密算法,很可能是使用最广泛的密钥系统,特别是在保护金融数据的安全中,最初开发的DEA是嵌入硬件中的.通常 ...

  4. CMU Bomblab 答案

    室友拉我做的... http://csapp.cs.cmu.edu/3e/labs.html Border relations with Canada have never been better. ...

  5. Git命令文本手册

    git init # 初始化本地git仓库(创建新仓库) git config --global user.name "xxx" # 配置用户名 git config --glob ...

  6. MSTest DeploymentItemAttribute

    该attribute可以把指定的文件拷贝到每次运行的Out目录下,比如有一个config文件,那么用下面的命令, [TestClass] [DeploymentItem("Default.c ...

  7. java字符串 64位编码

    byte[] encodeBase64 = Base64.encodeBase64("到了是是是是".getBytes("UTF-8")); System.ou ...

  8. 【BZOJ5005】乒乓游戏 [线段树][并查集]

    乒乓游戏 Time Limit: 10 Sec  Memory Limit: 256 MB Description Input Output Sample Input 5 1 1 5 1 5 11 2 ...

  9. 网络流专题练习Day1

    04/16 一共做了8道题 首先网络流目前自己掌握的只有最大流Dinic算法和普通的费用流算法 有空还要去学习一下SAP和ZKW费用流(flag早早立在前面以后看到都有动力... 但网络流的算法个人认 ...

  10. [BZOJ1031][JSOI2007]字符加密Cipher 解题报告

    Description 喜欢钻研问题的JS 同学,最近又迷上了对加密方法的思考.一天,他突然想出了一种他认为是终极的加密办法:把需要加密的信息排成一圈,显然,它们有很多种不同的读法.例如下图,可以读作 ...