2016 ACM/ICPC Asia Regional Dalian Online 1007

探讨在一个岛屿上,如何根据特定规则为每位矮人准备一条项链,使得朋友间的项链至少有一种相同颜色的宝石,敌人间的项链颜色全不相同。通过数学方法证明了可行性的判断条件。

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

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


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

答案为  floor(N/2)*ceil(N/2)<=M

因为边之间独特关系难以表示,故引入素因子区分各边,可能某种程度上使描述复杂,见谅

共N个结点构成集合V,每个结点存在值,任意两结点间存在一条边,边有两种颜色:红(朋友)、黑(敌对),其中红边有权值i为两结点某个共有素因子
任取结点p,p以红边能到底的结点组成集合S,以黑边能到底的结点组成集合T

假设集合S中任意两结点之间边为黑色,集合T中任意两结点之间边为黑色,此时S、T、{p}集合意义上等价
对于任意的 s属于S,t属于T,边(s,t)都是红色,此时跨越集合S,T的每条边权值都是独特
那么此时跨越集合S,T的红色边共有|S||T|
同样,对于{p},每个s属于S 都有一条权值独特的红色边到点p,那么跨越集合S,{p}共有|S|条边
此时,全图图共有 |S|(|T|+1) 条权值独特的红色边

证明 对于集合S,T,{p}集合内和集合间,满足约束下不论边为任意色,全图最多有 |S|(|T|+1) 条权值独特的红色边
反证
1.如果存在边(s,t)为黑色,易知跨越集合S,T的权值独特的红色边数减少
2.若存在 u!=v属于S,有(u,v)为红色,那么对于所有的(u,t)的权值都可修改为(v,t)的权值
  此时跨越集合S,T的权值独特的红色边数减少
3.因为S、T集合意义上等价,故u!=v属于T,跨越集合S,T的权值独特的红色边数同减少

综上,|S|(|T|+1) 为最大值y,而 |T|=|V|-|S|-|{p}|,|V|=N,设x=|S|
故 y=x(N-x),显然该函数最大值为 floor(N/2)*ceil(N/2)

注 :  floor(N/2)*ceil(N/2) == floor((N^2)/4)

typedef long long LL;
int main()
{
//    freopen("F:\\test.txt","r",stdin);
//    freopen("F:\\tsst.txt","w",stdout);
    LL N,M;
    while(~scanf("%lld %lld",&N,&M))
    {
        LL A = N/2;
        LL B = A*2==N?A:A+1;
        LL Ans = A*B;
        printf("%c\n",Ans<=M?'T':'F');
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值