LightOj 1042 - Secret Origins
/*
LightOj 1042-Secret Origin
Verdict:: Accepted
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <cctype>
#include <sstream>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#define sf scanf
#define pf printf
#define sfint scanf ("%d %d",&a,&b)
#define sfl scanf ("%ld %ld",&a,&b)
#define sfll scanf ("%lld %lld",&a,&b)
#define sfd scanf ("%lf %lf",&a,&b)
#define sff scanf ("%f %f",&a,&b)
#define loop(i,n) for(i=0;i<n;i++)
#define LL long long
#define L long
#define nl puts("")
#define MX 1000005
#define N 100
#define MOD 10000000007
#define pb push_back
#define pi acos(-1.0)
#define sz size()
#define gc getchar ()
#define ps push
#define clr clear
#define bn begin()
#define ed end()
using namespace std;
int main()
{
int t,tc,i;
vector<int>v;
sf("%d",&tc);
loop(t,tc)
{
LL n,a,b;
sf("%lld",&n);
a=n;b=n;
// making Binary
while(a!=0)
{
a%=2;
v.pb(a);
b/=2;
a=b;
}
v.pb(0);
//loop(i,v.size())cout << v[i] << " ";
reverse(v.begin(),v.end()); //nl;
next_permutation(v.begin(),v.end());
//loop(i,v.size())cout << v[i] << " ";
int sze=v.size();
LL p=sze-1, r=0;
// Binary to Decimal of your desired Number.
loop(i,sze)
{
r+=v[i]*pow(2,p);
p--;
}
pf("Case %d: %lld\n",t+1,r);
v.clear();
}
return 0;
}
LightOj 1042-Secret Origin
Verdict:: Accepted
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <cctype>
#include <sstream>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#define sf scanf
#define pf printf
#define sfint scanf ("%d %d",&a,&b)
#define sfl scanf ("%ld %ld",&a,&b)
#define sfll scanf ("%lld %lld",&a,&b)
#define sfd scanf ("%lf %lf",&a,&b)
#define sff scanf ("%f %f",&a,&b)
#define loop(i,n) for(i=0;i<n;i++)
#define LL long long
#define L long
#define nl puts("")
#define MX 1000005
#define N 100
#define MOD 10000000007
#define pb push_back
#define pi acos(-1.0)
#define sz size()
#define gc getchar ()
#define ps push
#define clr clear
#define bn begin()
#define ed end()
using namespace std;
int main()
{
int t,tc,i;
vector<int>v;
sf("%d",&tc);
loop(t,tc)
{
LL n,a,b;
sf("%lld",&n);
a=n;b=n;
// making Binary
while(a!=0)
{
a%=2;
v.pb(a);
b/=2;
a=b;
}
v.pb(0);
//loop(i,v.size())cout << v[i] << " ";
reverse(v.begin(),v.end()); //nl;
next_permutation(v.begin(),v.end());
//loop(i,v.size())cout << v[i] << " ";
int sze=v.size();
LL p=sze-1, r=0;
// Binary to Decimal of your desired Number.
loop(i,sze)
{
r+=v[i]*pow(2,p);
p--;
}
pf("Case %d: %lld\n",t+1,r);
v.clear();
}
return 0;
}
Comments
Post a Comment