HDU 5874-Friends and Enemies(n個結點的無三元環的圖的最大邊數)

來源:互聯網
上載者: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 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 2016 ACM/ICPC Asia Regional Dalian Online  
Recommend wange2014   |   We have carefully selected several similar problems for you:   5877  5876  5875  5874  5872   

題目意思:

有nnn個人, mmm種顏色的石頭, 人兩兩之間要麼是朋友, 要麼是敵人. 每個人可以攜帶若干種石頭或者不帶, 要求朋友之間至少攜帶一種顏色相同的石頭, 敵人之間不能攜帶有相同顏色的石頭. 問最壞情況下, mmm種顏色是否夠.
解題思路:

n個點的圖, 要求有盡量多的邊, 並且不存在三元環. 這個邊數就是mmm的下界.

對於一個nnn個結點的沒有三元環的圖, 邊數最大的就是完全二分圖. 於是答案就是⌊n2⌋⋅⌈n2⌉\lfloor \frac{n}{2} \rfloor \cdot \lceil\frac{n}{2} \rceil⌊2n⌋⋅⌈2n⌉.

#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 20010using 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;}/**20 100**/



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.