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