sgu 175 Encoding
来源:互联网 发布:泰坦尼克号细节知乎 编辑:程序博客网 时间:2024/05/22 15:18
175. Encoding
time limit per test: 0.5 sec.
memory limit per test: 4096 KB
memory limit per test: 4096 KB
input: standard
output: standard
output: standard
Let phi(W) is the result of encoding for algorithm:
1. If the length of W is 1 then phi(W) is W;
2. Let coded word is W = w1w2...wN and K = N / 2 (rounded down);
3. phi(W) = phi(wNwN-1...wK+1) + phi(wKwK-1...w1).
For example, phi('Ok') = 'kO', phi('abcd') = 'cdab'.
Your task is to find position of letter wq in encoded word phi(W).
1. If the length of W is 1 then phi(W) is W;
2. Let coded word is W = w1w2...wN and K = N / 2 (rounded down);
3. phi(W) = phi(wNwN-1...wK+1) + phi(wKwK-1...w1).
For example, phi('Ok') = 'kO', phi('abcd') = 'cdab'.
Your task is to find position of letter wq in encoded word phi(W).
Input
Given integers N, q (1 <= N <= 10^9; 1<= q <= N), where N is the length of word W.
Output
Write position of letter wq in encoded word phi(W).
Sample test(s)
Input
9 4
Output
8
这是。。。。?编程能力测试题?
简单的递归方程就解决了。
贴上代码:
这是。。。。?编程能力测试题?
简单的递归方程就解决了。
贴上代码:
#include<iostream>#include<cstring>#include<cstdio>#include<set>#include<algorithm>#include<vector>#include<cstdlib>#define inf 0xfffffff#define CLR(a,b) memset((a),(b),sizeof((a)))#define FOR(a,b) for(int a=1;a<=(b);(a)++)using namespace std;int const nMax = 1010;int const base = 10;typedef int LL;typedef pair<LL,LL> pij;// std::ios::sync_with_stdio(false);int ans;void phi (int l,int n,int p){ if(n==1) { ans=l; return ; } int k=n/2; if(p<=k) { phi(n-k+l,k,k-p+1); }else { phi(l,n-k,n-p+1); } return ;}int n,p;int main(){ scanf("%d%d",&n,&p); phi(1,n,p); printf("%d\n",ans); return 0;}
- sgu 175 Encoding
- sgu 175 Encoding 二分
- sgu 175
- SGU
- SGU
- SGU
- SGU
- SGU
- SGU
- (SGU
- SGU
- SGU
- SGU
- SGU
- SGU
- SGU
- SGU
- Encoding
- ios 从网络下载图片,保存,并用imageview从保存中显示
- 生于忧患、死于安乐
- 面试100题:6.求上排数字在下排出现的次数
- WAP版浏览器不支持.NET的linkButton
- spring事物管理
- sgu 175 Encoding
- Android Push Notification实现信息推送使用
- WPF A simple example of implementing ICommand Binding
- 24种语言执行外部命令的方法
- HTML5高级编程之图形扭曲及其应用一(原理篇)
- 输出字符图形·2
- new iPad 图片分辨率的问题
- json创建和解析
- 学编程应注意的问题