zoukankan      html  css  js  c++  java
  • Codeforces Gym 100523C C

    C - Will It Stop?
    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87794#problem/C

    Description

    Byteasar was wandering around the library of the University of Warsaw and at one of its facades he noticed a piece of a program with an inscription “Will it stop?”. The question seemed interesting, so Byteasar tried to tackle it after returning home. Unfortunately, when he was writing down the piece of code he made a mistake and noted:
     
    while n > 1 do if n mod 2 = 0 then n := n=2 else n := 3 · n + 3
    Byteasar is now trying to figure out, for which initial values of the variable n the program he wrote down stops. We assume that the variable n has an unbounded size, i.e., it may attain arbitrarily large values.
     
     

    Input

    The first and only line of input contains one integer n (2 ¬ n ¬ 1014).

    Output

    In the first and only line of output you should write a single word TAK (i.e., yes in Polish), if the program stops for the given value of n, or NIE (no in Polish) otherwise.

    Sample Input

    4

    Sample Output

    TAK

    HINT

    题意

    给你一个数,然后问你这个数组是否会无限循环

    题解

    暴力10000000次,然后看看就吼了

    代码:

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 5000
    #define mod 10007
    #define eps 1e-9
    int Num;
    //const int inf=0x7fffffff;   //нчоч╢С
    const int inf=0x3f3f3f3f;
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    //**************************************************************************************
    
    int main()
    {
        unsigned long long n;
        cin>>n;
        int tot=0;
        while(n>1)
        {
            if(n%2==0)
                n=n/2;
            else
                n=3*n+3;
            tot++;
            if(tot>10000000)
            {
                cout<<"NIE"<<endl;
                return 0;
            }
        }
        cout<<"TAK"<<endl;
        
    }
  • 相关阅读:
    sqlite数据库的基本操作
    java-正则表达式判断移动联通电信手机号
    基金新手常识
    Android 心跳包心跳连接 如何实现android和服务器长连接呢?推送消息的原理
    java 设计模式之模板方法
    Android 自定义view实现水波纹效果
    Android中pendingIntent的深入理解
    CentOS 7.X下 -- 配置nginx正向代理支持https
    自动化运维工具saltstack04 -- 之jinja模板
    自动化运维工具saltstack03 -- 之SaltStack的数据系统
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4731115.html
Copyright © 2011-2022 走看看