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