HDU 5874-friends and enemies (maximum number of sides of a graph with no ternary rings for n nodes)

Source: Internet
Author: User

Friends and Enemies Time limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 292 Accepted Submission (s): 161


Problem Description on a isolated island, lived some dwarves. A King (not a dwarf) ruled the island and the seas nearby, there is abundant cobblestones of varying colors on the island . Every dwarves on the island is either friends or enemies. One day, the king demanded this dwarf on the island (not including the king himself, of course) wear a stone necklace According to the following rules:

For any of the dwarves, if they is friends, at least one of the stones from each of the their necklaces is of the same color; And if they is enemies, any of the stones from each of the their necklaces should be of different colors. Note that a necklace can is empty.

Now, given the population and the number of colors of stones on the island, you is going to judge if it's possible for EA Ch 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's possible to Fini SH The king ' s assignment. Output ' T ' (without quotes) if possible, ' F ' (without quotes) otherwise.
Sample Input
20 100
Sample Output
T
Source ACM/ICPC Asia Regional Dalian Online
Recommend wange2014 | We have carefully selected several similar problems for you:5877 5876 5875 5874 5872

topic Meaning:

There are nnn individuals, mmm-colored stones, 22 of whom are either friends or enemies. Each person can carry a number of stones or without, asking friends to carry at least one color of the same stone, the enemy can not carry the same color stone. Ask the worst case, the MMM color is enough.
Problem Solving Ideas:

The graph of n points requires as many edges as possible, and there is no ternary ring. This edge number is the lower bound of MMM.

For a graph with no ternary rings for a nnn node, the largest number of edges is a complete dichotomy. So the answer is ⌊n2⌋⋅⌈n2⌉\lfloor \frac{n}{2} \rfloor \cdot \lceil\frac{n}{2} \rceil⌊2 n⌋⋅⌈2 N⌉.

#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cstdio>
#include <set>
#include <cmath>
# Include <map>
#include <algorithm>
#define INF 0x3f3f3f3f
#define MAXN 20010
using namespace Std;
int main ()
{
    long long m,n;
    while (scanf ("%i64d%i64d", &m,&n)!=eof)
    {
        long long Ans=floor (m/2.0) *ceil (m/2.0);
        cout<<ans<<endl;
        if (N>=ans) puts ("T");
        Else puts ("F");
    }
    return 0;
}
/**
**/



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.