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 |
求大神 不知道哪里WA了 我是按位处理的#include<iostream> #include<string> #include<vector> #include <fstream> #include<bitset> using namespace std; string np_data; int length; __int64 data; unsigned __int64 cur_data; bitset<64> bs; int foundIndex = 63; bool handData() { return true; } void add(int index) { bool cin = 1, next_cin = false; do { if (np_data[length - 1 - index] == 'n') { next_cin = !bs[index]; } else { next_cin = bs[index]; } bs[index] = !bs[index]; cin = next_cin; index++; } while (cin); } int main() { //ifstream in("d:\\document\\test.txt"); int max_case; cin >> max_case; while (max_case--) { cin >> length >> np_data >> data; cur_data = 0; bool result = true; bool hasFound = true; foundIndex = length - 1; bs = bitset<64>(data); if (bs[63]) { hasFound = false; for (int i = 63; i >= length; i--) { if (!bs[i]) { result = false; break; } } if (result) { for (int i = length - 1; i >= 0; i--) { if (np_data[length - 1 -i] != 'n') { if (!bs[i]) { result = false; break; } else { bs[i] = 0; } } else { bs[i] = 1; if (bs[i]) { hasFound = true; break; } } } } } else { unsigned __int64 max = 0; for (int i = 0; i <= length - 1; i++) { max = max << 1; if (np_data[i] != 'n') { max += 1; } } if (max < (unsigned __int64)data) { result = false; } } if (result && hasFound) { for (int i = 0; i < foundIndex; i++) { int index = length - 1 - i; if (np_data[index] == 'n' && bs[i]) { add(i + 1); } } for (int i = length - 1; i >= 0; i--) { cout << bs[i]; } cout << endl; } else { cout << "Impossible" << endl; } } system("pause"); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator