HDOJ 5100 Chessboard【规律】

来源:互联网 发布:免流源码 编辑:程序博客网 时间:2024/05/18 00:06

Chessboard

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 911    Accepted Submission(s): 384


Problem Description
Consider the problem of tiling an n×n chessboard by polyomino pieces that are k×1 in size; Every one of the k pieces of each polyomino tile must align exactly with one of the chessboard squares. Your task is to figure out the maximum number of chessboard squares tiled.
 

Input
There are multiple test cases in the input file.
First line contain the number of cases T (T10000). 
In the next T lines contain T cases , Each case has two integers n and k. (1n,k100)
 

Output
Print the maximum number of chessboard squares tiled.
 

Sample Input
26 35 3
 

Sample Output
3624
 

恩,题意大致是,n*n的正方形,要放入k*1的长方形,求能放入长方形的1*1的正方形个数,即是n*n减去不能放长方形的那块面积。要放的话,就两种情况,一种直接一排一排的放,一种是旋转着放,空的那部分在中间(画个图比较好理解),最后比较一下哪种情况空的少,然后减去,既得最大值。


#include <iostream>#include<cstdio>#include<cstring>using namespace std;int main(){    int t,n,k,s;    scanf("%d",&t);    while(t--)    {        scanf("%d%d",&n,&k);        if(n<k)        {            printf("0\n");            continue;        }        s=n*n;        int tem=n%k;        if(tem)        {            int cnt1=tem*tem;            int tt=k-tem;            int cnt2=tt*tt;            //printf("%d %d\n",cnt1,cnt2);            s=s-min(cnt1,cnt2);        }        printf("%d\n",s);    }    return 0;}


0 0