Click the open link/* C:
Test instructions: Give an integer sequence, the maximum minimum value difference is not more than 2,
Requires the construction of a new equal-length sequence, so that (the same as the original series
The number is least) and (two of the series and equal) and (the largest of the new series
Value is less than or equal to the maximum value of the original sequence, the minimum value of the new sequence is greater than
The minimum value of the sequence number of ideas: The problem is the original sequence maximum and minimum value difference
Over 2, when the difference is 1 or 0, can not change the size of the original sequence number;
When the difference is 2 o'clock, you can convert the middle number to both sides, or both sides of the number
to intermediate transformation;
* * #include <bits/stdc++.h>
using namespace Std;
const int MAXN = 200010;
int CNT[MAXN];
int A[MAXN];
int main ()
{
memset (cnt,0,sizeof (CNT));
int n;
int ma =-maxn,mi = MAXN;
scanf ("%d", &n);
for (int i = 0; i < n; i++)
{
int x;
scanf ("%d", &x);
A[i] = x + 100000;
if (A[i] > Ma)
Ma = a[i];
if (A[i] < mi)
mi = a[i];
cnt[a[i]]++;
}
printf ("%d%d\n", mi,ma);
if (mi = = Ma | | ma-mi = = 1)
{
cout<<1<<endl;
printf ("%d\n", N);
for (int i = 0; i < n-1; i++)
printf ("%d", a[i]-100000);
printf ("%d\n", a[n-1]-100000);
}
Else
{
int tmp = ma-100000;
int a = Cnt[ma];
int b = Cnt[ma-1];
int c = Cnt[mi];
int m;
printf ("%d%d%d\n", a,b,c);
mi = min (a,c);
if (mi*2 >= b/2*2)
{
m = n-(mi*2);
A-= mi;
c-= mi;
b + = mi*2;
}
Else
{
m = n-(b/2*2);
A + = B/2;
c + = B/2;
B-= b/2*2;
}
printf ("%d%d%d\n", a,b,c);
printf ("%d\n", m);
for (int i = 0; i < A; i++)
printf ("%d", TMP);
for (int i = 0; i < b-1; i++)
printf ("%d", tmp-1);
if (c = = 0)
printf ("%d\n", tmp-1);
else if (b! = 0)
printf ("%d", tmp-1);
for (int i = 0; i < c-1; i++)
printf ("%d", tmp-2);
if (C > 0)
printf ("%d\n", tmp-2);
}
return 0;
}
/*
D:
Test instructions: There is an apple tree, and once the tree starts to result, it will appear in each node
An apple, and rolled down the tree at the bottom of the branch. In addition to the apple in the first inflorescence
In addition, all apples roll down a branch at the same time every second, once there are two
An apple meets at the same node, the two apples will be offset (i.e., each layer's last
There will be only 0 or 1 apples left, and the total amount of apples can eventually be reached. Idea: DFS statistics per layer of apples, is odd then this layer will get an apple,
Even can't get Apple
*/
#include <bits/stdc++.h>
using namespace Std;
int cnt[100100];
BOOL vis[100100];
Vector<int> g[100100];
int n;
void Dfs (int x,int step)
{
VIS[X] = 1;
cnt[step]++;
for (int i = 0; i < g[x].size (); i++)
{
if (!vis[g[x][i]])
DFS (G[X][I],STEP+1);
}
}
int main ()
{
scanf ("%d", &n);
memset (cnt,0,sizeof (CNT));
memset (vis,0,sizeof (VIS));
for (int i = 2; I <= n; i++)
{
int x;
scanf ("%d", &x);
G[x].push_back (i);
}
DFS (a);
int sum = 0;
for (int i = 1; I <= n; i++)
if (cnt[i]%2! = 0)
sum++;
printf ("%d\n", sum);
return 0;
}