hdu 2335 Containers

水题,就不解释了,不过这个题有一点很好,就是枚举的时候,枚举宽,也就是列数,因为这样才能越来越接近正方形

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 #include<algorithm>
 5 #include<cmath>
 6 #include<string>
 7 #include<queue>
 8 #include<stack>
 9 #include<map>
10 #include<vector>
11 #define maxn 5000
12 #define MAXN 2005
13 #define MAXM 20000005
14 #define INF  100000000000000
15 #define oo 1000000007
16 using namespace  std;
17 
18 typedef long long LL;
19 int main()
20 {
21     int t;
22     while(scanf("%d",&t)!=EOF)
23     {
24         while(t--)
25         {
26             LL n,x,y;
27             LL min_n=INF;
28             scanf("%I64d",&n);
29             n=(n+4)/5;
30             LL tem=(LL)sqrt(double(n));
31             for(LL i=1; i<=tem; i++)
32             {
33                 LL j=(n+(i-1))/i;
34                 LL xx=i*40+(i+1)*4;
35                 LL yy=j*8+(j+1)*2;
36                 //printf("%I64d %I64d %I64d %I64d\n",i,j,xx,yy);
37                 if(xx*yy<min_n)
38                 {
39                     x=xx;
40                     y=yy;
41                     min_n=xx*yy;
42                 }
43                 else if(xx*yy==min_n)
44                 {
45                     if(abs(x-y)>abs(xx-yy))
46                     {
47                         x=xx;
48                         y=yy;
49                     }
50                 }
51             }
52             printf("%I64d X %I64d = %I64d\n",max(x,y),min(x,y),min_n);
53 
54         }
55     }
56     return 0;
57 }

 

posted on 2015-04-07 19:54  tsw123  阅读(238)  评论(1编辑  收藏  举报

导航