题解

211 条题解

  • 0
    @ 2016-03-18 13:50:06

    只能说我大**java**威力无穷_(:з」∠)_

    import java.util.Scanner;

    public class Main {
    public static String reverse(String str) {
    StringBuffer buffer = new StringBuffer();
    for (int x = str.length() - 1; x >= 0; x--) {
    buffer.append(str.charAt(x));
    }
    return buffer.toString();
    }

    public static boolean isReversable(String str) {
    return str.equals(reverse(str));
    }

    public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int radix;
    Long data;
    radix = scanner.nextInt();
    data = scanner.nextLong(radix);
    for (int x = 0; x <= 30; x++) {
    if (isReversable(Long.toString(data, radix))) {
    System.out.println("STEP=" + x);
    return;
    } else {
    data = Long.parseLong(reverse(Long.toString(data, radix)), radix) + data;
    }
    }
    System.out.println("Impossible!");
    }
    }

  • 0
    @ 2016-03-12 23:18:59
    var n,len,x,i:longint;c:char;ms:string;
      m:array[1..1000] of integer;
    
    function judge():boolean;
    var i:integer;res:boolean;
    begin
      res:=true;
      for i:=1 to len div 2+1 do
        if m[i]<>m[len-i+1] then begin res:=false;break end;
      judge:=res;
    end;
    
    procedure add();
    var res:array[1..1000] of integer;
    begin
      fillchar(res,sizeof(res),0);
      for i:=1 to len do begin
        res[i]:=m[i]+m[len-i+1]+res[i];
        if res[i]>=n then begin
          res[i+1]:=res[i] div n;
          res[i]:=res[i] mod n;
        end;
      end;
      if res[len+1]>0 then inc(len);
      m:=res;
    end;
    
    begin
      readln(n);
      read(ms);
      len:=length(ms);
      for i:=1 to length(ms) do
        case ms[i] of
          '0'..'9':val(ms[i],m[length(ms)-i+1],x);
          'A':m[length(ms)-i+1]:=10;
          'B':m[length(ms)-i+1]:=11;
          'C':m[length(ms)-i+1]:=12;
          'D':m[length(ms)-i+1]:=13;
          'E':m[length(ms)-i+1]:=14;
          'F':m[length(ms)-i+1]:=15;
        end;
      x:=0;
      while (not judge()) and (x<=30) do begin
        inc(x);
        add();
      end;
      if x>30 then write('Impossible!')
      else write('STEP=',x);
    end. 
    
  • 0
    @ 2016-03-04 19:00:00

    感觉我这个好麻烦。。。不过我相信肯定会有比我更麻烦的哈哈哈

    #include<iostream>
    #include<string>
    #include<cstring>

    using namespace std;

    int len;

    bool huiwen(char *ch) //判断是否回文数
    {
    bool bo=true;
    for(int x=0;x<len;x++)
    {
    if(ch[x]!=ch[len-x-1]) bo=false;
    }
    return bo;
    }

    int main()
    {
    int a;
    cin>>a;
    string s;
    cin>>s;
    len=s.length();
    char ss[15],sss[15];
    for(int x=0;x<len;x++)
    {
    if(isalpha(s[x])) ss[len-x-1]=s[x]-7;//应付16进制
    else ss[len-x-1]=s[x];
    }
    int count=0;//计数器
    if(a)
    while(!huiwen(ss))
    {
    while(count>=30)
    {
    cout<<"Impossible!"<<endl;
    return 0;
    }
    int y=0;count++;
    int x=0;
    for(;x<len;x++)
    {
    int num=(ss[x]-'0')+(ss[len-x-1]-'0')+y;
    char ch=num%a+'0';
    sss[x]=ch;
    y=num/a;
    }
    if(y!=0) //进位
    {
    char cha=y+'0';
    sss[x]=cha;
    len++;
    }
    strcpy(ss,sss);
    memset(sss,0,sizeof(sss));
    }
    cout<<"STEP="<<count<<endl;
    return 0;
    }

  • 0
    @ 2016-02-21 01:07:57

    Java大法好

    import java.util.Scanner;
    
    public class Main {
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            int radix = in.nextInt();
            String s = in.next();
            StringBuffer s2 = new StringBuffer(s).reverse();
            int cnt = 0;
            long x = Long.valueOf(s, radix);
            while(!s2.toString().equals(s) && cnt <= 30){
                cnt++;
                x +=  Long.valueOf(s2.toString(), radix);
                s = Long.toString(x,radix);
                s2 = new StringBuffer(s).reverse();
            }
            if(cnt > 30){
                System.out.println("Impossible!");
            } else {
                System.out.println("STEP=" + cnt);
            }
            in.close();
        }
    }
    
  • 0
    @ 2016-02-19 20:25:41

    Pascal AC
    var n,i,j,k,s,la,lb,lc:longint;
    x,y,z,m:string;
    a,b,c:array[1..1000]of longint;
    begin
    readln(n);
    readln(m);
    for i:=1 to 30 do
    begin
    x:=m;
    y:='';
    for j:=1 to length(x) do
    y:=x[j]+y;
    fillchar(a,sizeof(a),0);
    b:=a;
    c:=a;
    la:=length(x);
    lb:=length(y);
    for j:=1 to la do
    if x[j] in ['0'..'9'] then
    a[la-j+1]:=ord(x[j])-ord('0')
    else a[la-j+1]:=ord(x[j])-55;
    for j:=1 to lb do
    if y[j] in ['0'..'9'] then
    b[lb-j+1]:=ord(y[j])-ord('0')
    else b[lb-j+1]:=ord(y[j])-55;
    s:=1;
    k:=0;
    while (s<=la)or(s<=lb) do
    begin
    c[s]:=a[s]+b[s]+k;
    k:=c[s] div n;
    c[s]:=c[s] mod n;
    inc(s);
    end;
    if k>0 then begin
    lc:=s;
    c[s]:=k;
    end
    else lc:=s-1;
    x:='';
    y:='';
    z:='';
    for j:=lc downto 1 do
    begin
    if c[j] in [0..9] then
    str(c[j],z)
    else z:=chr(c[j]+55);
    x:=x+z;
    y:=z+y;
    end;
    if x=y then
    begin
    write('STEP=',i);
    exit;
    end;
    m:=x;
    end;
    write('Impossible!');
    end.

  • 0
    @ 2016-02-18 21:36:58
    /* ***********************************************
    Author        :guanjun
    Created Time  :2016/2/18 21:18:36
    File Name     :vijosp1304.cpp
    ************************************************ */
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <stdio.h>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <iomanip>
    #include <list>
    #include <deque>
    #include <stack>
    #define ull unsigned long long
    #define ll long long
    #define mod 90001
    #define INF 0x3f3f3f3f
    #define maxn 10000+10
    #define cle(a) memset(a,0,sizeof(a))
    const ull inf = 1LL << 61;
    const double eps=1e-5;
    using namespace std;
    
    bool cmp(int a,int b){
        return a>b;
    }
    int a[100];
    int b[100];
    int m;
    bool judge(int *a){
        int mark=1;
        for(int i=0;i<m;i++){
            if(a[i]!=a[m-1-i]){
                mark=0;break;
            }
        }
        return mark;
    }
    int main()
    {
        #ifndef ONLINE_JUDGE
        //freopen("in.txt","r",stdin);
        #endif
        //freopen("out.txt","w",stdout);
        char s[100];
        int n;
        while(cin>>n>>s){
            int flag=0;
            m=strlen(s);
            cle(a),cle(b);
            for(int i=0;i<m;i++){
                if(s[i]<='9'&&s[i]>='0')a[i]=int(s[i]-'0');
                if(s[i]<='Z'&&s[i]>='A')a[i]=int(s[i]-'A')+10;
            }
            if(judge(a)){
                printf("STEP=%d\n",0);
                continue;
            }
            for(int k=1;k<=30;k++){
                for(int i=0;i<m;i++){
                    b[i]=a[m-i-1];
                }
                for(int i=0;i<m;i++){
                    a[i]=a[i]+b[i];
                    if(a[i]>=n){
                        a[i]-=n;
                        a[i+1]++;
                    }
                }
                if(a[m]>0)m++;
                if(judge(a)){
                    printf("STEP=%d\n",k);flag=1;break;
                }
            }
            if(!flag)puts("Impossible!");
        }
        return 0;
    }
    
    
  • 0
    @ 2015-10-03 08:42:21

    谁能知道p1304回文数的十组测试数据,有多少要多少,急!!!!!???!!!!!!!!

  • 0
    @ 2015-08-10 10:06:44

    #include <string>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    int k,step;
    struct INT
    {
    int n;
    short int a[100005];
    INT () {n = 0;memset(a,0,sizeof(a));}
    void operator = (const string &s)
    {
    n = s.length();
    for (int i = 0;i < n;i++)
    if ('0' <= s[i] && s[i] <= '9')
    a[n-1-i] = s[i] - '0';
    else if ('a' <= s[i] && s[i] <= 'z')
    a[n-1-i] = s[i] - 'a' + 10;
    else
    a[n-1-i] = s[i] - 'A' + 10;
    return;
    }
    INT operator + (const INT &x)
    {
    INT t;t.n = max(n,x.n);
    for (int i = 0;i < t.n;i++)
    {
    t.a[i] += a[i] + x.a[i];
    t.a[i+1] = t.a[i] / k;
    t.a[i] %= k;
    }
    if (t.a[t.n]) t.n++;
    return t;
    }
    bool operator == (const INT &x)
    {
    if (n != x.n) return 0;
    for (int i = n-1;i >= 0;i--)
    if (a[i] != x.a[i]) return 0;
    return 1;
    }
    };
    istream& operator >> (istream &in,INT &x)
    {
    string s;
    in >> s;
    x.n = (int)s.size();
    for (int i = 0;i < x.n;i++)
    if ('0' <= s[i] && s[i] <= '9')
    x.a[x.n-1-i] = s[i] - '0';
    else if ('a' <= s[i] && s[i] <= 'z')
    x.a[x.n-1-i] = s[i] - 'a' + 10;
    else
    x.a[x.n-1-i] = s[i] - 'A' + 10;
    return in;
    }
    ostream& operator << (ostream &out,const INT &x) {
    for (int i = x.n-1;i >= 0;--i) out << x.a[i];
    return out;
    }
    int main()
    {
    INT a,b;
    cin >> k >> a;
    step = 0;
    while (true)
    {
    for (int i = 0;i < a.n;i++)
    b.a[i] = a.a[a.n-1-i];
    b.n = a.n;
    if (b == a) break;
    step++;
    if (step > 30) break;
    #ifdef LOCAL
    cout << a << "+" << b << "=" << a+b << "\n";
    #endif
    a = a+b;
    }
    if (step > 30)
    cout << "Impossible!\n";
    else
    cout << "STEP=" << step << "\n";
    return 0;
    }
    秒过~~哈哈哈哈哈哈哈哈哈哈
    蜗牛看吧

  • 0
    @ 2015-07-13 20:23:44

    pascal秒过

    测试数据 #0: Accepted, time = 0 ms, mem = 428 KiB, score = 25

    测试数据 #1: Accepted, time = 0 ms, mem = 432 KiB, score = 25

    测试数据 #2: Accepted, time = 0 ms, mem = 432 KiB, score = 25

    测试数据 #3: Accepted, time = 0 ms, mem = 432 KiB, score = 25

    Accepted, time = 0 ms, mem = 432 KiB, score = 100

    代码

    type arr=array[0..100]of byte;
    var t,t2:arr;
    m:string;
    i,n:longint;
    function zhsz(st:string):arr;
    var i:longint;
    begin
    fillchar(zhsz,sizeof(zhsz),0);
    zhsz[0]:=length(st);
    for i:=zhsz[0] downto 1 do
    if st[i]in['A'..'Z'] then zhsz[zhsz[0]-i+1]:=ord(st[i])-55
    else zhsz[zhsz[0]-i+1]:=ord(st[i])-48;
    end;
    function fz(x:arr):arr;
    var i:longint;
    begin
    fillchar(fz,sizeof(fz),0);
    fz[0]:=x[0];
    for i:=1 to x[0] do fz[i]:=x[x[0]-i+1];
    end;
    function hw(x:arr):boolean;
    var i:longint;
    begin
    hw:=true;
    for i:=1 to x[0] div 2 do
    if x[i]<>x[x[0]-i+1] then exit(false);
    end;
    function plus(a,b:arr;m:longint):arr;
    var i:longint;
    begin
    fillchar(plus,sizeof(plus),0);
    if a[0]>b[0] then plus[0]:=a[0] else plus[0]:=b[0];
    for i:=1 to plus[0] do
    begin
    plus[i]:=plus[i]+a[i]+b[i];
    plus[i+1]:=plus[i] div m;
    plus[i]:=plus[i] mod m;
    end;
    if plus[i+1]<>0 then inc(plus[0]);
    end;
    begin
    readln(n);
    readln(m);
    t:=zhsz(m);
    t2:=fz(t);
    for i:=1 to 30 do
    begin
    if hw(plus(t,t2,n)) then
    begin
    writeln('STEP=',i);
    exit;
    end;
    t:=plus(t,t2,n);
    t2:=fz(t);
    end;
    writeln('Impossible!');
    end.

  • 0
    @ 2015-03-23 23:34:46

    有没有人跟我一样错在"Impossible!"!!!!
    是"Impossible!"而不是"Impossible!"

  • 0
    @ 2015-01-27 20:38:05

    c++ code

    #include<iostream>
    #include<string>
    #include<algorithm>
    #include<cctype>
    using namespace std;
    int n;
    void add(string &sa,string sb)
    {
    string sc;
    int a[10000],b[10000],c[10000];
    int i,j,x,lena,lenb,lenc;
    lena=sa.size();
    for (i=0,j=lena;i<lena;++i,--j)
    if (isdigit(sa[i])) a[j]=int(sa[i]-48);
    else a[j]=int(sa[i]-65+10);
    lenb=sb.size();
    for (i=0,j=lenb;i<lenb;++i,--j)
    if (isdigit(sb[i])) b[j]=int(sb[i]-48);
    else b[j]=int(sb[i])-65+10;
    i=1; x=0;
    while (i<=lena || i<=lenb)
    {
    c[i]=a[i]+b[i]+x;
    x=c[i]/n;
    c[i]%=n;
    ++i;
    }
    if (x>0)
    {
    lenc=i;
    c[i]=x;
    }
    else lenc=i-1;
    for (i=lenc;i>=1;i--)
    if (c[i]<10)sc+=char(c[i]+48);
    else sc+=char(c[i]-10+65);
    sa=sc;
    }
    int main()
    {
    string a,t;
    cin>>n>>a;
    for (int i=0;i<=30;++i)
    {
    t=a;
    reverse(t.begin(),t.end());
    if (a==t)
    {
    cout<<"STEP="<<i;
    return 0;
    }
    else add(a,t);
    }
    cout<<"Impossible!";
    return 0;
    }

  • 0
    @ 2014-12-10 16:49:24

    #include<iostream>
    using namespace std;
    int a[101],i;
    bool h(int a[])
    {
    for(i=1;i<=a[0];i++)
    if(a[i]!=a[a[0]-i+1])
    return 0;
    return 1;
    }
    main()
    {
    int b[101],c=0,n;
    string s;
    cin>>n>>s;
    a[0]=s.size();
    for(i=1;i<=a[0];i++)
    a[i]=(s[a[0]-i]>'/'&&s[a[0]-i]<':'?s[a[0]-i]-'0':s[a[0]-i]-'A'+10);
    if(h(a))
    {
    cout<<"STEP=0";
    return 0;
    }
    while(c<31)
    {
    c++;
    for(i=1;i<=a[0];i++)
    b[i]=a[a[0]-i+1];
    for(i=1;i<=a[0];i++)
    a[i]+=b[i];
    for(i=1;i<=a[0];i++)
    {
    a[i+1]+=a[i]/n;
    a[i]%=n;
    }
    if(a[a[0]+1])
    a[0]++;
    if(h(a))
    {
    cout<<"STEP="<<c;
    return 0;
    }
    }
    cout<<"Impossible!";
    }

  • 0
    @ 2014-11-01 15:30:13

    题目有误==**N<=16**
    中途int会**爆掉**==要用 long longTAT

  • 0
    @ 2014-10-06 22:25:51

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    using namespace std;
    #define N 400
    #define FILEE
    int jinzhi;
    struct Huiwen_Game
    {
    int len;
    int a[N];
    Huiwen_Game()
    {
    len=1;
    memset(a,0,sizeof(a));
    }
    int max(const Huiwen_Game&b)const
    {
    if( len<b.len )
    return b.len;
    return len;
    }
    Huiwen_Game operator=(const Huiwen_Game&b)
    {
    memset(a,0,sizeof(a));
    len=b.len;
    for(int i=0;i<len;i++)
    a[i]=b.a[i];
    return *this;
    }
    Huiwen_Game operator+(const Huiwen_Game&b)
    {
    Huiwen_Game c;
    c.len=max(b)+1;
    for(int i=0;i<c.len;i++)
    {
    c.a[i]=a[i]+b.a[i]+c.a[i];
    c.a[i+1]=c.a[i+1]+c.a[i]/jinzhi;
    c.a[i]=c.a[i]%jinzhi;
    }
    if( !c.a[c.len-1] )
    c.len--;
    return c;
    }
    Huiwen_Game operator+=(const Huiwen_Game&b)
    {
    *this=*this+b;
    return *this;
    }
    void Input()
    {
    char ch[100];
    gets(ch);
    len=strlen(ch);
    for(int i=0;i<len;i++)
    {
    a[i]=ch[len-i-1]-'0';
    if( ch[len-i-1]=='a' || ch[len-i-1]=='A' )
    a[i]=10;
    if( ch[len-i-1]=='b' || ch[len-i-1]=='B' )
    a[i]=11;
    if( ch[len-i-1]=='c' || ch[len-i-1]=='C' )
    a[i]=12;
    if( ch[len-i-1]=='d' || ch[len-i-1]=='D' )
    a[i]=13;
    if( ch[len-i-1]=='e' || ch[len-i-1]=='E' )
    a[i]=14;
    if( ch[len-i-1]=='f' || ch[len-i-1]=='F' )
    a[i]=15;
    }
    }
    void Output()
    {
    for(int i=len-1;i>=0;i--)
    cout<<a[i];
    }
    Huiwen_Game fan()
    {
    Huiwen_Game c;
    c.len=len;
    int i=0,j=len-1;
    while( i<=j )
    {
    c.a[i]=a[i],c.a[j]=a[j];
    if( i!=j )
    swap(c.a[i],c.a[j]);
    i++,j--;
    }
    return c;
    }
    bool Is_Huiwen() const
    {
    int i=0,j=len-1;
    while( i<j )
    {
    if( a[i]!=a[j] )
    return false;
    i++,j--;
    }
    return true;
    }
    };
    int main()
    {
    #ifdef FILE
    freopen("palnum.in","r",stdin);
    freopen("palnum.out","w",stdout);
    #endif
    int i=1;
    bool huiwen=true;
    cin>>jinzhi;
    getchar();
    Huiwen_Game a,b;
    a.Input();
    while( i<=30 )
    {
    b=a.fan();
    a=a+b;
    if( a.Is_Huiwen() )
    {
    cout<<"STEP="<<i<<endl;
    huiwen=false;
    break;
    }
    i++;
    }
    if( huiwen==true )
    cout<<"Impossible!"<<endl;
    return 0;

    }

  • 0
    @ 2014-10-06 22:24:49

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    using namespace std;
    #define N 400
    #define FILEE
    int jinzhi;
    struct Huiwen_Game
    {
    int len;
    int a[N];
    Huiwen_Game()
    {
    len=1;
    memset(a,0,sizeof(a));
    }
    int max(const Huiwen_Game&b)const
    {
    if( len<b.len )
    return b.len;
    return len;
    }
    Huiwen_Game operator=(const Huiwen_Game&b)
    {
    memset(a,0,sizeof(a));
    len=b.len;
    for(int i=0;i<len;i++)
    a[i]=b.a[i];
    return *this;
    }
    Huiwen_Game operator+(const Huiwen_Game&b)
    {
    Huiwen_Game c;
    c.len=max(b)+1;
    for(int i=0;i<c.len;i++)
    {
    c.a[i]=a[i]+b.a[i]+c.a[i];
    c.a[i+1]=c.a[i+1]+c.a[i]/jinzhi;
    c.a[i]=c.a[i]%jinzhi;
    }
    if( !c.a[c.len-1] )
    c.len--;
    return c;
    }
    Huiwen_Game operator+=(const Huiwen_Game&b)
    {
    *this=*this+b;
    return *this;
    }
    void Input()
    {
    char ch[100];
    gets(ch);
    len=strlen(ch);
    for(int i=0;i<len;i++)
    {
    a[i]=ch[len-i-1]-'0';
    if( ch[len-i-1]=='a' || ch[len-i-1]=='A' )
    a[i]=10;
    if( ch[len-i-1]=='b' || ch[len-i-1]=='B' )
    a[i]=11;
    if( ch[len-i-1]=='c' || ch[len-i-1]=='C' )
    a[i]=12;
    if( ch[len-i-1]=='d' || ch[len-i-1]=='D' )
    a[i]=13;
    if( ch[len-i-1]=='e' || ch[len-i-1]=='E' )
    a[i]=14;
    if( ch[len-i-1]=='f' || ch[len-i-1]=='F' )
    a[i]=15;
    }
    }
    void Output()
    {
    for(int i=len-1;i>=0;i--)
    cout<<a[i];
    }
    Huiwen_Game fan()
    {
    Huiwen_Game c;
    c.len=len;
    int i=0,j=len-1;
    while( i<=j )
    {
    c.a[i]=a[i],c.a[j]=a[j];
    if( i!=j )
    swap(c.a[i],c.a[j]);
    i++,j--;
    }
    return c;
    }
    bool Is_Huiwen() const
    {
    int i=0,j=len-1;
    while( i<j )
    {
    if( a[i]!=a[j] )
    return false;
    i++,j--;
    }
    return true;
    }
    };
    int main()
    {
    #ifdef FILE
    freopen("palnum.in","r",stdin);
    freopen("palnum.out","w",stdout);
    #endif
    int i=1;
    bool huiwen=true;
    cin>>jinzhi;
    getchar();
    Huiwen_Game a,b;
    a.Input();
    while( i<=30 )
    {
    b=a.fan();
    a=a+b;
    if( a.Is_Huiwen() )
    {
    cout<<"STEP="<<i<<endl;
    huiwen=false;
    break;
    }
    i++;
    }
    if( huiwen==true )
    cout<<"Impossible!"<<endl;
    return 0;

    }

  • 0
    @ 2014-10-05 17:18:06

    各位大虾帮帮忙呀!!哪里错了呀???
    var mm:string;
    n,m,lc,i,j,t,mt:longint;
    f:boolean;
    begin
    readln(n);
    readln(mm);
    lc:=1;m:=0;
    for i:=length(mm) downto 1 do begin
    case mm[i] of
    '1':t:=1;
    '2':t:=2;
    '3':t:=3;
    '4':t:=4;
    '5':t:=5;
    '6':t:=6;
    '7':t:=7;
    '8':t:=8;
    '9':t:=9;
    'A':t:=10;
    'B':t:=11;
    'C':t:=12;
    'D':t:=13;
    'E':t:=14;
    'F':t:=15;
    end;
    m:=m+t*lc;
    lc:=lc*n;
    end;
    for i:=1 to 30 do begin
    t:=m; mt:=0;
    while t>0 do begin
    mt:=mt*10+t mod 10;
    t:=t div 10;
    end;
    m:=m+mt;
    str(m,mm); f:=true;
    for j:=1 to length(mm) div 2 do begin
    if mm[j]<>mm[length(mm)-j+1] then begin f:=false; break; end;
    end;
    if f then break;
    end;
    if f then writeln('STEP=',i) else writeln('Impossible!');
    end.

  • 0
    @ 2014-08-15 11:04:15

    const
    step:integer=0;
    chars:array[0..15] of char=('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
    var
    digit:array[char] of integer;
    i,n,g:integer;
    m,s:string;
    ok:boolean;
    begin
    for i:=0 to 9 do digit[char(ord('0')+i)]:=i;
    for i:=0 to 5 do digit[char(ord('A')+i)]:=i+10;
    readln(n);
    readln(s);
    for i:=1 to length(s) do s[i]:=upcase(s[i]);
    repeat
    ok:=true;
    for i:=1 to length(s) div 2 do
    if s[i]<>s[length(s)+1-i] then ok:=false;
    if ok then break;
    inc(step);
    m:=s; g:=0;
    for i:=length(m) downto 1 do
    begin
    s[i]:=chars[(digit[m[i]]+digit[m[length(m)+1-i]]+g) mod n];
    g:=(digit[m[i]]+digit[m[length(m)+1-i]]+g) div n;
    end;
    if g>0 then s:=chars[g]+s;
    until step>=30;
    if ok then writeln('STEP=',step)
    else writeln('Impossible!');
    end.

  • 0
    @ 2013-11-01 08:30:06

    var
    i,j,l,n,m,ans:longint;
    s:string;
    a,b:array[1..1000] of longint;
    function check:boolean;
    begin
    for i:=1 to l do
    if b[i]<>a[l-i+1] then begin check:=false; exit; end ;
    check:=true;
    end;
    begin
    readln(n);
    readln(s);
    l:=length(s);
    for i:=1 to l do
    case s[i] of
    'A':b[i]:=10;
    'B':b[i]:=11;
    'C':b[i]:=12;
    'D':b[i]:=13;
    'E':b[i]:=14;
    'F':b[i]:=15;
    else b[i]:=ord(s[i])-48;
    end;
    while not check do
    begin
    fillchar(a,sizeof(a),0);
    for i:=1 to l do
    a[i]:=b[i]+b[l-i+1];
    for i:=1 to l do
    begin
    a[i+1]:=a[i+1]+a[i] div n;
    a[i]:=a[i] mod n;
    end;
    if a[i+1]<>0 then inc(l);
    b:=a;
    inc(ans);
    if ans>30 then
    begin
    writeln('Impossible!');
    halt;
    end;
    end;
    writeln('STEP=',ans);
    end.
    啊啊啊啊啊啊,第一次提交没打叹号,WA,第二次提交i没大写,又WA。。。
    庆祝第一百次提交。。。。

  • 0
    @ 2013-09-25 21:37:55

    var
    a:array[1..100,1..1000]of longint;
    s:string; yan:boolean; step,n,j,wei,hang:longint;
    begin
    readln(n); readln(s); wei:=length(s); hang:=1;
    for j:=1 to length(s) do
    if ord(s[j])>=65 then a[1,length(s)-j+1]:=ord(s[j])-55
    else val(s[j],a[1,length(s)-j+1]);
    repeat
    yan:=true; step:=step+1;
    for j:=wei downto 1 do
    a[hang+1,j]:=a[hang,wei-j+1];
    for j:=1 to wei do
    begin
    a[hang+2,j]:=a[hang+2,j]+a[hang,j]+a[hang+1,j];
    if a[hang+2,j]>=n then
    begin
    a[hang+2,j+1]:=a[hang+2,j]div n;
    a[hang+2,j]:=a[hang+2,j] mod n;
    if (j=wei)and(a[hang+2,j+1]<>0) then wei:=wei+1;
    end;
    end;
    for j:=(wei div 2) downto 1 do
    if a[hang+2,j]<>a[hang+2,wei+1-j] then yan:=false;
    if yan=false then hang:=hang+2;
    until (yan=true)or(step=30);
    if step=30 then begin write('Impossible!'); exit; end;
    if yan=true then write(step);
    end.
    30行秒杀~~~~

  • 0
    @ 2012-10-23 15:03:22

    被完虐。。半个小时终于发现 impossible !!!!!!!!!!!

信息

ID
1304
难度
5
分类
模拟 点击显示
标签
递交数
8080
已通过
2532
通过率
31%
被复制
31
上传者