[原创]HDU 5874 Friends and Enemies【思维】

2016-09-10 19:53:11 Tabris_ 阅读数:1446


博客爬取于2020-06-14 22:43:26
以下为正文

版权声明:本文为Tabris原创文章,未经博主允许不得私自转载。
https://blog.csdn.net/qq_33184171/article/details/52496677


题目连接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5874
---------------------------------------.

Friends and Enemies

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 26 Accepted Submission(s): 14

Problem Description
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) 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

Source
2016 ACM/ICPC Asia Regional Dalian Online

-------------------------------------------------------------.

题目大意:
就是有M个人N种颜色的石头 M个人中每两个人 不是朋友就是敌人
现在他们每个人要用石头要串一条项链 要求是
1.朋友之间的项链至少有一个相同颜色的石头
2.敌人之间没有颜色相同的石头
3.项链可以使空的 就是不串石头
问N种颜色的石头能不能满足这M个人

解题思路:
比赛的时候队友说是二分图 然后让我毫不犹豫的给否定了 然后就GG了..   谁能告诉我这是一种什么样的体验.. 网络赛再次坑了队友一波..  O(T_T)O

看题吧  问能不能满足 肯定是要和最坏的情况比较  也就是求最坏的情况下需要多少种颜色的石子

根据两个人的关系只有朋友和敌人这点 就可以相像成一个二分图了 分别在两侧的人是朋友 (比赛的时候居然想成了同侧的是朋友 就这样吧队友坑了)  这样的话 就是求一个完全二分图的边数有多少就行了   
因为M个人 想要边数最多 所以尽量均分 左右两边个一般就行了

这样的话 边数就是m/2*(m-m/2);
之后跟N比一下就好了 。。
这么水的题目 。。。
我。、

附本题代码
-------------------------------。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# include <bits/stdc++.h>
using namespace std;

int main()
{
LL m,n;
while(~scanf("%I64d %I64d",&m,&n))
{
LL ans = m/2*(m-m/2);

if( ans <= n) puts("T");
else puts("F");
}
return 0;
}