HDU 5874 Friends and Enemies
2016-09-11 21:54
459 查看
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
找了很久的规律,终于确定,只有当n个人分成两个集合x和yx中的人互相敌对,y中的人互相敌对,并且x和y中的人互相友好时需要的颜色为x*y,而x+y=n,所以颜色要大于等于n/2*(n-n/2)才行。#include<set>
#include<map>
#include<ctime>
#include<cmath>
#include<stack>
#include<queue>
#include<bitset>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#define rep(i,j,k) for (int i = j; i <= k; i++)
#define per(i,j,k) for (int i = j; i >= k; i--)
#define loop(i,j,k) for (int i = j;i != -1; i = k[i])
#define lson x << 1, l, mid
#define rson x << 1 | 1, mid + 1, r
#define ff first
#define ss second
#define mp(i,j) make_pair(i,j)
#define pb push_back
#define pii pair<int,LL>
#define in(x) scanf("%d", &x);
using namespace std;
typedef long long LL;
const int low(int x) { return x&-x; }
const double eps = 1e-4;
const int INF = 0x7FFFFFFF;
const int mod = 998244353;
const int N = 1e5 + 10;
int n, m;
int main()
{
while (scanf("%d%d", &n, &m) != EOF)
{
printf("%s\n", 1LL * n * n / 4 <= m ? "T" : "F");
}
return 0;
}
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
找了很久的规律,终于确定,只有当n个人分成两个集合x和yx中的人互相敌对,y中的人互相敌对,并且x和y中的人互相友好时需要的颜色为x*y,而x+y=n,所以颜色要大于等于n/2*(n-n/2)才行。#include<set>
#include<map>
#include<ctime>
#include<cmath>
#include<stack>
#include<queue>
#include<bitset>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#define rep(i,j,k) for (int i = j; i <= k; i++)
#define per(i,j,k) for (int i = j; i >= k; i--)
#define loop(i,j,k) for (int i = j;i != -1; i = k[i])
#define lson x << 1, l, mid
#define rson x << 1 | 1, mid + 1, r
#define ff first
#define ss second
#define mp(i,j) make_pair(i,j)
#define pb push_back
#define pii pair<int,LL>
#define in(x) scanf("%d", &x);
using namespace std;
typedef long long LL;
const int low(int x) { return x&-x; }
const double eps = 1e-4;
const int INF = 0x7FFFFFFF;
const int mod = 998244353;
const int N = 1e5 + 10;
int n, m;
int main()
{
while (scanf("%d%d", &n, &m) != EOF)
{
printf("%s\n", 1LL * n * n / 4 <= m ? "T" : "F");
}
return 0;
}
相关文章推荐
- hdu_5874_Friends and Enemies(公式题)
- hdu 5874 Friends and Enemies(思维)
- HDU 5874 Friends and Enemies
- HDU 5874 Friends and Enemies 大连网络赛
- HDU 5874 Friends and Enemies
- HDU 5874 Friends and Enemies(二分图思想)——2016 ACM/ICPC Asia Regional Dalian Online
- HDU 5874 2016 ACM/ICPC Asia Regional Dalian Online 1007 Friends and Enemies
- hdu 5874 Friends and Enemies【题意不明系列+二分图】
- 【2016-大连赛区网络赛-G】(Friends and Enemies,hdu 5874)
- HDU 5874-Friends and Enemies(n个结点的无三元环的图的最大边数)
- HDU 5874 Friends and Enemies
- HDU-5874-Friends and Enemies-构造+找规律
- HDU-5874-Friends and Enemies
- HDU 5874 Friends and Enemies (二分图 读不懂题系列)
- HDU 5874 Friends and Enemies 【构造】 (2016 ACM/ICPC Asia Regional Dalian Online)
- hdu 5874 Friends and Enemies -ICPC网络赛大连-二分图
- 2016 ICPC 大连网络赛 HDU 5874 Friends and Enemies
- hdu 5874 Friends and Enemies
- Friends and Enemies HDU - 5874
- HDU 5874 Friends and Enemies(构造)