题目描述

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. Java之BigDecimal详解

    一.BigDecimal概述 ​ Java在java.math包中提供的API类BigDecimal,用来对超过16位有效位的数进行精确的运算.双精度浮点型变量double可以处理16位有效数,但在实 ...

  2. eclipse查看.class文件

    要使用jd-gui.exe反编译程序 步骤:window-preferences-general-editors-file associations, 如下图 上面的框选中,*.class witho ...

  3. 第二场周赛(递归递推个人Rank赛)——题解

    很高兴给大家出题,本次难度低于上一场,新生的六个题都可以直接裸递归式或者裸递推式解决,对于老生的汉诺塔3,需要找出一般式,后两题分别为裸ST算法(或线段树)/线性DP. 正确的难度顺序为 种花 角谷定 ...

  4. 简说Python发展及其就业前景

    简说python 发展历史 Python是著名的"龟叔"Guido van Rossum在1989年圣诞节期间,为了打发无聊的圣诞节而编写的一个编程语言. python从ABC语言 ...

  5. Linux之正则表达式grep

    真好!

  6. .netCore+Vue 搭建的简捷开发框架 (2)--仓储层实现和EFCore 的使用

    书接上文,继续搭建我们基于.netCore 的开发框架.首先是我们的项目分层结构. 这个分层结构,是参考张老师的分层结构,但是实际项目中,我没有去实现仓储模型.因为我使用的是EFCore ,最近也一直 ...

  7. 让API实现版本管理的实践

    API版本管理的重要性不言而喻,对于API的设计者和使用者而言,版本管理都有着非常重要的意义.下面会从WEB API 版本管理的角度提供几种常见办法: 首先,对于API的设计和实现者而言,需要考虑向后 ...

  8. Java门面模式

    一.简介 隐藏系统的复杂性,对外提供统一的访问入口,外部系统访问只通过此暴露出的统一接口访问.是一种结构型模式.封装子系统接口的复杂性,提供统一的对外接口,能够使子系统更加简单的被使用. 二.结构及使 ...

  9. Spring 梳理 - AOP那些学术概念—通知、增强处理连接点(JoinPoint)切面(Aspect)

    Spring  AOP那些学术概念—通知.增强处理连接点(JoinPoint)切面(Aspect)   1.我所知道的AOP 初看起来,上来就是一大堆的术语,而且还有个拉风的名字,面向切面编程,都说是 ...

  10. JS/Jquery关系

    1. JS / JQuery介绍 Jquery是JS库,何为JS库,即把常用的js方法进行封装,封装到单独的JS文件中,要用的时候直接调用即可: 2. JS / JQuery对象 1. 定义 (1) ...