HDU 5874-Friends and Enemies(n个结点的无三元环的图的最大边数)
来源:互联网 发布:in Linux system 编辑:程序博客网 时间:2024/05/22 10:58
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.
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 integersM,N (M,N<231) representing the total number of dwarves (not including the king) and the number of colors of stones on the island.
For each test case, the one and only line contains 2 positive integers
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
Recommend
wange2014 | We have carefully selected several similar problems for you: 5877 5876 5875 5874 5872
题目意思:
有n
个人, m
种颜色的石头, 人两两之间要么是朋友, 要么是敌人. 每个人可以携带若干种石头或者不带, 要求朋友之间至少携带一种颜色相同的石头, 敌人之间不能携带有相同颜色的石头. 问最坏情况下, m
种颜色是否够.
解题思路:
n
个点的图, 要求有尽量多的边, 并且不存在三元环. 这个边数就是m
的下界.
对于一个n
个结点的没有三元环的图, 边数最大的就是完全二分图. 于是答案就是⌊2n⌋⋅⌈2n⌉
.
#include <iostream>#include <cstring>#include <string>#include <vector>#include <queue>#include <cstdio>#include <set>#include <cmath>#include <map>#include <algorithm>#define INF 0x3f3f3f3f#define MAXN 20010using namespace std;int main(){ long long m,n; while(scanf("%I64d%I64d",&m,&n)!=EOF) { long long ans=floor(m/2.0)*ceil(m/2.0); //cout<<ans<<endl; if(n>=ans) puts("T"); else puts("F"); } return 0;}/**20 100**/
0 0
- HDU 5874-Friends and Enemies(n个结点的无三元环的图的最大边数)
- HDU 5874 Friends and Enemies(构造)
- hdu 5874 Friends and Enemies(思维)
- HDU 5874 Friends and Enemies
- hdu 5874 Friends and Enemies
- HDU 5874 Friends and Enemies
- HDU-5874-Friends and Enemies
- hdu 5874 Friends and Enemies
- Friends and Enemies HDU
- hdu 5874 Friends and Enemies【题意不明系列+二分图】
- hdu 5874 Friends and Enemies【二分图,构造】
- HDU 5874 Friends and Enemies【思维】
- N个结点的连通图的边数问题
- HDU 5874 Friends and Enemies (二分图 读不懂题系列)
- n个点的简单无向图没有长度为3的环,求其最大的边数
- 2016 大连网络赛 HDU 5874 Friends and Enemies【思维】
- HDU-5874-Friends and Enemies-构造+找规律
- 2016 ICPC 大连网络赛 HDU 5874 Friends and Enemies
- 欢迎使用CSDN-markdown编辑器
- 今日头条新闻采集爬虫分享
- 189 - rotate array
- 13章上机练习
- C++ STL <vector>
- HDU 5874-Friends and Enemies(n个结点的无三元环的图的最大边数)
- MapReducer工作流程小结
- 51Nod - Nim游戏(博弈)
- Java大牛养成记(11)----Struts 2 & Struts 1
- 实现顺序栈各种基本运算算法
- JavaScript中的window.parent ,window.top,window.self 等等
- 删除字符串中相邻三个或以上重复的字符
- Java 第12章典型例子
- vi笔记3——vi之快速移动