博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Rectangle
阅读量:4694 次
发布时间:2019-06-09

本文共 1491 字,大约阅读时间需要 4 分钟。

Rectangle

Time Limit: 1000ms
Memory Limit: 65536KB
64-bit integer IO format: 
%lld      Java class name: Main
 
frog has a piece of paper divided into 
n rows and m columns. Today, she would like to draw a rectangle whose perimeter is not greater than k.
 
 
There are 
8 (out of 9) ways when n=m=2,k=6
 
Find the number of ways of drawing.
 

Input

The input consists of multiple tests. For each test:
 
The first line contains 
3 integer n,m,k (1n,m5104,0k109).
 

Output

For each test, write 
1 integer which denotes the number of ways of drawing.
 

Sample Input

2 2 61 1 050000 50000 1000000000

Sample Output

801562562500625000000
有技巧的暴力搜索方法:
    设总方格长和宽分别为n,m,一个长为i,宽为j(j 可以大于i,这里只是为了与总方格相对应)的矩形,可以找到有(n-i+1)*(m-j+1)个这样的矩形。
    并且, i <= min(n,k-1), 取过i后,j <= min(m,k-i);有i = (1 ~ min(n,k-1)),j = (1~min(m,k-i));所以可以通过枚举i,并且由于j的值符合等差级数,可以通过“首项加末项乘以项数除以二”快速求得j。
    所有,sum[i] = (n-i+1),sum[j] = ( (m-1+1)+(m-j+1) ) * j / 2 ; ans += sum[i]*sum[j],即得。
 
#include
#include
#include
#include
#define ll long long//BNUOJ似乎不识别__int64;using namespace std;int main(){ ll n,m,k; while(~scanf("%I64d%I64d%I64d",&n,&m,&k)){ k /= 2; ll ans = 0; ll nn = min(n,k-1); for(ll i = 1; i <= nn; i++){ ll j = min(m,k - i); ans += (n - i + 1)*(m + m - j + 1)*j/2; } cout<
<

 

转载于:https://www.cnblogs.com/ACMessi/p/4852668.html

你可能感兴趣的文章
小甲鱼OD学习第1讲
查看>>
HDU-1085 Holding Bin-Laden Captive-母函数
查看>>
php提示undefined index的几种解决方法
查看>>
LRJ
查看>>
Struts2环境搭建
查看>>
Linux: Check version info
查看>>
stl学习之测试stlen,cout等的运行速度
查看>>
魔戒三曲,黑暗散去;人皇加冕,光明归来
查看>>
Error和Exception
查看>>
Python和Singleton (单件)模式[转载]
查看>>
httpclient设置proxy与proxyselector
查看>>
IT常用单词
查看>>
拓扑排序
查看>>
NYOJ--32--SEARCH--组合数
查看>>
JMS
查看>>
gulpfile 压缩模板
查看>>
【34.14%】【BZOJ 3110】 [Zjoi2013]K大数查询
查看>>
【 henuacm2016级暑期训练-动态规划专题 A 】Cards
查看>>
第五篇:白话tornado源码之褪去模板的外衣
查看>>
设备常用框架framework
查看>>