• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            poj1023

            The Fun Number System


            Time Limit: 1000MS
            Memory Limit: 10000K
            Total Submissions: 8549
            Accepted: 2797

            Description

            In a k bit 2's complement number, where the bits are indexed from 0 to k-1, the weight of the most significant bit (i.e., in position k-1), is -2^(k-1), and the weight of a bit in any position i (0 ≤ i < k-1) is 2^i. For example, a 3 bit number 101 is -2^2 + 0 + 2^0 = -3. A negatively weighted bit is called a negabit (such as the most significant bit in a 2's complement number), and a positively weighted bit is called a posibit.
            A Fun number system is a positional binary number system, where each bit can be either a negabit, or a posibit. For example consider a 3-bit fun number system Fun3, where bits in positions 0, and 2 are posibits, and the bit in position 1 is a negabit. (110)Fun3 is evaluated as 2^2-2^1 + 0 = 3. Now you are going to have fun with the Fun number systems! You are given the description of a k-bit Fun number system Funk, and an integer N (possibly negative. You should determine the k bits of a representation of N in Funk, or report that it is not possible to represent the given N in the given Funk. For example, a representation of -1 in the Fun3 number system (defined above), is 011 (evaluated as 0 - 2^1 + 2^0), and
            representing 6 in Fun3 is impossible.

            Input

            The first line of the input file contains a single integer t (1 ≤ t ≤ 10), the number of test cases, followed by the input data for each test case. Each test case is given in three consecutive lines. In the first line there is a positive integer k (1 ≤ k ≤ 64). In the second line of a test data there is a string of length k, composed only of letters n, and p, describing the Fun number system for that test data, where each n (p) indicates that the bit in that position is a negabit (posibit).
            The third line of each test data contains an integer N (-2^63 ≤ N < 2^63), the number to be represented in the Funk number
            system by your program.

            Output

            For each test data, you should print one line containing either a k-bit string representing the given number N in the Funk number system, or the word Impossible, when it is impossible to represent the given number.

            Sample Input

            2 3 pnp 6 4 ppnn 10

            Sample Output

            Impossible 1110

            Source

            Tehran 2002, First Iran Nationwide Internet Programming Contest


            是個好題,不過沒想出來怎么做,跟數的補碼有關

            code
            #include <cstdio>
            #include 
            <cstdlib>
            #include 
            <cstring>
            #include 
            <cmath>
            #include 
            <ctime>
            #include 
            <cassert>
            #include 
            <iostream>
            #include 
            <sstream>
            #include 
            <fstream>
            #include 
            <map>
            #include 
            <set>
            #include 
            <vector>
            #include 
            <queue>
            #include 
            <algorithm>
            #include 
            <iomanip>
            using namespace std;
            __int64 maxnum,minnum;
            __int64 n;
            char s[100];
            int main()
            {
                
            char str[100];
                
            int t,len;
                
            long long flag;
                scanf(
            "%d",&t);
                
            while(t--)
                {
                    scanf(
            "%d",&len);
                    scanf(
            "%s",str);
                    scanf(
            "%I64d",&n);
                    maxnum
            =0;
                    minnum
            =0;
                    
            for(int i=0; i<len; i++)
                    {
                        
            if(str[i]=='p') maxnum=maxnum*2+1,minnum=minnum*2;
                        
            else maxnum=maxnum*2,minnum=minnum*2-1;
                    }
                    memset(s,
            0,sizeof(s));
                    
            if((n<minnum&&minnum<=0)||(n>maxnum&&maxnum>=0)) printf("Impossible\n");
                    
            else
                    {
                        
            for(int i=len-1; i>=0; i--)
                        {
                            flag
            =0;
                            
            if(n&1)
                            {
                                s[i]
            ='1';
                                
            if(str[i]=='n')flag=1;
                            }
                            
            else s[i]='0';
                            n
            =n>>1;
                           
            // printf("%d\n",n);
                            if(flag) n++;
                           
            // printf("%d\n",n);
                        }
                        puts(s);
                    }
                }
                
            return 0;
            }

            posted on 2012-07-30 21:44 jh818012 閱讀(115) 評論(0)  編輯 收藏 引用

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導航

            統計

            常用鏈接

            留言簿

            文章檔案(85)

            搜索

            最新評論

            • 1.?re: poj1426
            • 我嚓,,輝哥,,居然搜到你的題解了
            • --season
            • 2.?re: poj3083
            • @王私江
              (8+i)&3 相當于是 取余3的意思 因為 3 的 二進制是 000011 和(8+i)
            • --游客
            • 3.?re: poj3414[未登錄]
            • @王私江
              0ms
            • --jh818012
            • 4.?re: poj3414
            • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
            • --王私江
            • 5.?re: poj1426
            • 評論內容較長,點擊標題查看
            • --王私江
            日韩精品无码久久一区二区三| 国产成人精品免费久久久久| 中文字幕精品久久| 久久亚洲日韩精品一区二区三区| 精品综合久久久久久97超人| 亚洲国产成人久久综合碰| 久久大香香蕉国产| 久久综合色老色| 国产精品va久久久久久久| 18岁日韩内射颜射午夜久久成人| 久久精品国产亚洲网站| 色综合久久久久久久久五月| 久久久久噜噜噜亚洲熟女综合| 人妻丰满AV无码久久不卡| 久久婷婷午色综合夜啪| 国产综合成人久久大片91| 国产成人精品白浆久久69| 久久香综合精品久久伊人| 久久久91人妻无码精品蜜桃HD| 国产精品久久自在自线观看| 亚洲精品美女久久久久99| 中文字幕久久亚洲一区| 久久久久久A亚洲欧洲AV冫| 99麻豆久久久国产精品免费| 亚洲愉拍99热成人精品热久久 | 久久精品国产精品亚洲下载| 男女久久久国产一区二区三区| 97精品依人久久久大香线蕉97| 一本色道久久综合狠狠躁篇| 色婷婷久久久SWAG精品| 久久亚洲国产成人影院网站| 国产精品99久久久久久www| 国产无套内射久久久国产| 久久国产精品99久久久久久老狼| 97精品国产91久久久久久| 久久国产欧美日韩精品| 成人免费网站久久久| 人人狠狠综合久久亚洲婷婷| 99久久精品国产一区二区三区| 夜夜亚洲天天久久| 久久99精品久久久久久9蜜桃|