zoukankan      html  css  js  c++  java
  • HDU5874

    Friends and Enemies

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


    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
     

    Source

     
    最后竟成了找规律。。
    1 0
    2 1
    3 2
    4 4
    5 6
    6 9
    7 12
    8 16
    9 20
    10 25
    11 30
    12 36
    13 42
    ......
     1 //2016.9.10
     2 #include <iostream>
     3 #include <cstdio>
     4 
     5 using namespace std;
     6 
     7 long long fun(int m)
     8 {
     9     long long ans;
    10     ans = (m/2)*(m/2);
    11     if(m%2)ans += (m/2);
    12     return ans;
    13 }
    14 
    15 int main()
    16 {
    17     long long n, m, res;
    18     while(scanf("%lld%lld", &m, &n)!=EOF)
    19     {
    20         res = fun(m);
    21         if(n>=res)
    22           printf("T
    ");
    23         else printf("F
    ");
    24     }
    25 
    26     return 0;
    27 }
  • 相关阅读:
    转 new和malloc的区别
    转 内联函数
    转 C++宏定义详解
    转 内联函数和宏定义的区别
    转 C++中不能声明为虚函数的有哪些函数
    转 PV操作简单理解
    转 Python执行系统命令的方法
    转 常量指针和指针常量的区别详解
    转 python语法学习面向对象之继承
    Singleton、MultiThread、Lib——实现单实例无锁多线程安全API
  • 原文地址:https://www.cnblogs.com/Penn000/p/5861017.html
Copyright © 2011-2022 走看看