Flea CodeForces - 32C

原题链接
考察:思维(?)
思路:
  我的做法略笨.先以第一行第一列为起点看最多能占几个.然后再枚举以第一行的点为起点的最多跳跃数.同理枚举第一列的点为起点的最多跳跃数.需要记录最大的行列能取到哪,因为枚举到\((1+s,1+s)\)的位置.

Code

#include <iostream>
#include <cstring>
using namespace std;
typedef long long LL;
int n,m,s;
LL solve()
{
	int a = (n+s-1)/s,b = (m+s-1)/s; 
	LL cnt = (LL)a*b;
	if(cnt==1) return (LL)m*n;
	//以第1行 开始 
	LL ans = cnt;
	int row = 1,col = 1;
	for(int i=2;i<1+s;i++)
	{
		int c = (n+s-i)/s;
		if((LL)c*b==cnt) ans+=cnt,col = i;
		else break;
	}
	for(int i=2;i<1+s;i++)
	{
		int c = (m+s-i)/s;
		if((LL)c*a==cnt) ans+=cnt,row = i;
		else break;
	}
	ans+=(LL)(row-1)*(col-1)*cnt;
	return ans;
}
int main()
{
	scanf("%d%d%d",&n,&m,&s);
	printf("%lld\n",solve());
	return 0;
}

posted @ 2021-09-13 13:27  acmloser  阅读(22)  评论(0编辑  收藏  举报