2016 ICPC 大连网络赛 HDU 5874 Friends and Enemies

Friends and Enemies

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 457    Accepted Submission(s): 253


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
 

【题意】有m个人,n种石头,将n种石头分给m个人,每两个人之间要么是朋友关系,要么是敌人关系,朋友的话他们必须有一种相同颜色的石头,敌人的话他们必须所有石头的颜色都不相同。另外,一个人可以不拥有任何一种石头。求m个人的所有关系是不是都能用n种石头表示出来。

【分析】我们考虑这样的一种情况,我们把人分为左边和右边两部分,每边的人里面都互相为敌人,同时左边的任意一个人和右边的任意一个人都是朋友。举个例子,左边有3人,右边两人。考虑左边第一人,他和右边每一个人都要有相同的至少一种石头,那么他至少要有两种石头,而左边的每一个人的每一个石头都不能一样,那么至少要有3*2=6种石头。通过这个例子我们就可以找出规律来了,总共需要的石头量为左右人数之积。那么问题就转化成了,将m个人分成两组,使得乘积最大(这是m个人下的最坏的情况,如果这个情况都能满足,那么其他情况也都能满足了)。显然,将m个人均分一下得到的乘积最大,那么答案就出来了。

AC代码

//
//Created by just_sort 2016/9/12 09:48
//Copyright (c) 2016 just_sort.All Rights Reserved
//

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
int n,m;
int main()
{
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        int a=n/2,b=n-n/2;
        if(1LL*a*b>m) printf("F\n");
        else printf("T\n");
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值