HDU 5874 Friends and Enemies 2016大连网赛

在一个孤岛上,国王要求每个矮人都要根据彼此之间的友谊或敌对关系来佩戴宝石项链。若两人是朋友,则他们的宝石项链至少有一个相同颜色;若为敌人,则项链上的宝石颜色完全不同。任务是判断在给定的人口数量和宝石颜色种类下,是否可以完成国王的要求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Friends and Enemies
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 810    Accepted Submission(s): 425


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 

题意就是每人有一串项链 2个人 不是敌人就是朋友
a和b是敌人 a项链里的所有颜色的石头 b都没有
a和b是朋友 a的项链中 至少有一颗石头和b的某石头同色
且a b项链都为空时 她们是敌人

当m=2时 显然 互为朋友是最坏情况 需要1种
m=3时 考虑a和b和c互为朋友 不难发现 这其实只需要1种
当a和b,c是朋友 b,c是敌人 需要2种
如果a,b是朋友 就连接a,b 如果a,b之间没边 则a,b是敌人
当有环出现时 这个环只需要一种公共颜色 所以只要让图尽量没环就能达到最坏情况
而这种情况就是二分图(U,V,E)
且对任意u属于U v属于V 都存在(u,v)属于E 边的条数就是颜色的总数
所以最坏情况就是|U|*|V|种

#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<time.h>
#include<math.h>
#include<list>
#include<cstring>
#include<fstream>
//#include<memory.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define INF 1000000007
#define pll pair<ll,ll>
#define pid pair<int,double>

int main()
{
    //freopen("/home/lu/文档/r.txt","r",stdin);
    //freopen("/home/lu/文档/w.txt","w",stdout);
    int m,n;
    while (~scanf("%d%d",&m,&n)) {
        int a=m/2,
                b=m-a;
        printf("%c\n",((ll)a*(ll)b>n)?'F':'T');
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值