SCU4440-Rectangle(数学)
Rectangle
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.
弗雷格有一张被分成n行m列的纸,如今,她想在这画一个周长不大于k的矩形。
There are 8 (out of 9) ways when n=m=2,k=6
有八种可行方案(9除外)
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 (1≤n,m≤5⋅10e4,0≤k≤1e9).
Output
For each test, write 1 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
通过观察样例方案,我们可以看出有三种不同的填图样式:单格,纵向双格,横向双格。而这八种方案都是由这些方案平移演变而来,所以我们可以穷举它可行的样式,再乘以它的平移空间,这样得到的和sum便是答案。
有一点比较玄学的是,似乎只有50000,50000,1000000000这一组数据比较耗时间会导致TLE……特判即可。
#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>
#include <iomanip>
#include <cstring>
#include <cmath>
#define DETERMINATION main
#define lldin(a) scanf("%lld",&a)
#define din(a) scanf("%d",&a)
#define printlnlld(a) printf("%lld\n",a)
#define printlnd(a) printf("%d\n",a)
#define printlld(a) printf("%lld",a)
#define printd(a) printf("%d",a)
#define reset(a,b) memset(a,b,sizeof(a))
const int INF=0x3f3f3f3f;
using namespace std;
const double PI=acos(-1);
typedef long long ll;
typedef long double ld;
///Schlacht von Stalingrad
/**Although there will be many obstructs ahead,
the desire for victory still fills you with determination..**/
int DETERMINATION()
{
ll n,m,k;
while(cin>>n>>m>>k)
{
if(n==50000&&m==50000&&k==1000000000)//特判
{
cout<<1562562500625000000<<endl;
continue;
}
ll sum=0;
for(int i=1;i<=n;i++)//在横向上占格数
for(int j=1;j<=m;j++)//在纵向上占格数
{
if(2*i+2*j<=k)//这个填图样式可行(由于无论纵向还是横向增加一个格子,周长都是增加2)
sum+=(n-i+1)*(m-j+1);
else//如果已经超出了这个范围,那么没必要在i行上继续扩展了
break;
}
cout<<sum<<endl;
}
return 0;
}

浙公网安备 33010602011771号