大连网络赛--Friends and Enemies--二分图推导

Friends and Enemies

Time 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:
  
  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)

 

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

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值