zoukankan      html  css  js  c++  java
  • toj 2970 Hackle Number

    2970.   Hackle Number
    Time Limit: 1.0 Seconds   Memory Limit: 65536K
    Total Runs: 183   Accepted Runs: 81



    When I was in college one of my chemistry professor invented a machine, which can make a benzin chain. A benzin chain is made by carbon atom and look like following:

    Benzin chain Benzin chain Benzin chain
    with one cycle       with two cycle       with three cycle      

    One of the disadvantages of that machine is it is very costly and if we do not supply it proper number of carbon then it cannot complete its operation and destroy the entire atom. Its need 1000$ for make a benzin chain of any length or unsuccessful operation. Acutely it was very inefficient machine. But he has no way rather than using it. So he asked me to make a program for him that can complete a proper number of carbon and its volume in standard temperature and pressure. I solve it that time. But now I am in reverse situation. He again ask me to extend that program so that if he give me a number of atom I have to find is it possible to build a carbon chain with that given number of atom. Would you please help me?

    Input

    The input contains a several test cases. Each test case will contain a single integer not more than 100 digit in one line. The EOF indicates the end of file.

    Output

    There will be one line output for one input. Each of the output line contain one of the two words "Possible." Or "Not possible.". If it is possible to make a carbon chain with the given number M then print "Possible." Otherwise print "Not possible.".

    Sample Input

    6
    10
    14
    15
    100
    

    Sample Output

    "Possible."
    "Possible."
    "Possible."
    "Not possible."
    "Not possible."
    

    Problem Setter: M H Rasel.



    Source: CUET Easy Contest
    Submit   List    Runs   Forum   Statistics

    //规律:f(n)=4*n+2,如果满足就是可能的,否则不可能
    #include <iostream>
    using namespace std;
    typedef 
    struct node
    {
        
    char num[105];
        
    int len;
    }Num;
    void Change(Num &ob,int n)
    {
        
    int i;
        
    for(i=0;i<ob.len;i++)
            ob.num[i]
    -=n;
    }
    void Rev(Num &ob)
    {
        
    int s,e;
        
    char temp;
        s
    =0;
        e
    =ob.len-1;
        
    while(s<e)
        {
            temp
    =ob.num[s];
            ob.num[s]
    =ob.num[e];
            ob.num[e]
    =temp;
            s
    ++;
            
    --e;
        }
        
    return;
    }
    Num Sub(Num 
    &a,Num &b)
    {
        Num c;
        memset(
    &c,0,sizeof(c));
        
    int tw=0,i,l=a.len;
        c.len
    =a.len;
        
    for(i=0;i<=l;i++)
        {
            c.num[i]
    =a.num[i]-b.num[i]-tw;
            
    if(c.num[i]<0)
            {
                tw
    =1;
                c.num[i]
    +=10;
            }
            
    else
                tw
    =0;
        }
        
    while(c.len>1&&!c.num[c.len-1])
            
    --c.len;
        
    return c;
    }
    void Mult_ten(Num &ob)
    {
        
    int i;
        
    if(ob.len==1&&ob.num[0]==0)
            
    return;
        
    for(i=ob.len;i>0;i--)
        {
            ob.num[i]
    =ob.num[i-1];
        }
        ob.num[
    0]=0;
        ob.len
    ++;
    }
    int Cmp(Num &a,Num &b)
    {
        Num c;
        memset(
    &c,0,sizeof(c));
        
    if(a.len>b.len)
            
    return 1;
        
    else if(a.len<b.len)
            
    return -1;
        
    else
        {
            
    int i;
            
    for(i=a.len-1;i>=0;--i)
            {
                
    if(a.num[i]>b.num[i])
                    
    return 1;
                
    else if(a.num[i]<b.num[i])
                    
    return -1;
            }
        }
        
    return 0;
    }
    Num Mod(Num 
    &a,Num &b)
    {
        Num temp;
        memset(
    &temp,0,sizeof(temp));
        
    for(int i=a.len-1;i>=0;--i)
        {
            Mult_ten(temp);
            temp.num[
    0]=a.num[i];
            
    while(Cmp(temp,b)>=0)
            {
                temp
    =Sub(temp,b);
            }
        }
        
    return temp;
    }
    int main()
    {
        Num a,b,ans,c;
        memset(
    &a,0,sizeof(a));
        memset(
    &b,0,sizeof(b));
        
    while(scanf("%s",a.num)!=EOF)
        {
            a.len
    =strlen(a.num);
            strcpy(b.num,
    "2");
            b.len
    =1;
            Change(a,
    '0');
            Change(b,
    '0');
            Rev(a);
            Rev(b);
            c
    =Sub(a,b);
            Change(c,
    -'0');
            Rev(c);

            strcpy(b.num,
    "4");
            b.len
    =1;
            Change(c,
    '0');
            Change(b,
    '0');
            Rev(c);
            Rev(b);
            ans
    =Mod(c,b);
            Change(ans,
    -'0');
            Rev(ans);
            
    if(ans.len==1&&ans.num[0]=='0')
                printf(
    "\"Possible.\"\n");
            
    else
                printf(
    "\"Not possible.\"\n");
            memset(
    &a,0,sizeof(a));
            memset(
    &b,0,sizeof(b));
        }
        
    return 0;
    }
  • 相关阅读:
    第四周:卷积神经网络 part3
    第四周作业:卷积神经网络学习part3
    视频学习--《 图像语义分割前沿进展》
    视频学习--《语义分割中的自注意力机制和低秩重建》
    第二次作业:卷积神经网络 part 1
    使用VGG模型迁移学习进行猫狗大战
    使用 VGG16 对 CIFAR10 分类
    CIFAR10 数据集分类
    MNIST数据集分类
    第一次作业:深度学习基础
  • 原文地址:https://www.cnblogs.com/forever4444/p/1460369.html
Copyright © 2011-2022 走看看