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 |
第一个ac,庆祝一下/** *@author: Bin Hong <hongbin0908@gmail.com> */ #include <iostream> #include <deque> #include <stack> //#define __DEBUG__ int case_num; int num; std::deque<bool> pas; std::stack<int> op; #ifdef __DEBUG__ void output() { std::cout << "["; for (int i = 0; i < (int)pas.size();i++) { if (pas[i]) { std::cout << "(" << " "; } else { std::cout << ")" << " "; } } std::cout << "]" << std::endl; } #endif void encode() { for (int i = 0; i < (int)pas.size();i++) { if (pas[i]) { op.push(i); } else { int left = op.top(); op.pop(); std::cout << (i - left + 1)/2 << " "; } } std::cout << std::endl; } void cal_per_line(int num) { pas.clear(); int last = 0; int cur = 0; for (int i = 0; i < num; i++) { std::cin >> cur; #ifdef __DEBUG__ std::cout << cur << " "; #endif for (int j = 0; j < cur - last; j++) { pas.push_back(true); } pas.push_back(false); last = cur; } #ifdef __DEBUG__ std::cout << std::endl; output(); #endif encode(); } int main(int argc, char** argv) { std::cin >> case_num; #ifdef __DEBUG__ std::cout << "case_num: " << case_num << std::endl; #endif for (int i = 0 ; i < case_num; i++) { std::cin >> num; #ifdef __DEBUG__ std::cout << "num: " << num << std::endl; #endif cal_per_line(num); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator