C1. Bessie’s Birthday Cake (Easy Version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output
Proof Geometric Construction Can Solve All Love Affairs - manbo-p
⠀
This is the easy version of the problem. The only difference between the two versions is the constraint on y y y. In this version y = 0 y = 0 y=0. You can make hacks only if both versions are solved.
Bessie has received a birthday cake from her best friend Elsie, and it came in the form of a regular polygon with n n n sides. The vertices of the cake are numbered from 1 1 1 to n n n clockwise. You and Bessie are going to choose some of those vertices to cut non-intersecting diagonals into the cake. In other words, the endpoints of the diagonals must be part of the chosen vertices.
Bessie would only like to give out pieces of cake which result in a triangle to keep consistency. The size of the pieces doesn’t matter, and the whole cake does not have to be separated into all triangles (other shapes are allowed in the cake, but those will not be counted).
Bessie has already chosen x x x of those vertices that can be used to form diagonals. She wants you to choose no more than y y y other vertices such that the number of triangular pieces of cake she can give out is maximized.
What is the maximum number of triangular pieces of cake Bessie can give out?
Input
The first line contains a single integer t t t ( 1 ≤ t ≤ 1 0 4 1 \leq t \leq 10^4 1≤t≤104) — the number of test cases.
The first line of each test case consists of three integers, n n n, x x x, and y y y ( 4 ≤ n ≤ 1 0 9 4 \leq n \leq 10^9 4≤n≤109, 2 ≤ x ≤ min ( n , 2 ⋅ 1 0 5 ) 2 \leq x \leq \min(n, 2 \cdot 10^5) 2≤x≤min(n,2⋅105), y = 0 y = 0 y=0) — the number of sides of the polygon, number of vertices Bessie has chosen, and the maximum number of other vertices you can choose.
The second line consists of x x x distinct integers from 1 1 1 to n n n, representing the vertices Bessie has chosen.
It is guaranteed the sum of x x x over all test cases does not exceed 2 ⋅ 1 0 5 2 \cdot 10^5 2⋅105.
Output
For each test case, output a single integer: the maximum number of non-intersecting triangular pieces of cake she can give out.
Example
inputCopy
3
8 4 0
1 6 2 5
8 8 0
1 3 2 5 4 6 7 8
4 2 0
1 3
outputCopy
2
6
2
Note
In test cases 1 1 1, 2 2 2 and 3 3 3, you can get 2 2 2, 6 6 6 and 2 2 2 non-intersecting triangular pieces of cake, respectively. A possible construction is shown in the following pictures:
The green dots represent vertices that can be used, the blue lines represent diagonals that are drawn, and the red numbers represent triangles that are counted.
AC代码:
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<queue>
#include<string>
#include<bitset>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<numeric>
#include<iomanip>
#define endl '\n'
using namespace std;typedef long long ll;
typedef pair<int, int>PII;
const int N=3e5+10;
const int MOD=1e9 + 7;
const int INF=0X3F3F3F3F;
const int dx[]={-1,1,0,0,-1,-1,+1,+1};
const int dy[]={0,0,-1,1,-1,+1,-1,+1};
const int M = 1e6 + 10;int t ;
int n, x ,y;
int a[N];
int main()
{cin >> t;while(t --){cin >> n >> x >> y;for(int i = 1; i <= x; i ++){cin >> a[i];}sort(a + 1, a + 1 + x);a[x + 1] = a[1] + n;int ans = x - 2;for(int i = 1; i <= x; i ++){if(a[i + 1] - 2 == a[i]) ans ++;}cout << ans << endl;}return 0;
}
//纯数学