UVALive 3177 Beijing Guards】的更多相关文章

题目大意:给定一个环,每个人要得到Needi种物品,相邻的人之间不能得到相同的,问至少需要几种. 首先把n=1特判掉. 然后在n为偶数的时候,答案就是max(Needi+Needi+1)(包括(1,n)). 证明:把物品排成一行,只要一个人从左边开始取,下一个人从右边开始取,以此类推,保证不会重复. 然后在n为奇数的时候,答案就不好做了. 观察一下这道题,发现答案满足可二分性,不如思考一下check怎么写. 因为n为奇数时难点就在看n与1是否矛盾上,只要解决了这个问题,一切好说. 不难发现答案下…
Beijing Guards Beijing was once surrounded by four rings of city walls: the Forbidden City Wall, the Imperial City Wall, the Inner City Wall, and finally the Outer City Wall. Most of these walls were demolished in the 50s and 60s to make way for road…
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1178 题意 圆桌上有n个人,每个人要求a_i种不同的礼物,相邻两个人的礼物不能重复,问有至少要准备多少种礼物 思路 如刘书 1. 明显,若n=1,直接输出a[0] 2. 若n为偶数,则可以形如ABABAB,直接取最大的两个相连之和 3. 若n为奇数,则可以转化为二分判断…
题目链接:uva 1335 - Beijing Guards 题目大意:有n个人为成一个圈,其中第i个人想要r[i]种不同的礼物,相邻的两个人可以聊天,炫耀自己的礼物.如果两个相邻的人拥有同一种礼物,则双方都会很不高兴,问最少需要多少种不同的礼物才能满足所有人的需求,假设每种礼物有无限多个. 解题思路:自己想没有什么思路,参照大白书上的解释,琢磨了一下. 如果n为偶数的话,ans = max{r[i] + r[i + 1] },(r[n + 1] = r[1]). 如果n为奇数的话,上述式子就不…
Beijing Guards Beijing was once surrounded by four rings of city walls: the Forbidden City Wall, the Imperial City Wall, the Inner City Wall, and finally the Outer City Wall. Most of these walls were demolished in the 50s and 60s to make way for road…
UVA1335 Beijing Guards 双倍经验:P4409 [ZJOI2006]皇帝的烦恼 如果只是一条链,第一个护卫不与最后一个护卫相邻,那么直接贪心,找出最大的相邻数的和. 当变成环,贪心很容易找到反例(如[5,5,5],贪心答案为10,实际上为15) 答案存在单调性,考虑二分 那么怎么判断mid是否合理呢?设mx[i]表示第i个数与第一个数最多可以相同多少个,mn[i] 表示第i个数与第一个数至少相同多少个 mx[i]=min(a[i],a[1]-mn[i-1]); [i-1]最少…
Beijing was once surrounded by four rings of city walls: the Forbidden City Wall, the Imperial City Wall, the Inner City Wall, and finally the Outer City Wall. Most of these walls were demolished in the 50s and 60s to make way for roads. The walls we…
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1178 http://7xjob4.com1.z0.glb.clouddn.com/8e1ee1ef5ea10e46ebda75b88b058f47 题意:n个人围圈,每人有不同或相同数量礼物,相邻礼物不能一样,求最少总礼物数. 思路: n是偶数:为相邻两人礼物数和的最大值:n…
竟然用二分,真是想不到: 偶数的情况很容易想到:不过奇数的就难了: 奇数的情况下,一个从后向前拿,一个从前向后拿的分配方法实在太妙了! 注: 白书上的代码有一点点错误 代码: #include<cstdio> #define maxn 100009 #include<algorithm> using namespace std; int p[maxn],right[maxn],left[maxn],n; bool check(int m) { ],y=m-p[]; left[]=x…
入口: https://cn.vjudge.net/problem/UVA-1335 [题意] 有n个人为成一个圈,其中第i个人想要r[i]种不同的礼物,相邻的两个人可以聊天,炫耀自己的礼物.如果两个相邻的人拥有同一种礼物,则双方都会很不高兴,问最少需要多少种不同的礼物才能满足所有人的需求,假设每种礼物有无限多个 [分析] [蓝书例题] 如果n为偶数的话,ans = max{r[i] + r[i + 1] },(r[n + 1] = r[1]). 如果n为奇数的话,上述式子就不成立了,因为n个人…