The beauty of programming in the second round of the 2013 qualifying round

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.