首页 > 其他 > 详细

Problem B. Beer Refrigerator

时间:2019-04-05 11:01:07      阅读:131      评论:0      收藏:0      [点我收藏+]

http://codeforces.com/gym/241680/problem/B
比赛的时候考虑的是,它们3个尽可能接近,然后好麻烦,不如暴力枚举,这里不需要质因数分解,而是两重循环枚举所有因数,第3个因数也就随之确定

技术分享图片
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<queue>
 4 #include<algorithm>
 5 #include<cmath>
 6 #include<ctime>
 7 #include<set>
 8 #include<map>
 9 #include<stack>
10 #include<cstring>
11 #define inf 2147483647
12 #define ls rt<<1
13 #define rs rt<<1|1
14 #define lson ls,nl,mid,l,r
15 #define rson rs,mid+1,nr,l,r
16 #define N 100010
17 #define For(i,a,b) for(int i=a;i<=b;i++)
18 #define p(a) putchar(a)
19 #define g() getchar()
20 
21 using namespace std;
22 int x;
23 int a[1010];
24 int cnt;
25 int k;
26 int ans=inf;
27 int ANS[10];
28 void in(int &x){
29     int y=1;
30     char c=g();x=0;
31     while(c<0||c>9){
32         if(c==-)y=-1;
33         c=g();
34     }
35     while(c<=9&&c>=0){
36         x=(x<<1)+(x<<3)+c-0;c=g();
37     }
38     x*=y;
39 }
40 void o(int x){
41     if(x<0){
42         p(-);
43         x=-x;
44     }
45     if(x>9)o(x/10);
46     p(x%10+0);
47 }
48 int main(){
49     freopen("beer.in","r",stdin);
50     freopen("beer.out","w",stdout);
51     in(x);
52     For(i,1,x)
53         if(x%i==0)
54             a[++cnt]=i;
55     For(i,1,cnt)
56         For(j,1,cnt){
57             k=x/a[i]/a[j];
58             if(x!=a[i]*a[j]*k)
59                 continue;
60             if(ans>a[i]*a[j]+a[i]*k+a[j]*k){
61                 ans=a[i]*a[j]+a[i]*k+a[j]*k;
62                 ANS[1]=a[i];
63                 ANS[2]=a[j];
64                 ANS[3]=k;
65             }
66         }
67     o(ANS[1]);p( );
68     o(ANS[2]);p( );
69     o(ANS[3]);
70     return 0;
71 }
View Code

 

Problem B. Beer Refrigerator

原文:https://www.cnblogs.com/war1111/p/10658017.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!