当前位置:   article > 正文

HDU 5874-Friends and Enemies(n个结点的无三元环的图的最大边数)_没有3环的图最多边数

没有3环的图最多边数

Friends and Enemies

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


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   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
 

Recommend
wange2014   |   We have carefully selected several similar problems for you:   5877  5876  5875  5874  5872 
 

题目意思:

nnn个人, mmm种颜色的石头, 人两两之间要么是朋友, 要么是敌人. 每个人可以携带若干种石头或者不带, 要求朋友之间至少携带一种颜色相同的石头, 敌人之间不能携带有相同颜色的石头. 问最坏情况下, mmm种颜色是否够.

解题思路:

n个点的图, 要求有尽量多的边, 并且不存在三元环. 这个边数就是mmm的下界.

对于一个nnn个结点的没有三元环的图, 边数最大的就是完全二分图. 于是答案就是⌊n2⌋⋅⌈n2⌉\lfloor \frac{n}{2} \rfloor \cdot \lceil\frac{n}{2} \rceil2n2n.

  1. #include <iostream>
  2. #include <cstring>
  3. #include <string>
  4. #include <vector>
  5. #include <queue>
  6. #include <cstdio>
  7. #include <set>
  8. #include <cmath>
  9. #include <map>
  10. #include <algorithm>
  11. #define INF 0x3f3f3f3f
  12. #define MAXN 20010
  13. using namespace std;
  14. int main()
  15. {
  16. long long m,n;
  17. while(scanf("%I64d%I64d",&m,&n)!=EOF)
  18. {
  19. long long ans=floor(m/2.0)*ceil(m/2.0);
  20. //cout<<ans<<endl;
  21. if(n>=ans) puts("T");
  22. else puts("F");
  23. }
  24. return 0;
  25. }
  26. /**
  27. 20 100
  28. **/



声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/64617
推荐阅读
相关标签
  

闽ICP备14008679号