题目描述

In a far away kingdom lives a very greedy king. To defend his land, he built n n n guard towers. Apart from the towers the kingdom has two armies, each headed by a tyrannical and narcissistic general. The generals can't stand each other, specifically, they will never let soldiers of two armies be present in one tower.

During defence operations to manage a guard tower a general has to send part of his army to that tower. Each general asks some fee from the king for managing towers. As they live in a really far away kingdom, each general evaluates his fee in the following weird manner: he finds two remotest (the most distant) towers, where the soldiers of his army are situated and asks for the fee equal to the distance. Each tower is represented by a point on the plane with coordinates (x,y) (x,y) (x,y) , and the distance between two points with coordinates (x1,y1) (x_{1},y_{1}) (x1​,y1​) and (x2,y2) (x_{2},y_{2}) (x2​,y2​) is determined in this kingdom as ∣x1−x2∣+∣y1−y2∣ |x_{1}-x_{2}|+|y_{1}-y_{2}| ∣x1​−x2​∣+∣y1​−y2​∣ .

The greedy king was not exactly satisfied with such a requirement from the generals, that's why he only agreed to pay one fee for two generals, equal to the maximum of two demanded fees. However, the king is still green with greed, and among all the ways to arrange towers between armies, he wants to find the cheapest one. Each tower should be occupied by soldiers of exactly one army.

He hired you for that. You should find the minimum amount of money that will be enough to pay the fees. And as the king is also very scrupulous, you should also count the number of arrangements that will cost the same amount of money. As their number can be quite large, it is enough for the king to know it as a remainder from dividing by 109+7 10^{9}+7 109+7 .

Two arrangements are distinct if the sets of towers occupied by soldiers of the first general are distinct.

输入输出格式

输入格式:

The first line contains an integer n n n ( 2<=n<=5000 2<=n<=5000 2<=n<=5000 ), n n n is the number of guard towers. Then follow n n n lines, each of which contains two integers x,y x,y x,y — the coordinates of the i i i -th tower (0<=x,y<=5000) (0<=x,y<=5000) (0<=x,y<=5000) . No two towers are present at one point.

Pretest 6 is one of the maximal tests for this problem.

输出格式:

Print on the first line the smallest possible amount of money that will be enough to pay fees to the generals.

Print on the second line the number of arrangements that can be carried out using the smallest possible fee. This number should be calculated modulo 1000000007 1000000007 1000000007 ( 109+7 10^{9}+7 109+7 ).

输入输出样例

输入样例#1:

2
0 0
1 1
输出样例#1:

0
2
输入样例#2:

4
0 0
0 1
1 0
1 1
输出样例#2:

1
4
输入样例#3:

3
0 0
1000 1000
5000 5000
输出样例#3:

2000
2

说明

In the first example there are only two towers, the distance between which is equal to 2. If we give both towers to one general, then we well have to pay 2 units of money. If each general receives a tower to manage, to fee will be equal to 0. That is the smallest possible fee. As you can easily see, we can obtain it in two ways.


二分判断是否是二分图;

二分集合里的最小值,把大于这个值的连上一条边,然后判断是否是二分图;

我因为没开long long调了一上午,生无可恋。


Code:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;
const int mod = ; int n, X[], Y[];
int dis[][];
int color[];
int l = , r=1e6;
int bel[]; inline long long ksm(long long a, long long y)
{
int res = ;
while (y)
{
if (y & ) res = (res % mod * a % mod) % mod;
a = (a % mod * a % mod) % mod;
y >>= ;
}
return res % mod;
} bool dfs(int x, int col, int minn)
{
color[x] = col;
for (register int i = ; i <= n ; i ++)
{
if (x == i) continue;
if (dis[x][i] > minn)
{
if (color[i] == -)
{
if (!dfs(i, -col, minn)) return ;
}
else if (color[i] != - col) return ;
}
}
return ;
} inline bool check(int x)
{
memset(color, -, sizeof color);
for (register int i = ; i <= n ; i ++)
if (color[i] == -)
if (!dfs(i, , x)) return ;
return ;
} void dfs2(int x, int minn, int nu)
{
bel[x] = nu;
for (register int i = ; i <= n ; i ++)
{
if (i == x) continue;
if (bel[i]) continue;
if (dis[x][i] <= minn) continue;
dfs2(i, minn, nu);
}
} int main()
{
scanf("%d", &n);
for (register int i = ; i <= n ; i ++) scanf("%d%d",&X[i],&Y[i]);
for (register int i = ; i <= n ; i ++)
for (register int j = ; j <= n ; j ++)
dis[i][j] = abs(X[i]-X[j]) + abs(Y[i]-Y[j]);
int ans;
while (l < r)
{
int mid = l + r >> ;
if (check(mid)) r = mid;
else l = mid + ;
}
ans = l;
cout << ans << endl;
int tot = ;
for (register int i = ; i <= n ; i ++)
{
if (!bel[i]) tot++, dfs2(i, ans, tot);
}
cout << (ksm(, tot)) % mod;
return ;
}

[CF85E] Guard Towers - 二分+二分图的更多相关文章

  1. CF85E Guard Towers(二分答案+二分图)

    题意 已知 N 座塔的坐标,N≤5000 把它们分成两组,使得同组内的两座塔的曼哈顿距离最大值最小 在此前提下求出有多少种分组方案 mod 109+7 题解 二分答案 mid 曼哈顿距离 >mi ...

  2. 「CF85E」 Guard Towers

    「CF85E」 Guard Towers 模拟赛考了这题的加强版 然后我因为初值问题直接炸飞 题目大意: 给你二维平面上的 \(n\) 个整点,你需要将它们平均分成两组,使得每组内任意两点间的曼哈顿距 ...

  3. BZOJ_4443_[Scoi2015]小凸玩矩阵_二分+二分图匹配

    BZOJ_4443_[Scoi2015]小凸玩矩阵_二分+二分图匹配 Description 小凸和小方是好朋友,小方给小凸一个N*M(N<=M)的矩阵A,要求小秃从其中选出N个数,其中任意两个 ...

  4. NOIP 2010 关押罪犯 并查集 二分+二分图染色

    题目描述: S 城现有两座监狱,一共关押着N 名罪犯,编号分别为1~N.他们之间的关系自然也极不和谐.很多罪犯之间甚至积怨已久,如果客观条件具备则随时可能爆发冲突.我们用"怨气值" ...

  5. [NOIP 2010] 关押罪犯 (二分+二分图判定 || 并查集)

    题目描述 S 城现有两座监狱,一共关押着N 名罪犯,编号分别为1~N.他们之间的关系自然也极不和谐.很多罪犯之间甚至积怨已久,如果客观条件具备则随时可能爆发冲突.我们用"怨气值"( ...

  6. LUOGU 1525 关押罪犯 - 并查集拆点(对立点) / 二分+二分图染色

    传送门 分析: 并查集: 第一步先将所有矛盾从大至小排序,显然先将矛盾值大的分成两部分会更优. 普通的并查集都只能快速合并两个元素至同一集合,却不能将两个元素分至不同集合. 对于将很多数分成两个集合, ...

  7. CF 85E Guard Towers——二分图染色

    题目:http://codeforces.com/contest/85/problem/E 当然是二分.然后连一个图,染色判断是不是二分图即可.方案数就是2^(连通块个数). 别真的连边!不然时间空间 ...

  8. CF85 E Guard Towers——二分图

    题目:http://codeforces.com/contest/85/problem/E 给定一些点的坐标,求把它们分成两组,组内最大距离的最小值: 二分答案,判断就是看距离大于 mid 的点能否组 ...

  9. [USACO2003][poj2112]Optimal Milking(floyd+二分+二分图多重匹配)

    http://poj.org/problem?id=2112 题意: 有K个挤奶器,C头奶牛,每个挤奶器最多能给M头奶牛挤奶. 每个挤奶器和奶牛之间都有一定距离. 求使C头奶牛头奶牛需要走的路程的最大 ...

随机推荐

  1. CSS——字体

    1.字体样式font-family.颜色color <!DOCTYPE html> <html> <head> <meta charset="UTF ...

  2. 40 (OC)* 数据库常见sql语句

    1:增加INSERT INTO t_student (name, age) VALUES ('liwx', 18);2:删除DELETE FROM t_student WHERE name = 'li ...

  3. [Spark] 01 - What is Spark

    大数据 云计算概念 课程:Spark编程基础(Python版) 大数据4V特性 Volumn, Variety, Velocity, Value. 思维方式 通过数据发现问题,再解决问题. 速度更重要 ...

  4. [LeetCode] 面试题之犄角旮旯 第叁章

    题库:LeetCode题库 - 中等难度 习题:网友收集 - zhizhiyu 此处应为一个简单的核心总结,以及练习笔记. 查找一个数“在不在”?桶排序理论上貌似不错. 回文问题 ----> [ ...

  5. C#操作SQLServer的一个简单封装

    class DBHandler { //SqlConnection数据库连接对象 private SqlConnection localConnection = null; //构造函数中初始化连接对 ...

  6. Widget 中的 State 解析

    StatefulWidget 应对有交互.需要动态变化视觉效果的场景 StatelessWidget 则用于处理静态的.无状态的视图展示 那么,StatelessWidget 是否有存在的必要?Sta ...

  7. Python学习-迭代器、生成器

    一.迭代器 1. 可迭代对象 我们知道字符串.列表.元组.字典.集合都可以使用for语句进行循环遍历,然后输出每一个元素,这些都是可迭代对象. 检查对象是否是可迭代对象可以用两种方式去判断: (1)使 ...

  8. Scala Basis

    基础 Scala 中数据类型也是 class 7 种数值类型: Byte, Char, Short, Int, Long, Float, and Double Boolean 类型 原始类型与 cla ...

  9. Vue.js+vue-element搭建属于自己的后台管理模板:Vue.js快速入门(二)

    Vue.js+vue-element搭建属于自己的后台管理模板:Vue.js快速入门(二) 前言 上篇文章对Vue.js有了初步理解,接下来我们把Vue.js基础语法快速的过一遍,先混个脸熟留个印象就 ...

  10. 【ADO.NET基础-Login】带验证码验证的登录界面(用于简单的基础学习)

    以下代码如果有不对或者不妥之处,还望大神们指点一二 或者有同学者有问题或建议,一定要提出来,共同探讨 小弟在此感谢! 前台代码: <!DOCTYPE html> <html xmln ...