Codeforces 712C. Memory and De-evolution

Source: Internet
Author: User

Title Link: Http://codeforces.com/problemset/problem/712/C

Test instructions

Give you two values A and B (a > B), which means there are two equilateral triangle, the side lengths are A and B, you can transform the triangles with the side length A, each change you can select an edge, and give it a length, of course, you can also make a triangle after the transformation is completed. Ask at least how much The second transformation can transform the equilateral triangle's three-side length from A to B.

Ideas:

The meaning of the topic from the big triangle to the small triangle, here can be replaced by a way, that is, "at least how many times the transformation can be side length from B to a", you can think of, what needs to be done here is to let three sides in the range of change as close as possible to a. That is, for side length (BA, BB, Change range for BA < BB + BC, if BB + BC <= A, then in order to let BA closer to a, you can let BA take BB + BC -1, if BB + BC < A, then BA directly take A is good; Then make the same transformation for the second side BB, and then know that the iteration continues until ba = bb = BC = A, the end of the transformation is good.

Code:

1#include <bits/stdc++.h>2 3 using namespacestd;4typedefLong LongLL;5 6 Const intMAXN =100000;7 intSt, ed, ans =0;8 9 voidSolvintAintBintc) {Ten     if(A = = b && a = = c && a = = st)return ; Oneans++; A     if(Ans%3==1) St < b + c? A = St:a = B + C-1;//make the first edge as close as possible to St -     Else if(Ans%3==2) St < A + c? b = St:b = a + C-1; -     ElseSt < A + b? c = St:c = a + B-1; the Solv (A, B, c); - } -  - intMain () { + Ios_base::sync_with_stdio (); Cin.tie (); -Cin >> St >>Ed; + Solv (Ed, Ed, ed); Acout << ans <<Endl; at     return 0; -}

 

Codeforces 712C. Memory and De-evolution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.