zoukankan      html  css  js  c++  java
  • Cake

    Cake

    Time Limit : 1000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
    Total Submission(s) : 32   Accepted Submission(s) : 14
    Problem Description
    一次生日Party可能有p人或者q人参加,现准备有一个大蛋糕.问最少要将蛋糕切成多少块(每块大小不一定相等),才能使p人或者q人出席的任何一种情况,都能平均将蛋糕分食.
     
    Input
    每行有两个数p和q.
     
    Output
    输出最少要将蛋糕切成多少块.
     
    Sample Input
    2 3
     
    Sample Output
    4 [hint]将蛋糕切成大小分别为1/3,1/3,1/6,1/6的四块即满足要求. 当2个人来时,每人可以吃1/3+1/6=1/2 , 1/2块。 当3个人来时,每人可以吃1/6+1/6=1/3 , 1/3, 1/3块。[/hint]
     
    Author
    LL
     
    Source
    HZIEE 2007 Programming Contest
     
     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 
     4 int fun(int MAX,int MIN)
     5 {
     6     int sign;
     7     do
     8     {
     9        sign=MAX%MIN;
    10        MAX=MIN;
    11        MIN=sign;
    12        }while(MIN!=0);
    13        return (MAX);
    14 }
    15 
    16 int main()
    17 {
    18     int MAX,MIN,a,b,sum;
    19     while(scanf("%d%d",&a,&b)!=EOF)
    20     {
    21         MAX=(a>b)?a:b;
    22         MIN=a+b-MAX;
    23         sum=MAX+MIN-fun(MAX,MIN);
    24         printf("%d
    ",sum);
    25     }
    26     return 0;
    27 }
    View Code
    转载请备注:
    **************************************
    * 作者: Wurq
    * 博客: https://www.cnblogs.com/Wurq/
    * Gitee: https://gitee.com/wurq
    **************************************
  • 相关阅读:
    js人工智能对话框
    html 实现相册
    thinkphp5 三种重定向(跳转)
    thinkphp5 分页实现
    常用的Mysql数据库操作语句大全
    FormData之file图片上传
    FormData对象
    input file 上传图片时限制格式
    form 中Enctype=multipart/form-data 的作用
    thinkphp5 不刷新退出
  • 原文地址:https://www.cnblogs.com/Wurq/p/3750297.html
Copyright © 2011-2022 走看看