UVa 12208 How Many Ones Needed? (组合数学)

12208 - How Many Ones Needed?

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php?option=onlinejudge&Itemid=99999999&category=244&page=show_problem&problem=3360

水。

完整代码:

/*0.035s*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll c[31][31], sum;
int i, j, cnt;

void init()
{
    for (i = 0; i < 31; ++i)
        c[i][0] = c[i][i] = 1;
    for (i = 2; i < 31; ++i)
        for (j = 1; j < i; ++j)
            c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
}

inline ll calc(int n, bool yeah)
{
    sum = cnt = 0;
    for (i = 31; i >= 0; --i)
    {
        if (n & (1 << i))
        {
            for (j = 0; j <= i; ++j)
                sum += c[i][j] * (j + cnt);
            ++cnt;
        }
    }
    if (yeah) sum += cnt;///把数n也算上
    return sum;
}

int main()
{
    init();
    int a, b, cas = 0;
    ll ans;
    while (scanf("%d%d", &a, &b), a || b)
        printf("Case %d: %lld\n", ++cas, calc(b, true) - calc(a, false));
    return 0;
}

作者:csdn博客 synapse7

查看本栏目更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索for
, long
many
how many days needed、needed me、if needed、you needed me、man.needed,以便于您获取更多的相关知识。

时间: 2024-12-23 13:31:18

UVa 12208 How Many Ones Needed? (组合数学)的相关文章

UVa 10254 The Priest Mathematician:组合数学&amp;amp;规律发现&amp;amp;高精度

10254 - The Priest Mathematician Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=34&page=show_problem&problem=1195 The ancient folklore behind the "Towers of Hanoi" puzzle i

UVa 11609 Teams (组合数学)

11609 - Teams Time limit: 1.000 seconds http://uva.onlinejudge.org/index.php? option=com_onlinejudge&Itemid=8&category=467&page=show_problem&problem=26 56 In a galaxy far far away there is an ancient game played among the planets. The spec

UVa 10198 Counting:组合数学&amp;amp;高精度

10198 - Counting Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1139 The Problem Gustavo knows how to count, but he is now learning how write numbers. As

UVa 10157 Expressions:组合数学&amp;amp;高精度

10157 - Expressions Time limit: 10.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=34&page=show_problem&problem=1098 Let X be the set of correctly built parenthesis expressions. The elements of X a

UVa 10247 Complete Tree Labeling:组合数学&amp;amp;高精度

10247 - Complete Tree Labeling Time limit: 15.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1188 A complete k-ary tree is a k-ary tree in which all leaves have same d

UVa 861 Little Bishops (组合数学)

861 - Little Bishops Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=36&page=show_problem&problem=802 A bishop is a piece used in the game of chess which is played on a board of squar

UVa 10237 Bishops:组合数学

10237 - Bishops Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1178 A bishop is a piece used in the game of chess which is played on a board of square grids. A bishop ca

UVa 10994 Simple Addition :组合数学

10994 - Simple Addition Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=115&page=show_problem&problem=1935 计算sum{i从右往左数的第一个非0数字,p<=i<=q}. 见代码.. 01./*0.016s*/ 02. 03.#include<

UVa 11076 Add Again (组合数学)

11076 - Add Again Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php? option=com_onlinejudge&Itemid=8&category=467&page=show_problem&problem=20 17 Summation of sequence of integers is always a common problem in Computer Science