Codeforces Round #468 (Div. 2): C. Laboratory Work(贪心)
2018-03-05 15:08
447 查看
给你n个数,这n个数最大最小数差距<=2
让你重新构造一个序列,使得满足①平均数不变;②最大值最小值也不变;
③和原本序列相同的数字尽可能少(位置不对应)
当最大值-最小值<=1时,所有数字只能和原序列全部相同,直接输出就行了
当最大值-最小值=2时,有两种情况:①不停的将中间的数一个-1,一个+1;②不停的将最大的数-1,最小的数+1
取更优的就OK了
#include<stdio.h>
#include<vector>
using namespace std;
vector<int> G[100005];
int dep[100005];
void Sech(int x, int y)
{
int i, v;
dep[y]++;
for(i=0;i<G[x].size();i++)
{
v = G[x][i];
Sech(v, y+1);
}
}
int main(void)
{
int n, i, x, ans;
scanf("%d", &n);
for(i=2;i<=n;i++)
{
scanf("%d", &x);
G[x].push_back(i);
}
Sech(1, 1);
ans = 0;
for(i=1;i<=n;i++)
ans += (dep[i]%2==1);
printf("%d\n", ans);
return 0;
}
相关文章推荐
- 【Codeforces Round 326 (Div 2)A】【贪心】Duff and Meat 屯肉前溯花费最低
- 贪心/数学 Codeforces Round #212 (Div. 2) A. Two Semiknights Meet
- Codeforces Round #202 (Div. 2)B-贪心
- Codeforces Round #437 (Div. 2 C. Ordering Pizza 贪心 only two types of pizza
- Codeforces Round #379 (Div. 2) B. Anton and Digits(简单贪心)
- Codeforces Round #292 (Div. 2) C. Drazil and Factorial(贪心YY)
- Codeforces Round #468 (Div. 2): F. Teodor is not a liar!(DP)
- Codeforces Round #342 (Div. 2) 625A Guest From the Past(贪心)
- Codeforces Round #375 (Div. 2) Polycarp at the Radio 优先队列模拟题 + 贪心
- 【Codeforces Round 375 (Div 2) F】【构造 贪心】st-Spanning Tree 树的特殊最小生成树使得S度不超SD,T度不超TD
- Codeforces Round #353 (Div. 2) C. Money Transfers (贪心)
- Codeforces Round #277.5 (Div. 2)---B. BerSU Ball (贪心)
- Codeforces Round #433 (Div. 2) Jury Meeting(贪心)
- Codeforces Round #265 (Div. 2) C 暴力+ 找规律+ 贪心
- Codeforces Round #437 (Div. 2 C. Ordering Pizza 贪心 only two types of pizza
- Codeforces Round #342 (Div. 2)(A)贪心,数学
- Codeforces Round #364 (Div. 2) D. As Fast As Possible 【二分+贪心+验证】
- Codeforces Round #377 (Div. 2) C. Sanatorium(贪心,二分)
- Codeforces Round #334 (Div. 2)C. Alternative Thinking(贪心)
- 【Codeforces Round 330 (Div 2)E】【贪心 暴力】Edo and Magnets 给定矩形最多去除m个,最小面积矩形使得覆盖所有小矩形重心