【瞎搞】 UVALive 6527 Counting ones
2014-11-01 14:43
411 查看
题目地址
例:
0000
0001
0010
0011
0100
0101
0110
0111
每一位上的个数都是 每 2^i的数 最后2^(i-1)都为 1
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <cmath>
using namespace std;
#include <queue>
#include <stack>
#include <vector>
#include <deque>
#define cler(arr, val) memset(arr, val, sizeof(arr))
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define IN freopen ("in.txt" , "r" , stdin);
#define OUT freopen ("out.txt" , "w" , stdout);
typedef long long LL;
const int MAXN = 10052;
const int MAXM = 6000010;
const int INF = 0x3f3f3f3f;
const int mod = 1e9;
const double eps= 1e-8;
#define lson l,m, rt<<1
#define rson m+1,r,rt<<1|1
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
LL a,b;
while(cin>>a>>b)
{
a--;
LL sum1=0,sum2=0;
LL n=a;
LL i=0;
while(n)
{
i++;
LL po=(LL)pow(2,i);
LL po2=(LL)pow(2,i-1);
LL moo=a%po;
if(moo>=po/2)
sum1+=a/po*po2+moo-(po2-1);
else sum1+=a/po*po2;
n/=2;
}
n=b;
i=0;
while(n)
{
i++;
LL po=(LL)pow(2,i);
LL po2=(LL)pow(2,i-1);
LL moo=b%po;
if(moo>=po/2)
sum2+=b/po*po2+moo-(po2-1);
else sum2+=b/po*po2;
n/=2;
}
cout<<sum2-sum1<<endl;
}
return 0;
}
例:
0000
0001
0010
0011
0100
0101
0110
0111
每一位上的个数都是 每 2^i的数 最后2^(i-1)都为 1
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <cmath>
using namespace std;
#include <queue>
#include <stack>
#include <vector>
#include <deque>
#define cler(arr, val) memset(arr, val, sizeof(arr))
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define IN freopen ("in.txt" , "r" , stdin);
#define OUT freopen ("out.txt" , "w" , stdout);
typedef long long LL;
const int MAXN = 10052;
const int MAXM = 6000010;
const int INF = 0x3f3f3f3f;
const int mod = 1e9;
const double eps= 1e-8;
#define lson l,m, rt<<1
#define rson m+1,r,rt<<1|1
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
LL a,b;
while(cin>>a>>b)
{
a--;
LL sum1=0,sum2=0;
LL n=a;
LL i=0;
while(n)
{
i++;
LL po=(LL)pow(2,i);
LL po2=(LL)pow(2,i-1);
LL moo=a%po;
if(moo>=po/2)
sum1+=a/po*po2+moo-(po2-1);
else sum1+=a/po*po2;
n/=2;
}
n=b;
i=0;
while(n)
{
i++;
LL po=(LL)pow(2,i);
LL po2=(LL)pow(2,i-1);
LL moo=b%po;
if(moo>=po/2)
sum2+=b/po*po2+moo-(po2-1);
else sum2+=b/po*po2;
n/=2;
}
cout<<sum2-sum1<<endl;
}
return 0;
}
相关文章推荐
- 【瞎搞】 UVALive 6527 Counting ones
- UVALive 6527 Counting ones dfs(水
- UVALive 6527 Counting ones dfs(水
- UVAlive 5971 Permutation Counting
- UVALive 6184 One-Dimensional Cellular Automaton(矩阵加速)
- UVALive 7752 Free Figurines (瞎搞)
- ecjtu-summer training #5 F - And Then There Was One UVALive - 3882
- UVALive - 3882 And Then There Was One (递推[dp])
- UVALive3882-And Then There Was One-约瑟夫问题-递推
- UVALive 6602 Counting Lattice Squares
- UVALive 3882 And Then There Was One
- [UVALive4864] Bit Counting && 数位DP
- 【瞎搞】 UVALive 6530 Football
- UVALive 6184 - One-Dimensional Cellular Automaton 高斯消元模板题 (2012 Tokyo)
- 【瞎搞】 UVALive 6530 Football
- C - Permutation Counting UVALive - 5092 dp
- [UVALive5058] Counting BST && 计数DP + BST
- UVALive 6527 Counting ones
- UVALive 7337 Counting Weekend Days【水题】
- UVALive - 3882 And Then There Was One 约瑟夫的变形问题