sgu 175 Encoding
题意:已知在原串的位置,问在编码串的位置。
写个递归函数。水平够的话一下就能写出来。
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <vector> #include <iomanip> #include <cstring> #include <map> #include <queue> #include <set> #include <cassert> #define mkp make_pair using namespace std; const double EPS=1e-8; const int SZ=800010,INF=0x7FFFFFFF; typedef long long lon; int getp(int len,int pos) { if(len==1)return 1; else { int pre=len/2,last=len-pre; if(pos<=pre)return last+getp(pre,pre-pos+1); else return getp(last,len-pos+1); } } int main() { std::ios::sync_with_stdio(0); //freopen("d:\\1.txt","r",stdin); lon casenum; //cin>>casenum; //for(lon time=1;time<=casenum;++time) { int n,pos; cin>>n>>pos; cout<<getp(n,pos)<<endl; } return 0; }