Friends and EnemiesTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1752 Accepted Submission(s): 766 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:
Input Multiple test cases, process till end of the input. |
给出N个人,M个颜色,每个人可以带或不带颜色,若干个,人与人之间两两是朋友或敌人。问颜色数是否够用。
最坏的情况应该是分成两部分人,A B。A内和B内全是敌人,A B之间都是朋友的关系。
假设A有X人,B有M-X个人,那么A内至少X种颜色,因为他们的颜色需要完全不同。
考虑B,B和A都是朋友,A有X种颜色,那么B中的每一个人也至少要X种颜色,朋友之间至少一个颜色同,那么B一共X*(M-X)。求导,X=M/2时这个式子取得最大值,为M*M/4。
#include <algorithm> //STL通用算法
#include <bitset> //STL位集容器
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex> //复数类
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque> //STL双端队列容器
#include <exception> //异常处理类
#include <fstream>
#include <functional> //STL定义运算函数(代替运算符)
#include <limits>
#include <list> //STL线性列表容器
#include <map> //STL 映射容器
#include <iomanip>
#include <ios> //基本输入/输出支持
#include<iosfwd> //输入/输出系统使用的前置声明
#include <iostream>
#include <istream> //基本输入流
#include <ostream> //基本输出流
#include <queue> //STL队列容器
#include <set> //STL 集合容器
#include <sstream> //基于字符串的流
#include <stack> //STL堆栈容器
#include <stdexcept> //标准异常类
#include <streambuf> //底层输入/输出支持
#include <string> //字符串类
#include <utility> //STL通用模板类
#include <vector> //STL动态数组容器
#include <cwchar>
#include <cwctype>
#define ll long long
using namespace std;
priority_queue<int,vector<int>,less<int> >q;
int dx[]= {-1,1,0,0,-1,-1,1,1};
int dy[]= {0,0,-1,1,-1,1,1,-1};
const int maxn = 100000+66;
const ll mod=10007;
int n,k,m;
int a[maxn];
int main()
{
while(scanf("%d %d",&m,&n)!=EOF)
{
if(n>=m*m/4)printf("T\n");
else printf("F\n");
}
return 0;
}