赞
踩
用边长小于N的正方形方砖(注意,不要求所有的方砖大小相同,请看样例说明)不重叠地铺满N*N的正方形房间,最少要几块方砖。
题目漏写了方砖边长应为正整数,最小为1;要使方砖数最小,则需几块面积较大的方砖。使用一块边长为(N/2+1)的砖和3块边长为N/2的砖,即可占据大部分面积,留下两条边长为1的长方形。
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> #include <unistd.h> int main(void) { int N,n; scanf("%d",&N); while (N--) { scanf("%d",&n); if(n%2==0) printf("4\n"); else printf("%d\n",4+(n/2)*2); } getchar(); getchar(); return 0; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。