bestcoder#17 1001&&HDU 5100 Chessboard(数学)

Chessboard

                                                                  点击打开题目链接
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 85    Accepted Submission(s): 50


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 ( ). 
In the next T lines contain T cases , Each case has two integers n and k. ( )
 

Output
Print the maximum number of chessboard squares tiled.
 

Sample Input
  
  
2 6 3 5 3
 

Sample Output
  
  
36 24
 

Source
 


先来吐槽一下题目,我去,就两句话的英语,读了好长时间才读懂,这次1001栽了不少人;
题目很简单,给一个n*n的正方形棋盘,由kX1的小块组成,问用这个小的(k*1)的小块来覆盖棋盘,最多能占多少格(每格是一个1X1的小格);
有个结论:当n%k!=0时,最多为:n*n-min(a,b);其中a=(n%k)*(n%k),b=(k-n%k)*(k-n%k);
当n%k==0时,显然是n*n;
至于证明,当时只是感性的认为这个结论是正确的,按照贪心的思想来放的,发现最后又两种情况;
网上有一则证明:附个网址: http://www.matrix67.com/blog/archives/5900
                           http://www.brand.site.co.il/riddles/201403a.html
代码:
#include <iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<stdlib.h>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<set>
#define inf 0x3f3f3f3f
#define eps 1e-5
#define max(a,b) a>b?a:b
//#define min(a,b) a<b?a:b
using namespace std;
int main()
{
    int t,n,k,ans;
    while(~scanf("%d",&t))
    {
        while(t--)
        {
            scanf("%d%d",&n,&k);
            if(k>n)
            {
                printf("%d\n",0);
            }
            else
            {
                if(n%k==0)
                    ans=n*n;
                else
                {
                    int a=(n%k)*(n%k);
                    int b=(k-n%k)*(k-n%k);
                    ans=(n*n)-min(a,b);
                }
                printf("%d\n",ans);
            }
        }
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值