LA 7500 Boxes and Balls (mathematics)

Source: Internet
Author: User

Test instructions: Given n balls, each time you take one from each basket and put it in a new basket, and remove the same, sort by the number of balls, ask you to complete the loop with a few balls.

Analysis: Mathematical problems, it is easy to find the top N and is the largest number of balls, so we just need to find the largest n.

The code is as follows:

#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, in t> p;const int inf = 0x3f3f3f3f;const double inf = 0x3f3f3f3f3f3f3f;const double EPS = 1e-8;const int maxn = 1e6 + 5;co NST 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;}

LA 7500 Boxes and Balls (math)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.