• <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
            • 評論內容較長,點擊標題查看
            • --王私江
            久久综合伊人77777| 亚洲va中文字幕无码久久不卡| 99久久精品国产免看国产一区| 国产免费久久久久久无码| 久久996热精品xxxx| 亚洲伊人久久精品影院| 久久国产精品-久久精品| 久久综合日本熟妇| 久久发布国产伦子伦精品| 久久久久久国产精品无码下载| 久久天天躁狠狠躁夜夜躁2O2O| 久久国产精品波多野结衣AV| 精品久久久久久中文字幕人妻最新| 免费一级做a爰片久久毛片潮| 97r久久精品国产99国产精| 亚洲乱码日产精品a级毛片久久 | 成人亚洲欧美久久久久| 伊人久久大香线蕉av不卡| 狠狠色丁香婷婷综合久久来来去 | 久久综合九色欧美综合狠狠| 丁香五月网久久综合| 欧美一区二区三区久久综合| 国产精品日韩深夜福利久久| 狠狠色婷婷综合天天久久丁香| 亚洲av伊人久久综合密臀性色| 久久国产精品无| 青青久久精品国产免费看| 狠狠色丁香婷婷综合久久来来去| 亚洲狠狠综合久久| 丰满少妇人妻久久久久久4| 久久精品免费一区二区三区| 青青草原1769久久免费播放| 久久国产成人精品麻豆| 亚洲精品高清国产一久久| 日本精品久久久中文字幕| 久久精品成人免费网站| 日本精品久久久中文字幕 | 国产亚洲综合久久系列| 久久国产成人精品麻豆| 久久成人永久免费播放| 亚洲va久久久久|