Codeforces Global Round 8 A. C+= (思维)

题目传送
题意:
给你俩个数a,b现在你能进行 += 操作,比如 a += b,那么a的值会加上b,而b不会变,现在给的a,b都是整数,再给一个正整数n,问最少进行几次操作使得其中的一个数大于n?

思路:
友情提示,一定要认真读题,第一次看成了俩个数都要大于n,第二次看成了,只要一个数大于等于n即可。。。。其实题目就是一个数严格大于n即可。。。

要最少操作次数,那么每次我加上最大的那个数就好啦(使得价值的增加更快)

AC代码

#include 
inline long long read(){char c = getchar();long long x = 0,s = 1;
while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();}
while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();}
return x*s;}
using namespace std;
#define NewNode (TreeNode *)malloc(sizeof(TreeNode))
#define Mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) (x)&(-x)
const int N = 1e6 + 10;
const long long INFINF = 0x7f7f7f7f7f7f7f;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-7;
const long long mod = 1e9+7;
const double II = acos(-1);
const double PP = (II*1.0)/(180.00);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> piil;
signed main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        ll a,b,n,sum = 0;
        cin >> a >> b >> n;
        while(1)
        {
            if(a > n || b > n) break;
            if(a > b) swap(a,b);
            a += b;
            sum++;
        }
        cout << sum << endl;
    }
}

好吧,我承认了,这篇博客我是来水的

你可能感兴趣的:(codeforces,思维)