Created
September 27, 2013 15:34
-
-
Save swapnil-warke/6730532 to your computer and use it in GitHub Desktop.
Uva 10940 Throwing cards Josephs problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<vector> | |
#include<algorithm> | |
#include<cstdio> | |
#include<cstring> | |
#include<cmath> | |
#include <iostream> | |
#include <map> | |
#include <queue> | |
#include <set> | |
#include <string> | |
#include<limits> | |
using namespace std; | |
#define fi(i,a,b) for(int i=(int)a;i<=(int)b;i++) | |
#define fd(i,a,b) for(int i=(int)a;i>=(int)b;i--) | |
#define rep(i,n) fi(i,0,n-1) | |
//stl | |
#define sz(a) int((a).size()) | |
#define pb push_back | |
#define all(c) ((c).begin(),(c).end()) | |
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) | |
#define present(c,x) ((c).find(x) != (c).end()) | |
#define cpresent(c,x) (find(all(c),x) != (c).end()) | |
typedef long long ll; | |
typedef vector<int> vi; | |
typedef pair<int, int> ii; | |
typedef vector<ii> vii; | |
typedef vector<vi> vvi; | |
typedef vector<vii> vvii; | |
int main() | |
{ | |
int c[50001],d[50001]; | |
c[1]=d[1]=1; | |
c[2]=2;d[2]=1; | |
fi(i,3,50000) | |
{ | |
if(i%2) | |
{ | |
c[i]=d[i/2]*2; | |
d[i]=2*c[i/2+1]-1; | |
} | |
else | |
{ | |
c[i]=2*c[i/2]; | |
d[i]=d[i/2]*2-1; | |
} | |
} | |
int n; | |
while(cin>>n && n) | |
cout<<c[n]<<endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment