题目描述

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. airflow + CeleryExecutor 环境搭建

    airflow整合环境搭建 1. 整体结构 mysql -> 后端数据库 redis -> 用于broker CeleryExecutor -> 执行器 2. 环境安装 2.1,安装 ...

  2. jquery多级树形下拉菜单

    效果图: 使用方法 (1)引入 jQuery 包,下载地址 (2)引入 zTree 包,下载地址 (3)引入 tree-select.js (4)$("#id").treeSele ...

  3. 松软科技课堂:SQL-SELECT-INTO语句

    SQL SELECT INTO 语句可用于创建表的备份复件. SELECT INTO 语句 SELECT INTO 语句从一个表中选取数据,然后把数据插入另一个表中. SELECT INTO 语句常用 ...

  4. centos7下mysql 用户管理和权限设置

    1.进入mysql命令行,输入root及密码[root@localhost ~]# mysql -u root -pEnter password: Welcome to the MySQL monit ...

  5. Django中自定义模型管理器(Manager)及方法

    1.自定义管理器(Manager) 在语句Book.objects.all()中,objects是一个特殊的属性,通过它来查询数据库,它就是模型的一个Manager.每个Django模型至少有一个ma ...

  6. 上传本地Jar包到阿里云的云效私有仓库

    一.前言 前2天玩了一下上传本地jar到maven中央仓库,随后我们老大又给我说了一个叫云效的私有仓库也可以玩,小编试了一下,果然很舒服,配置很简单,效率很高,几分钟就能搞定,只需要自己有个阿里云的账 ...

  7. Containers vs Serverless:你选择谁,何时选择?

    两者都是当今技术时代的热门话题,也都被视为是开发技术的竞争对手. 首先,还有相当多的好奇和担心.此外,两者都是可供工程师使用的.高效的.机器无关的抽象. 但是,在冠军之间,有一个不可逾越的鸿沟.你要么 ...

  8. 使用mkfs.ext4格式化大容量磁盘

    使用mkfs.ext4默认参数格式化磁盘后,发现格式化时间特别长,并且格式化会占用磁盘很大的空间.例如2TB的磁盘格式化会占用10分钟左右时间,并占用30G左右的磁盘空间.究其原因,原来inode会占 ...

  9. java算法基础范例

    题目1:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少?  1.程序分析: 兔子的规律为数列1,1,2,3 ...

  10. Java String 类解析

    I.构造函数: public String() {} 默认构造函数 public String(String original) {} 使用原有字符串构造  public String(char va ...