CodeForces 32C Flea
题目链接: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的更多相关文章
- CodeForces 32C. Flea 水题
C. Flea time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...
- CodeForces 32C
额 找找规律吧 要用long long 才过. #include <cstdio> #include <algorithm> using namespace std; in ...
- Codeforces Beta Round #51 A. Flea travel 水题
A. Flea travel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/problem ...
- 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 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
随机推荐
- DataBase -- Customers Who Never Order
Question: Suppose that a website contains two tables, the Customers table and the Orders table. Writ ...
- number 解题报告
number 题目描述 给定整数 \(m,k\),求出正整数 \(n\) 使得 \(n+1,n+2,-,2n\) 中恰好有 \(m\) 个数在二进制下恰好有 \(k\) 个 \(1\). 有多组数据. ...
- Socket和ServerSocket学习笔记
对于即时类应用或者即时类的游戏,HTTP协议很多时候无法满足于我们的需求.这会,Socket对于我们来说就非常实用了.下面是本次学习的笔记.主要分异常类型.交互原理.Socket.ServerSock ...
- javascript错误处理(转)
1.onerror事件处理函数onerror事件处理函数是第一个用来协助javascript处理错误的机制.页面上出现异常时,error事件便在window对象上触发.例如: <html> ...
- java三
1,深复制与浅复制 浅复制:被复制对象的所有变量都含有与原来的对象相同的值,而所有的对其他对象的引用仍然指向原来的对象.换言之,浅复制仅仅复制所考虑的对象,而不复制它所引用的对象. 深复制:被复制对象 ...
- HDOJ 3501 Calculation 2
题目链接 分析: 要求的是小于$n$的和$n$不互质的数字之和...那么我们先求出和$n$互质的数字之和,然后减一减就好了... $\sum _{i=1}^{n} i[gcd(i,n)==1]=\le ...
- POJ 3617 Best Cow Line (模拟)
题目链接 Description FJ is about to take his N (1 ≤ N ≤ 2,000) cows to the annual"Farmer of the Yea ...
- [bzoj3884]上帝与集合的正确用法——欧拉函数
题目大意 题解 出题人博客 代码 #include <bits/stdc++.h> using namespace std; const int M = 10001000; int phi ...
- Opencv 学习笔记之——鼠标,进度条操作
Opencv中提供一个鼠标调用的函数,SetMouseCallback()函数,它配合一个回调函数来实现鼠标操作的功能. 首先看一下SetMouseCallback的函数原型: c++: void ...
- (七)计算G711语音的打包长度和RTP里timestamp的增长量
如何计算G711语音等的打包长度和RTP里timestamp的增长量 一般对于不同的语音有不同的打包周期,而不同的打包周期又对应着不同的timestamp in RTP 那么是如何计算的呢,我们通过G ...