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)