hdu 5874 Friends and Enemies(思维)
2017-06-20 15:07
369 查看
On an isolated island, lived some dwarves. A king (not a dwarf) ruled the island and the seas nearby, there are abundant cobblestones of varying colors on the island. Every two dwarves on the island are either friends or enemies. One day, the king demanded that each dwarf on the island (not including the king himself, of course) wear a stone necklace according to the following rules:
For any two dwarves, if they are friends, at least one of the stones from each of their necklaces are of the same color; and if they are enemies, any two stones from each of their necklaces should be of different colors. Note that a necklace can be empty.
Now, given the population and the number of colors of stones on the island, you are going to judge if it’s possible for each dwarf to prepare himself a necklace.
Input
Multiple test cases, process till end of the input.
For each test case, the one and only line contains 2 positive integers M,N (M,N<231)M,N (M,N<231) representing the total number of dwarves (not including the king) and the number of colors of stones on the island.
Output
For each test case, The one and only line of output should contain a character indicating if it is possible to finish the king’s assignment. Output
Sample Input
20 100
Sample Output
T
题目大意:
就是有M个人N种颜色的石头 M个人中每两个人 不是朋友就是敌人
现在他们每个人要用石头要串一条项链 要求是
1.朋友之间的项链至少有一个相同颜色的石头
2.敌人之间没有颜色相同的石头
3.项链可以使空的 就是不串石头
问N种颜色的石头能不能满足这M个人
最坏的情况就是 分成两组,同一组的全部是敌人,但是与对面组的全部是朋友,因为与对面组的全部是朋友,但是对面组的人之间又是敌人,所以你有一半的人的数量的珠子颜色是不同的,而和你同组的人又不能有任何一个和你相同,那么它也是有一半的人数的珠子颜色不一样而且和你的所有珠子颜色也不一样,那么加起来就是 n/2*n/2 了,但人数不一定能平分,那么就是(n/2*(n-n/2))
For any two dwarves, if they are friends, at least one of the stones from each of their necklaces are of the same color; and if they are enemies, any two stones from each of their necklaces should be of different colors. Note that a necklace can be empty.
Now, given the population and the number of colors of stones on the island, you are going to judge if it’s possible for each dwarf to prepare himself a necklace.
Input
Multiple test cases, process till end of the input.
For each test case, the one and only line contains 2 positive integers M,N (M,N<231)M,N (M,N<231) representing the total number of dwarves (not including the king) and the number of colors of stones on the island.
Output
For each test case, The one and only line of output should contain a character indicating if it is possible to finish the king’s assignment. Output
T" (without quotes) if possible,F” (without quotes) otherwise.
Sample Input
20 100
Sample Output
T
题目大意:
就是有M个人N种颜色的石头 M个人中每两个人 不是朋友就是敌人
现在他们每个人要用石头要串一条项链 要求是
1.朋友之间的项链至少有一个相同颜色的石头
2.敌人之间没有颜色相同的石头
3.项链可以使空的 就是不串石头
问N种颜色的石头能不能满足这M个人
最坏的情况就是 分成两组,同一组的全部是敌人,但是与对面组的全部是朋友,因为与对面组的全部是朋友,但是对面组的人之间又是敌人,所以你有一半的人的数量的珠子颜色是不同的,而和你同组的人又不能有任何一个和你相同,那么它也是有一半的人数的珠子颜色不一样而且和你的所有珠子颜色也不一样,那么加起来就是 n/2*n/2 了,但人数不一定能平分,那么就是(n/2*(n-n/2))
#include <bits/stdc++.h> using namespace std; int main() { long long n,m; while(scanf("%lld%lld",&n,&m)!=EOF) { if(n/2*(n-n/2)<=m) printf("T\n"); else printf("F\n"); } }
相关文章推荐
- HDU 5874 Friends and Enemies【思维】
- HDU 5874 Friends and Enemies
- HDU 5874-Friends and Enemies(n个结点的无三元环的图的最大边数)
- 2016 大连网络赛 HDU 5874 Friends and Enemies【思维】
- hdu 5874 Friends and Enemies
- HDU 5874 Friends and Enemies 大连网络赛
- HDU 5874 Friends and Enemies(二分图思想)——2016 ACM/ICPC Asia Regional Dalian Online
- HDU 5874 Friends and Enemies 【构造】 (2016 ACM/ICPC Asia Regional Dalian Online)
- HDU 5874 Friends and Enemies 【构造】 (2016 ACM/ICPC Asia Regional Dalian Online)
- 2016 ICPC 大连网络赛 HDU 5874 Friends and Enemies
- HDU 5874 2016 ACM/ICPC Asia Regional Dalian Online 1007 Friends and Enemies
- Friends and Enemies HDU - 5874
- HDU 5874 Friends and Enemies (二分图 读不懂题系列)
- HDU 5874 Friends and Enemies
- hdu 5874 Friends and Enemies【二分图,构造】
- hdu 5874 Friends and Enemies -ICPC网络赛大连-二分图
- hdu 5874 Friends and Enemies【题意不明系列+二分图】
- 【2016-大连赛区网络赛-G】(Friends and Enemies,hdu 5874)
- HDU-5874-Friends and Enemies
- hdu_5874_Friends and Enemies(公式题)