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
    **************************************
  • 相关阅读:
    Kafka 生产者 自定义分区策略
    同步互斥
    poj 1562 Oil Deposits(dfs)
    poj 2386 Lake Counting(dfs)
    poj 1915 KnightMoves(bfs)
    poj 1664 放苹果(dfs)
    poj 1543 Perfect Cubes (暴搜)
    poj 1166 The Clocks (暴搜)
    poj 3126 Prime Path(bfs)
    处理机调度
  • 原文地址:https://www.cnblogs.com/Wurq/p/3750297.html
Copyright © 2011-2022 走看看