Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
竟然也A了 哦呵呵#include <cstdio> #include <iostream> using namespace std; int DetoBinary(long long n,int a[]) { int count = 0; while(n) { a[count++] = n%2; n = n/2; } return count; } int main() { int cas; scanf("%d",&cas); while(cas--) { int length; char csign[165]; int sign[165]; long long n; int a[165],b[165]; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); int flag1 = 1,flag2 = 1; scanf("%d",&length); scanf("%s",csign); scanf("%I64d",&n); if(n<0) { n = -1*n; flag1 = 0; } int l = DetoBinary(n,a); if(l>length) { printf("Impossible\n"); continue; } //for(int i=0;i<l;i++) // printf("%d",a[l-1-i]); for(int i = length-1 ;i>=0;i--) { if(flag1==1) if(csign[i]=='p') sign[length-1-i] = 1; else sign[length-1-i] =0; else if(csign[i]=='p') sign[length-1-i] = 0; else sign[length-1-i] = 1; } for(int i=0;i<length;i++) { a[i+1] += a[i]/2; a[i] = a[i]% 2; if(a[i] == 1) { if(sign[i] == 0) a[i+1] ++; } } if(a[length]) printf("Impossible\n"); else { for(int i=0;i<length;i++) printf("%d",a[length-1-i]); printf("\n"); } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator