/// Raihan Ruhin /// CSE, Jahangirnagar University. /// Dhaka-Bangladesh. /// id: raihanruhin (topcoder / codeforces / codechef / uva), 3235 (lightoj) /// mail: raihanruhin@ (yahoo / gmail / facebook) /// blog: ruhinraihan.blogspot.com #include<bits/stdc++.h> using namespace std; #define SET(a) memset(a,-1,sizeof(a)) #define CLR(a) memset(a,0,sizeof(a)) #define PI acos(-1.0) #define MOD 1000000007 #define MX 100010 int main() { ios_base::sync_with_stdio(0);cin.tie(0); int kk=1, tc, n, m, k, x; string s; cin>>tc; while(tc--) { vector<int>nowID, nextID, nowData, nextData, initial; cin>>n>>k; m=(1<<n); vector<int> child[m+2]; initial.push_back(0); for(int i=1;i<=m;i++) { cin>>x; initial.push_back(x); nowData.push_back(x); nowID.push_back(i); } while(nowData.size()>1) { for(int i=0;i<nowData.size();i+=2) { if(nowData[i]>=nowData[i+1]) { nextData.push_back(min(initial[nowID[i]], nowData[i]-nowData[i+1]+k)); nextID.push_back(nowID[i]); child[nowID[i]].push_back(nowID[i+1]); } else { nextData.push_back(min(initial[nowID[i+1]], nowData[i+1]-nowData[i]+k)); nextID.push_back(nowID[i+1]); child[nowID[i+1]].push_back(nowID[i]); } } nowData=nextData; nowID=nextID; nextData.clear(); nextID.clear(); } cout<<nowID[0]<<"\n"; cout<<child[nowID[0]][0]; for(int i=1;i<child[nowID[0]].size();i++) cout<<" "<<child[nowID[0]][i]; cout<<"\n"; } return 0; }
Tuesday, 31 May 2016
Arm Wrestling Tournament (UVALive 5060, Regionals 2010 >> Asia - Jakarta)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment