22190_Reprogramming

2022-5-16 18:21| 发布者: Hocassian| 查看: 24| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-5-89506187161000-Problem List-采集的数据-后羿采集器.html

Pro.ID

22190

Title

Reprogramming

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=22190

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 3000/1000 MS (Java/Others)     Memory Limit: 131072/65536 K (Java/Others)
  • 描述

    Recently Doctor Guan has discovered two new kinds of bacteria and named them BT-U and BT-V. BT-U and BT-V are quite special, they can only live with the help of each other. Doctor Guan did several experiments on BT-U and BT-V, here’re the results:
    Put 100 BT-Us and 80 BT-Vs together, one minute later, there are 20 BT-Us and 80 BT-Vs, one minute later again, there are 20 BT-Us and 60 BT-Vs, then 20 BT-Us and 40 BT-Vs, then 20 BT-Us and 20 BT-Vs, then these 20 BT-Us and 20 BT-Vs keep alive.
    Put 3 BT-Us and 5 BT-Vs together, one minute later, there are 3 BT-Us and 2 BT-Vs, one more minute later there are 1 BT-U and 2 BT-Vs, then 1 BT-U and 1 BT-V, and this 1 BT-U and 1 BT-V keep alive.
    According to the results above, Doctor Guan has reached a conclusion that when putting x BT-Us and y BT-Vs together, if x=y then they keep alive, if x < y then x BT-Vs would die in one minute, if x > y then y BT-Us would die in one minute.
    Doctor Guan has made a program to determine how many BT-Us and BT-Vs survive when putting x BT-Us and y BT-Vs together. Program is as follow :

    #include<fstream.h>

    ifstream filein("reprog.in");

    ofstream fileout("reprog.out");

    int main(){

      long x,y;

      for (;;){

       filein>>x>>y;

       if( x <= 0 || y <= 0 )break;

       while(x!=y) if( x > y ) x-=y; else y-=x;

       fileout<<x<<endl;

       }

       return 0;

    }

    But this program is quite inefficient; Doctor Guan needs your help to improve it.

    输入

    There're multiple cases. For each case there's one line containing two integers for x and y. Input is end with two 0's.

    输出

    Description
    Recently Doctor Guan has discovered two new kinds of bacteria and named them BT-U and BT-V. BT-U and BT-V are quite special, they can only live with the help of each other. Doctor Guan did several experiments on BT-U and BT-V, here’re the results:
    Put 100 BT-Us and 80 BT-Vs together, one minute later, there are 20 BT-Us and 80 BT-Vs, one minute later again, there are 20 BT-Us and 60 BT-Vs, then 20 BT-Us and 40 BT-Vs, then 20 BT-Us and 20 BT-Vs, then these 20 BT-Us and 20 BT-Vs keep alive.
    Put 3 BT-Us and 5 BT-Vs together, one minute later, there are 3 BT-Us and 2 BT-Vs, one more minute later there are 1 BT-U and 2 BT-Vs, then 1 BT-U and 1 BT-V, and this 1 BT-U and 1 BT-V keep alive.
    According to the results above, Doctor Guan has reached a conclusion that when putting x BT-Us and y BT-Vs together, if x=y then they keep alive, if x < y then x BT-Vs would die in one minute, if x > y then y BT-Us would die in one minute.
    Doctor Guan has made a program to determine how many BT-Us and BT-Vs survive when putting x BT-Us and y BT-Vs together. Program is as follow :

    #include<fstream.h>

    ifstream filein("reprog.in");

    ofstream fileout("reprog.out");

    int main(){

      long x,y;

      for (;;){

       filein>>x>>y;

       if( x <= 0 || y <= 0 )break;

       while(x!=y) if( x > y ) x-=y; else y-=x;

       fileout<<x<<endl;

       }

       return 0;

    }

    But this program is quite inefficient; Doctor Guan needs your help to improve it.

    Input
    There're multiple cases. For each case there's one line containing two integers for x and y. Input is end with two 0's.
    Output
    For each case output the result in a single line.
    Sample Input
    2 2
    1 1
    0 0
    Sample Output
    2
    1
    Source

    样例输入

    2 2
    1 1
    0 0

    样例输出

    2
    1

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部