toj 2970 Hackle Number

本文介绍了一种名为HackleNumber的算法问题,该问题源于一种能够制造苯环链的机器。文章详细阐述了如何判断给定数量的碳原子是否能构成有效的苯环链,并提供了具体的实现代码。
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 chainBenzin chainBenzin 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 ;
}

转载于:https://www.cnblogs.com/forever4444/archive/2009/05/19/1460369.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值