HDU 5100 chessboard uses a k x 1 rectangle to cover the square board of N x n

Source: Internet
Author: User
Click Open Link
Chessboard Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 335 accepted submission (s): 168


Problem descriptionconsider 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.
Inputthere are multiple test cases in the input file.
First line contain the number of cases T ( T ≤ 10000 ).
In the next t lines contain t cases, each case has two integers N and K .( 1 ≤ n, k ≤ 100 )
Outputprint the maximum number of chessboard squares tiled.
Sample Input
26 35 3
 
Sample output
3624
 
Sourcebestcoder round #17 Use a k × 1 small rectangle to overwrite an n × n square board and ask how many square boards can be covered.
The rule is: if n is less than K, it will definitely not work. Define mod = n % K; If (mod <= K/2), the result is: N * n-mod * MOD; Otherwise, the result is N * N-(k-mod) * (k-MoD ); Click here to prove
//0MS228K#include<stdio.h>int main(){    int t,n,k;    scanf("%d",&t);    while(t--)    {        scanf("%d%d",&n,&k);        if(n<k){printf("0\n");continue;}        int mod=n%k;        if(mod<=k/2)printf("%d\n",n*n-mod*mod);        else printf("%d\n",n*n-(k-mod)*(k-mod));    }    return 0;}


HDU 5100 chessboard uses a k x 1 rectangle to cover the square board of N x n

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.