2016 ACM/ICPC Asia Regional Dalian Online 1007

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');
    }
}
基于python实现的粒子群的VRP(车辆配送路径规划)问题建模求解+源码+项目文档+算法解析,适合毕业设计、课程设计、项目开发。项目源码已经过严格测试,可以放心参考并在此基础上延申使用,详情见md文档 算法设计的关键在于如何向表现较好的个体学习,标准粒子群算法引入惯性因子w、自我认知因子c1、社会认知因子c2分别作为自身、当代最优解和历史最优解的权重,指导粒子速度和位置的更新,这在求解函数极值问题时比较容易实现,而在VRP问题上,速度位置的更新则难以直接采用加权的方式进行,一个常见的方法是采用基于遗传算法交叉算子的混合型粒子群算法进行求解,这里采用顺序交叉算子,对惯性因子w、自我认知因子c1、社会认知因子c2则以w/(w+c1+c2),c1/(w+c1+c2),c2/(w+c1+c2)的概率接受粒子本身、当前最优解、全局最优解交叉的父代之一(即按概率选择其中一个作为父代,不加权)。 算法设计的关键在于如何向表现较好的个体学习,标准粒子群算法引入惯性因子w、自我认知因子c1、社会认知因子c2分别作为自身、当代最优解和历史最优解的权重,指导粒子速度和位置的更新,这在求解函数极值问题时比较容易实现,而在VRP问题上,速度位置的更新则难以直接采用加权的方式进行,一个常见的方法是采用基于遗传算法交叉算子的混合型粒子群算法进行求解,这里采用顺序交叉算子,对惯性因子w、自我认知因子c1、社会认知因子c2则以w/(w+c1+c2),c1/(w+c1+c2),c2/(w+c1+c2)的概率接受粒子本身、当前最优解、全局最优解交叉的父代之一(即按概率选择其中一个作为父代,不加权)。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值