hdu 5874 Friends and Enemies -ICPC网络赛大连-二分图
来源:互联网 发布:python sys.exit 1 编辑:程序博客网 时间:2024/05/16 11:15
Friends and Enemies
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
题意
有M个人N种颜色的石头 M个人中每两个人 不是朋友就是敌人 ,现在他们每个人要用石头要串一条项链 要求是
1.朋友之间的项链至少有一个相同颜色的石头
2.敌人之间没有颜色相同的石头
3.项链可以是空的
问N种颜色的石头能不能满足这M个人
解题思路
二分图,把所有人分为两部分A,B,每一部分之间都是敌人,与对面都是朋友
假设A组里有x个人,那么B组有m-x个人,每一组里的人不能一样所以石头必须有x种颜色才能满足A组
然后 对与B组的每一个人,都要与A组的人有一块相同色的石头,这个人至少有x个颜色,B组有m-x个人,所以,一共颜色是x*(m-x)
所以最坏的情况是使x*(m-x)最大,根据高中数学知识求个导,发现当x=m/2时候是最大的,所以石头颜色数量应该满足n>=m*m/4
代码
#include<cstdio>#include<iostream>#include<deque>using namespace std;int main(){ int n,m; while(scanf("%d%d",&m,&n)!=EOF) { if(n>=m*m/4) printf("T\n"); else printf("F\n"); } return 0;}
1 0
- hdu 5874 Friends and Enemies -ICPC网络赛大连-二分图
- 2016 ICPC 大连网络赛 HDU 5874 Friends and Enemies
- 2016 大连网络赛 HDU 5874 Friends and Enemies【思维】
- HDU 5874 Friends and Enemies 大连网络赛
- 2016ACM-ICPC大连网络预选赛1007 Friends and Enemies
- 【2016-大连赛区网络赛-G】(Friends and Enemies,hdu 5874)
- 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
- 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 2016大连网赛
- HDU 5874 Friends and Enemies【思维】
- Spring2.Ioc容器
- Leetcode 336 回文对
- Android开机动画流程
- iOS 视频播放(一~二)客户端小应用、边下边播
- OK-HTTP封装(okhttp版本号:3.4.1)
- hdu 5874 Friends and Enemies -ICPC网络赛大连-二分图
- JAVA中获取项目文件路径
- Android之SimpleAdapter简单实例和SimpleAdapter参数说明
- OpenGL顶点缓冲区一步步分析
- 第七章 动态内存管理
- SH整合异常:SessionFactoryImplementor.getProperties()Ljava/util/Map
- 自定义对象中文排序,可以指定排序的字段名,较为通用
- 深度网络之梯度下降算法
- 基于Eclipse Maven的Spring4/Spring-MVC/Hibernate4整合之十:Spring mvc & hibernate 事务处理(回滚)