zoukankan      html  css  js  c++  java
  • UVaLive 7500 Boxes and Balls (数学)

    题意:给定 n 个球,每次从每篮子里拿出来一个放在一个新篮子里,并移除相同的,按球的个数进行排序,问你用最多几个球能完成循环。

    析:数学问题,很容易发现前n项和就是最多的球数,所以我们只要找最大的n项就好了。

    代码如下:

    #include <cstdio>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <iostream>
    #include <cstring>
    #include <set>
    #include <queue>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <cctype>
    using namespace std ;
    typedef unsigned long long LL;
    typedef pair<int, int> P;
    const int INF = 0x3f3f3f3f;
    const double inf = 0x3f3f3f3f3f3f3f;
    const double eps = 1e-8;
    const int maxn = 1e6 + 5;
    const int dr[] = {0, 0, -1, 1};
    const int dc[] = {-1, 1, 0, 0};
    
    int main(){
        int T;  cin >> T;
        LL x;
        for(int kase = 1; kase <= T; ++kase){
            cin >> x;
            LL y = (LL)sqrt(2.0*x*1.0);
            LL ans = y*(y-1)/2;
            for(LL i = y-1; ; ++i){
                if(i * (i+1) <= 2*x)  ans = max(ans, i*(i+1)/2);
                else break;
            }
            printf("Case #%d: ", kase);
            cout << ans << endl;
        }
        return 0;
    }
    
  • 相关阅读:
    Flutter-路由
    写一个底部Tabs导航动态组件
    实例:Flutter布局01
    HTTP报文
    HTML文本的各种属性
    HTML必要简介和基础
    MySQL8.0.23安装超详细傻瓜式
    从一个HTTP请求来研究网络分层原理
    MySQL的增删改查
    MySQL常用数据类型有哪些?
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/5726777.html
Copyright © 2011-2022 走看看