Test instructions: The first line gives two numbers, N and a,n represent n Dice, and a represents the number of N dice thrown. The second line gives the number of N, which indicates the maximum number of dice that can be thrown, and the dice have problems,
It may not be possible to throw a few numbers, output n the number of dice can not be thrown out.
Analysis: We just consider the two extreme, test by the other dice to cast the maximum and minimum value, as well as its own at the maximum and minimum value, make a mathematical operation OK. The formula is as follows:
Maximum value of the dice-the maximum value to be cast + the minimum value that can be cast-1.
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 long Long Ll;typedef pair<int, int> p;c onst int inf = 0x3f3f3f3f;const double inf = 0x3f3f3f3f3f3f3f;const double EPS = 1e-8;const int maxn = 2e5 + 5;const int D R[] = {0, 0,-1, 1};const int dc[] = {-1, 1, 0, 0};int N, m;inline bool is_in (int r, int c) {return R >= 0 && ; R < n && C >= 0 && C < m;} int A[maxn];int Main () {LL sum; scanf ("%d%i64d", &n, &sum); LL x = sum; for (int i = 0; i < n; ++i) {scanf ("%d", &a[i]); Sum-= a[i]; } for (int i = 0; i < n; ++i) {if (i) Putchar (32); LL y = sum + a[i]; LL Mmax = min ((LL) a[i], X (n-1)); LL mmin = max (1LL, y); printf ("%I64d ", a[i]-mmax+mmin-1); } putchar (10); return 0;}
Codeforces 534C Polycarpus ' Dice (math)