#45148: 一直TLE?


austin131130@gmail.com (索尼克)

學校 : 國立中央大學
編號 : 271683
來源 : [36.229.250.201]
最後登入時間 :
2025-01-11 21:46:52

過不了,真的過不了
#include <iostream>
using namespace std;
int main()
{
    int n;

    while (cin >> n)
    {
        int count = 0;
        while (n != 4)
        {
            if (n % 2 == 0)
            {
                n /= 2;
            }
            else
            {
                n = (n * 3 + 1)/2;
                count++;
            }
            count++;
        }
        cout << count << endl;
    }
    return 0;
}
#45242: Re: 一直TLE?


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [39.12.66.21]
最後登入時間 :
2025-04-20 17:19:22

過不了,真的過不了
#include
using namespace std;
int main()
{
    int n;

    while (cin >> n)
    {
        int count = 0;
        while (n != 4)
        {
            if (n % 2 == 0)
            {
                n /= 2;
            }
            else
            {
                n = (n * 3 + 1)/2;
                count++;
            }
            count++;
        }
        cout << count << endl;
    }
    return 0;
}


建表,io加速就能過了

#45243: Re: 一直TLE?


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [39.12.66.21]
最後登入時間 :
2025-04-20 17:19:22

過不了,真的過不了
#include
using namespace std;
int main()
{
    int n;

    while (cin >> n)
    {
        int count = 0;
        while (n != 4)
        {
            if (n % 2 == 0)
            {
                n /= 2;
            }
            else
            {
                n = (n * 3 + 1)/2;
                count++;
            }
            count++;
        }
        cout << count << endl;
    }
    return 0;
}


建表,io加速就能過了


輸入輸出不要用cin cout,可以用printf scanf,如果用getchar_unlocked putchar_unlocked更快