• HDU 多校对抗赛 A Maximum Multiple


    Maximum Multiple

    Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 494    Accepted Submission(s): 215


    Problem Description
    Given an integer n, Chiaki would like to find three positive integers xy and z such that: n=x+y+zxnynzn and xyz is maximum.
     
    Input
    There are multiple test cases. The first line of input contains an integer T (1T106), indicating the number of test cases. For each test case:
    The first line contains an integer n (1n106).
     
    Output
    For each test case, output an integer denoting the maximum xyz. If there no such integers, output 1 instead.
     
    Sample Input
    3 1 2 3
     
    Sample Output
    -1 -1 1
     
    题意:

    找到三个正整数x,y和z,使得:n = x + y + z,x /n,y / n,z / n和xyz是最大的。


     题解:

    x+y+z=n

    设r=n/x,s=n/y,t=n/z

    所以 1/r+1/s+1/t=1;

    设 r<=s<=t;

    所以r<=3

    r=2     1/s+1/t=1/2;   s=t=4  | s=3 ,t=6

    r=3      s=t=3; 

    如果3/n的话 就分成 n/3,n/3,n/3;

    n/2,n/4,n/4;

    n/2,n/3,n/6; //这种的乘积小于其余的,舍弃

    n可以被3整除的话就分成n/3,n/3,n/3的情况
    n可以被4整除的情况就分成n/2,n/4,n/4的情况
     

    代码如下

    #include <cstdio>
    #include <algorithm>
    #include <iostream>
    using namespace std;
    typedef long long ll;
    int main(){
      int T;
      scanf("%d",&T);
      while(T--){
         ll n;
         scanf("%lld",&n);
         if(n%3==0){
           ll x=n/3;
           ll ans=x*x*x;
           printf("%lld
    ",ans);
         }
         else if (n%4==0){
           ll x=n/2;
           ll ans=x*n/4*n/4;
           printf("%lld
    ",ans);
         }else{
           printf("-1
    ");
         }
      }
      return 0;
    }
    View Code
    每一个不曾刷题的日子 都是对生命的辜负 从弱小到强大,需要一段时间的沉淀,就是现在了 ~buerdepepeqi
  • 相关阅读:
    java中讲讲PrintStream的用法,举例?
    Spark Scala当中reduceByKey的用法
    springboot与ActiveMQ整合
    solr(六): 集群
    zookeeper集群
    solr(五): centos中, 整合 tomcat&solr
    springboot redis(单机/集群)
    redis 五种数据类型
    redis 集群搭建: redis-cluster
    redis 持久化
  • 原文地址:https://www.cnblogs.com/buerdepepeqi/p/9357476.html
Copyright © 2020-2023  润新知