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. mybatis 一对多和多对一

      在学习MyBatis3的过程中,文档上面一直在强调一个id的东西!在做这个实验的时候,也因为没有理解清楚id含义而导致一对多的“多”中也只有一条数据.id和result的唯一不同是id表示的结果将 ...

  2. 【P1947】笨笨当粉刷匠(DP+前缀和)

    这个题乍一看觉得挺简单的,事实上却完全不是.首先,这个题看上去无脑直接刷就可以然而因为刷的次数远远大于木板的个数所以不行,然后开始考虑DP,自己一开始是这么想的,如果用f[t][i][j]表示刷t次时 ...

  3. Apache Phoenix数据类型

    数据类型 Java Map 占用大小 (byte) 范围 INTEGER java.lang.Integer 4 -2147483648 to 2147483647 UNSIGNED_INT java ...

  4. 导入Jquery.min.js时 JQuery 上打红X了

    问题解决:右击jquery.min.js——>MyEclipse——>点击Exclude From Validation——>点击Run Validation 即可

  5. sql中的group by 和 having 用法

    sql中的group by 用法:-- Group By语句从英文的字面意义上理解就是“根据(by)一定的规则进行分组(Group)”.--它的作用是通过一定的规则将一个数据集划分成若干个小的区域,然 ...

  6. numpy array或matrix的交换两行

    A[j,:] = A[maxindex,:] # 注意这样是一个很低级的错误!这样只是赋值 我们很容易想起python中的两个值交换一句搞定不用引入中间变量 a, b = b, a 但在numpy的a ...

  7. Codeforces 893E Counting Arrays:dp + 线性筛 + 分解质因数 + 组合数结论

    题目链接:http://codeforces.com/problemset/problem/893/E 题意: 共q组数据(q <= 10^5),每组数据给定x,y(x,y <= 10^6 ...

  8. StringUtil方法全集

    org.apache.commons.lang.StringUtils中方法的操作对象是Java.lang.String类型的对象,是JDK提供的String类型操作方法的补充,并且是null安全的( ...

  9. Explain分析查询语句

    ​表的读取顺序 读取操作的类型 可用索引,实际使用的索引 表之间的引用 每张表多少行被优化器查询 索引的长度 EXPLAIN字段解释: ØTable:显示这一行的数据是关于哪张表的 Øpossible ...

  10. java数组类Arrays:比较,填充,排序

    int i1[] = {1,2,3,4,5,6}; int i2[] = {6,5,4,3,2,1}; //排序 Arrays.sort(i2); System.out.println(i1.equa ...