Rectangle

frog has a piece of paper divided into nn rows and mm columns. Today, she would like to draw a rectangle whose perimeter is not greater than kk.

There are 88 (out of 99) ways when n=m=2,k=6n=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 33 integer n,m,kn,m,k (1≤n,m≤5⋅104,0≤k≤1091≤n,m≤5⋅104,0≤k≤109).

Output

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

Sample Input

    2 2 6
1 1 0
50000 50000 1000000000

Sample Output

    8
0
1562562500625000000
解析:枚举矩形的长h,然后它在h的方向上就有n-h+1种放法,同时宽的最大值w即为k/2 - h,对于每个0~w的宽度wi,它在w方向上的放法有m-wi+1种,求和即为所求方案数 我推出了数学公式
n*m中a*b的种数:(n-a+1)*(m-b+1)+(m-a+1)*(n-b+1)
这样仍会超时:a不变,b变化,推出一个公式。
1^2+2^2+3^2+……+n^2=n*(n+1)*(2*t+1)/6;
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#define ll long long
using namespace std;
int main()
{
ll n,m,k;
while(~scanf("%lld %lld %lld",&n,&m,&k))
{
ll s=;
ll temp;
if(k<&&k>=) s=n*m;
else if(k<) s=;
else
{
if(n>m)
{
temp=n;
n=m;
m=temp;
}
for(ll a=;a<=n;a++)
{
ll b=min(k/-a,m);
if(b>=a)
{
s+=(n-a+)*((m-a+)+(m-b+))*(b-a+)/;
}
b=min(k/-a,n);
if(b>=a)
{
s+=(m-a+)*((n-a+)+(n-b+))*(b-a+)/;
}
}
ll t=min(k/,n);
t=min(t,m);
ll ss=;
ss+=(t*(t+)*(*t+))/-(t+)*t*(n+m+)/+(n*m++n+m)*t;//中间有重复的情况,a=b的算了两次
s=s-ss;
}
printf("%lld\n",s);
}
return ;
}
也有更简单的思路:
#include <bits/stdc++.h>
using namespace std; int main(){
#ifdef sxk
freopen("in.txt", "r", stdin);
#endif // sxk long long n, m, k;
while(cin>>n>>m>>k){
k /= ;
long long ans = ;
for(int h=; h<=n; h++){
int w = k - h;
if(w <= ) break;
if(w > m) w = m;
ans += (n - h + ) * (m + m-w+)*w/; //对于每个h,在h方向上n-h+1种,在w方向上枚举wi求和为(m + m-w+1) * w / 2种
}
cout<<ans<<endl;
}
return ;
}


四川第七届 E Rectangle的更多相关文章

  1. 四川第七届 D Vertex Cover(二分图最小点覆盖,二分匹配模板)

    Vertex Cover frog has a graph with nn vertices v(1),v(2),…,v(n)v(1),v(2),…,v(n) and mm edges (v(a1), ...

  2. 四川第七届 I Travel(bfs)

    Travel The country frog lives in has nn towns which are conveniently numbered by 1,2,…,n1,2,…,n. Amo ...

  3. 四川第七届 C Censor (字符串哈希)

    Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text pp. Her j ...

  4. 第七届河南省赛H.Rectangles(lis)

    10396: H.Rectangles Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 229  Solved: 33 [Submit][Status] ...

  5. 山东省第七届ACM省赛------Memory Leak

    Memory Leak Time Limit: 2000MS Memory limit: 131072K 题目描述 Memory Leak is a well-known kind of bug in ...

  6. 山东省第七届ACM省赛------Reversed Words

    Reversed Words Time Limit: 2000MS Memory limit: 131072K 题目描述 Some aliens are learning English. They ...

  7. 山东省第七届ACM省赛------Triple Nim

    Triple Nim Time Limit: 2000MS Memory limit: 65536K 题目描述 Alice and Bob are always playing all kinds o ...

  8. 山东省第七届ACM省赛------The Binding of Isaac

    The Binding of Isaac Time Limit: 2000MS Memory limit: 65536K 题目描述 Ok, now I will introduce this game ...

  9. 山东省第七届ACM省赛------Fibonacci

    Fibonacci Time Limit: 2000MS Memory limit: 131072K 题目描述 Fibonacci numbers are well-known as follow: ...

随机推荐

  1. Go reflect反射

    Go语言中的反射非常强大,可以对string, int, struct, func...进行反射,使用起来也比较简单. 示例1:反射函数 package main import ( "fmt ...

  2. Python 条件判断语句(if ,elif, else)

    条件判断可以分: 单分支判断:只有一个if语句 双分支判断:if else 的格式 多分支判断:if elif  else 的格式 条件语句嵌套判断 # 下面是个条件多分支判断 score = 85 ...

  3. SQL中的5种常用的聚集函数

    首先你要知道 where->group by->having->order by/limit  ,这个就是写sql语句时的顺序  常用的5个聚集函数: Max             ...

  4. java基础(2)-面向对象(1)

    面向对象 面向对象思想 面向对象是相对面向过程而言 面向对象和面向过程都是一种思想 面向过程:强调的是功能行为 面向对象:将功能封装进对象,强调具备了功能的对象 面向对象是基于面向过程的 面向对象举例 ...

  5. mysql在表的某一位置增加一列的命令

    如果想在一个已经建好的表中添加一列,可以用诸如: alter table t1 add column addr varchar(20) not null; 这条语句会向已有的表t1中加入一列addr, ...

  6. contenteditable支持度

    contenteditable attribute (basic support) - Working Draft Global user stats*: Support: 86.71% Partia ...

  7. alias 中使用awk

    alias hehistory10='history |awk "{print \$2}"|sort|uniq -c|sort -rn|head -10' $要转义

  8. SQL SERVER 集合

    死锁和堵塞一直是性能测试执行中关注的重点. 下面是我整理的监控sql server数据库,在性能测试过程中是否出现死锁.堵塞的SQL语句,还算比较准备,留下来备用. --每秒死锁数量 SELECT * ...

  9. ural 2019 Pair: normal and paranormal

    2019. Pair: normal and paranormal Time limit: 1.0 secondMemory limit: 64 MB If you find yourself in ...

  10. ural 1039 树dp

    http://acm.timus.ru/problem.aspx?space=1&num=1039 1039. Anniversary Party Time limit: 0.5 second ...