zoukankan      html  css  js  c++  java
  • Problem B. Beer Refrigerator

    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
  • 相关阅读:
    Centos7 安装 mysql5.7
    python正则表达式---七七八八
    爬虫之英雄联盟
    爬虫之User-Agent
    爬虫之证书错误
    ubuntu windows双系统 删除Ubuntu后windows系统引导修复
    ubuntu系統桌面重置
    ubuntu安装qtcreator
    win10/ubuntu双系统----ubuntu有线无线都不能上网
    pyenv 安装
  • 原文地址:https://www.cnblogs.com/war1111/p/10658017.html
Copyright © 2011-2022 走看看