HDU 5874 Friends and Enemies 【构造】 (2016 ACM/ICPC Asia Regional Dalian Online)

67 篇文章 0 订阅
63 篇文章 0 订阅

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的大小即可。




//
//by coolxxx
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define mem(a,b) memset(a,b,sizeof(a))
#define eps (1e-10)
#define J 10000
#define mod 1000000007
#define MAX 0x7f7f7f7f
#define PI 3.14159265358979323
#pragma comment(linker,"/STACK:1024000000,1024000000")
#define N 200004
#define M 20004
using namespace std;
typedef long long LL;
double anss;
LL aans;
int cas,cass;
int n,m,lll,ans;
int main()
{
	#ifndef ONLINE_JUDGE
//	freopen("1.txt","r",stdin);
//	freopen("2.txt","w",stdout);
	#endif
	int i,j,k;
	int x,y,z;
//	init();
//	for(scanf("%d",&cass);cass;cass--)
//	for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
//	while(~scanf("%s",s))
	while(~scanf("%d",&n))
	{
		scanf("%d",&m);
		if(1LL*n/2*(n-n/2)<=m)puts("T");
		else puts("F");
	}
	return 0;
}
/*
//

//
*/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值