Friends and Enemies

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

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
 
Recommend
wange2014   |   We have carefully selected several similar problems for you:  5877 5875 5873 5872 5871 
 

Statistic | Submit | Discuss | Note

题目链接:

  http://acm.hdu.edu.cn/showproblem.php?pid=5874

题目大意:

  M个人,N种颜色的石头(M,N<231),两个人之间不是朋友就是敌人,每个人都有一个石头项链,项链上可以串多种颜色的石头,朋友至少有一种相同颜色,敌人不能有相同颜色。求是否能够满足。

题目思路:

  【构造】

  这道题还剩18s的时候过了太惊险。。

  首先,M个人,是朋友的连一条边代表有一种相同颜色。那么就有了一张图。

  现在考虑,X和Y,Z是朋友,Y和Z也是朋友,那么图上就形成了一个三角形XYZ,有三条边代表需要三种颜色的石头,但其实XYZ都互为朋友只需要一种颜色的石头就可以满足。

  而如果X与Y,Z是朋友,Y和Z是敌人,那么就需要两种颜色,(Y Z 不同色)。所以有三角形的情况不是最坏情况。而我们要考虑的是最坏情况。

  所以最终最坏情况的图是没有三角形的,即为一张完全二分图。左边集合X里的人互为敌人,右边集合Y里的人互为敌人(无三角形),X里每个点到Y的每个点都有连边

  总边数为X*Y,表示需要的石头颜色种数,又有X+Y=M,所以X=M/2,Y=M-M/2时,X*Y最大,为最坏情况,只需比较X*Y和N的大小即可。

  1. //
  2. //by coolxxx
  3. //#include<bits/stdc++.h>
  4. #include<iostream>
  5. #include<algorithm>
  6. #include<string>
  7. #include<iomanip>
  8. #include<map>
  9. #include<stack>
  10. #include<queue>
  11. #include<set>
  12. #include<bitset>
  13. #include<memory.h>
  14. #include<time.h>
  15. #include<stdio.h>
  16. #include<stdlib.h>
  17. #include<string.h>
  18. //#include<stdbool.h>
  19. #include<math.h>
  20. #define min(a,b) ((a)<(b)?(a):(b))
  21. #define max(a,b) ((a)>(b)?(a):(b))
  22. #define abs(a) ((a)>0?(a):(-(a)))
  23. #define lowbit(a) (a&(-a))
  24. #define sqr(a) ((a)*(a))
  25. #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
  26. #define mem(a,b) memset(a,b,sizeof(a))
  27. #define eps (1e-10)
  28. #define J 10000
  29. #define mod 1000000007
  30. #define MAX 0x7f7f7f7f
  31. #define PI 3.14159265358979323
  32. #pragma comment(linker,"/STACK:1024000000,1024000000")
  33. #define N 200004
  34. #define M 20004
  35. using namespace std;
  36. typedef long long LL;
  37. double anss;
  38. LL aans;
  39. int cas,cass;
  40. int n,m,lll,ans;
  41. int main()
  42. {
  43. #ifndef ONLINE_JUDGE
  44. // freopen("1.txt","r",stdin);
  45. // freopen("2.txt","w",stdout);
  46. #endif
  47. int i,j,k;
  48. int x,y,z;
  49. // init();
  50. // for(scanf("%d",&cass);cass;cass--)
  51. // for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
  52. // while(~scanf("%s",s))
  53. while(~scanf("%d",&n))
  54. {
  55. scanf("%d",&m);
  56. if(1LL*n/*(n-n/)<=m)puts("T");
  57. else puts("F");
  58. }
  59. return ;
  60. }
  61. /*
  62. //
  63.  
  64. //
  65. */

HDU 5874 Friends and Enemies 【构造】 (2016 ACM/ICPC Asia Regional Dalian Online)的更多相关文章

  1. HDU 5875 Function 【倍增】 (2016 ACM/ICPC Asia Regional Dalian Online)

    Function Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  2. HDU 5876 Sparse Graph 【补图最短路 BFS】(2016 ACM/ICPC Asia Regional Dalian Online)

    Sparse Graph Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)To ...

  3. HDU 5873 Football Games 【模拟】 (2016 ACM/ICPC Asia Regional Dalian Online)

    Football Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  4. 2016 ACM/ICPC Asia Regional Dalian Online 1002/HDU 5869

    Different GCD Subarray Query Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K ( ...

  5. 2016 ACM/ICPC Asia Regional Dalian Online 1006 /HDU 5873

    Football Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  6. hdu 5868 2016 ACM/ICPC Asia Regional Dalian Online 1001 (burnside引理 polya定理)

    Different Circle Permutation Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K ...

  7. hdu 5878 I Count Two Three (2016 ACM/ICPC Asia Regional Qingdao Online 1001)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5878 题目大意: 给出一个数n ,求一个数X, X>=n. X 满足一个条件 X= 2^a*3^ ...

  8. hdu 5877 线段树(2016 ACM/ICPC Asia Regional Dalian Online)

    Weak Pair Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  9. 2016 ACM/ICPC Asia Regional Dalian Online HDU 5877 Weak Pair treap + dfs序

    Weak Pair Problem Description   You are given a rooted tree of N nodes, labeled from 1 to N. To the  ...

随机推荐

  1. 程序使用嵌套的for循环找出2〜100中的素数

    #import <Foundation/Foundation.h> int main () { /* local variable definition */ int i, j; ; i& ...

  2. DateTime.ToString()

       /*            [y]代表年份,注意是小写的y,大写的Y并不代表年份.            [M]表示月份.            [d]表示日期,注意D并不代表什么.       ...

  3. DB天气app冲刺二阶段第三天

    今天发现自己不能乖乖的按照计划来进行项目了.弄着这个然后不知不觉就弄到那边去了,结果就是哪边都弄不好,但又很纠结.还是要给自己一个计划白班才行,每次只是计划这一两天的根本不行.明天要指定一个计划白板, ...

  4. 【高斯消元】BZOJ 1013: [JSOI2008]球形空间产生器sphere

    Description 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困在了这个n维球体中,你只知道球面上n+1个点的坐标,你需要以最快的速度确定这个n维球体的球心坐标,以便于摧毁 ...

  5. [笨木头FireFly 02]入门篇2_客户端发送请求,服务器处理请求

    原地址:http://www.9miao.com/question-15-53940.html 好,经过上一篇不权威的讲解,大家已经能轻易地让客户端和服务端连接起来了. 但是,仅仅是连接了,可它们俩不 ...

  6. POJ 2318 TOYS && POJ 2398 Toy Storage(几何)

    2318 TOYS 2398 Toy Storage 题意 : 给你n块板的坐标,m个玩具的具体坐标,2318中板是有序的,而2398无序需要自己排序,2318要求输出的是每个区间内的玩具数,而231 ...

  7. URAL 1353 Milliard Vasya's Function(DP)

    题目链接 题意 : 让你找出1到10^9中和为s的数有多少个. 思路 : 自己没想出来,看的题解,学长的题解报告 题解报告 //URAL 1353 #include <iostream> ...

  8. linux 使用kill命令杀死进程的几个办法

    常规篇: 首先,用ps查看进程,方法如下: $ ps -ef ……smx       1822     1  0 11:38 ?        00:00:49 gnome-terminalsmx   ...

  9. 使用头文件climits中的符号常量获知整型数据的表数范围---gyy整理

    在头文件climits(limits.h)以宏定义的方式定义了各种符号常量来表示各种整型类型表示数的范围,如int的最大最小值,long的最大最小值等. 符号常量 表示 CHAR_BIT char 的 ...

  10. IOS开发基础

    http://blog.csdn.net/wokenshin/article/details/50292253 1.修改UI大小 2.设置颜色 3.禁止横屏 4.点击空白处隐藏键盘 5.弹出键盘时,后 ...