Rectangle
Time Limit: 1000 ms memory limit: 256 MB
Description
In the grid consisting of n horizontal lines and m vertical lines, place K stones. Each stone can only be placed at the intersection of the grid. In the optimal placement mode, the maximum number of rectangles with four sides parallel to the coordinate axis can be found, with exactly one stone on each of the four corners.
Input
The input file contains multiple groups of trial data.
The first line is an integer T, which is the number of data groups. Next we will give the trial data for each group of workers in sequence.
Each group of data contains three integers n, m, and K separated by spaces.
Output
For each group of test data, output a line "case # X: Y", where X indicates the number of test data, and y indicates the maximum number of rectangle that can be found. All data is numbered from 1 in the read order.
Data range
1 ≤ t ≤100
0 ≤ k ≤ n * m
Small Data: 0 <n, m ≤ 30
Big Data: 0 <n, m ≤ 30000
-
Example Input
-
33 3 84 5 137 14 86
-
Example output
-
Case #1: 5Case #2: 18Case #3: 1398
#include<cstdio>#include<cmath>#define ll long longint n,m,k;int min(int a,int b){return a<b?a:b;}ll cal(int x){return (x-1)*x/2;}ll C(int a,int b){return cal(a)*cal(b)+(b<m?b:a)*cal(k-a*b);}int main(){ int T,b,q,r,ca=1,i;scanf("%d",&T);while(T--){scanf("%d%d%d",&n,&m,&k);printf("Case #%d: ",ca++);if(n>m){ll t=n;n=m;m=t;}q=sqrt(1.0*k);r=min(n,q);ll ans=0;for(i=2;i<=r;i++){b=min(m,k/i);if(k>=b*(i+1))continue;ll tmp=C(i,b);if(ans<tmp)ans=tmp;}printf("%lld\n",ans);}return 0;}
The beauty of programming in the second round of the 2013 qualifying round