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的概 ...
随机推荐
- 【题解】JSOI2010满汉全席
~bzoj1823 第一次接触2-SAT——SAT,即适定性(Satisfiability)的缩写.像名称所说,即满足需求的可能性问题,而k-SAT即每个人有k种需求,已经证明k>2时是一个NP ...
- 线程 condition_variable
http://www.cnblogs.com/haippy/p/3252041.html 理解wait():当前线程调用 wait() 后将被阻塞(此时当前线程应该获得了锁(mutex).在线程被阻塞 ...
- 解决echarts中X轴文字过长的问题。【转】
axisLabel: { interval: , formatter:function(value) { debugger var ret = "";//拼接加\n返回的类目项 ; ...
- ViewData和ViewBag的那些事
既然结论是“共享着相同的数据”,那我们就证实一下吧. 看来结论是正确的. 去查看定义,发现他们的类型是不一样的,ViewData是ViewDataDictionary,ViewBag是dynamic. ...
- gitlab迁移升级
一.迁移步骤 1.首先安装最新版本gitlab(gitlab7.2安装) 2.停止旧版本gitlab服务 3.将旧的项目文件完整导入新的gitlab bundle exec rake gitlab:i ...
- JS中二维数组的声明
var myarr=new Array(); //先声明一维 for(var i=0;i<2;i++){ //一维长度为2 myarr[i]=new Array(); //再声明二维 for(v ...
- Java之戳中痛点 - (2)取余用偶判断,不要用奇判断
取余判断原则:取余用偶判断,不要用奇判断 先看一个 程序: package com.test; import java.util.Scanner; public class t1 { public s ...
- centos 安装mysql 笔记
1.查询已安装软件的目录 rpm -ql mysql 2.mysql的安装卸载 a. 查找已安装的myslq 版本: #rpm -qa | grep mysql (注意大小写,如果mysql 不行 ...
- iconfont字体图标
1.1.进入阿里图标网站 http://www.iconfont.cn/ 1.2.在购物车里添加自己需要的字体图标 1.3.下载代码 1.4.解压过后,找到iconfont.css,放在你的项目里,需 ...
- 在eclipse中使用JUnit4,以及使用JUnit4进行单元测试的技巧
一 在eclipse中使用JUnit4 首先在工程上右键,选择属性,找到Java Builder Path,添加JUnit4的lib,如下图: 在要测试的类上右键新建 Junit test cas ...