[CF85E] Guard Towers - 二分+二分图
题目描述
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 ).
输入输出样例
2
0 0
1 1
0
2
4
0 0
0 1
1 0
1 1
1
4
3
0 0
1000 1000
5000 5000
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 - 二分+二分图的更多相关文章
- CF85E Guard Towers(二分答案+二分图)
题意 已知 N 座塔的坐标,N≤5000 把它们分成两组,使得同组内的两座塔的曼哈顿距离最大值最小 在此前提下求出有多少种分组方案 mod 109+7 题解 二分答案 mid 曼哈顿距离 >mi ...
- 「CF85E」 Guard Towers
「CF85E」 Guard Towers 模拟赛考了这题的加强版 然后我因为初值问题直接炸飞 题目大意: 给你二维平面上的 \(n\) 个整点,你需要将它们平均分成两组,使得每组内任意两点间的曼哈顿距 ...
- BZOJ_4443_[Scoi2015]小凸玩矩阵_二分+二分图匹配
BZOJ_4443_[Scoi2015]小凸玩矩阵_二分+二分图匹配 Description 小凸和小方是好朋友,小方给小凸一个N*M(N<=M)的矩阵A,要求小秃从其中选出N个数,其中任意两个 ...
- NOIP 2010 关押罪犯 并查集 二分+二分图染色
题目描述: S 城现有两座监狱,一共关押着N 名罪犯,编号分别为1~N.他们之间的关系自然也极不和谐.很多罪犯之间甚至积怨已久,如果客观条件具备则随时可能爆发冲突.我们用"怨气值" ...
- [NOIP 2010] 关押罪犯 (二分+二分图判定 || 并查集)
题目描述 S 城现有两座监狱,一共关押着N 名罪犯,编号分别为1~N.他们之间的关系自然也极不和谐.很多罪犯之间甚至积怨已久,如果客观条件具备则随时可能爆发冲突.我们用"怨气值"( ...
- LUOGU 1525 关押罪犯 - 并查集拆点(对立点) / 二分+二分图染色
传送门 分析: 并查集: 第一步先将所有矛盾从大至小排序,显然先将矛盾值大的分成两部分会更优. 普通的并查集都只能快速合并两个元素至同一集合,却不能将两个元素分至不同集合. 对于将很多数分成两个集合, ...
- CF 85E Guard Towers——二分图染色
题目:http://codeforces.com/contest/85/problem/E 当然是二分.然后连一个图,染色判断是不是二分图即可.方案数就是2^(连通块个数). 别真的连边!不然时间空间 ...
- CF85 E Guard Towers——二分图
题目:http://codeforces.com/contest/85/problem/E 给定一些点的坐标,求把它们分成两组,组内最大距离的最小值: 二分答案,判断就是看距离大于 mid 的点能否组 ...
- [USACO2003][poj2112]Optimal Milking(floyd+二分+二分图多重匹配)
http://poj.org/problem?id=2112 题意: 有K个挤奶器,C头奶牛,每个挤奶器最多能给M头奶牛挤奶. 每个挤奶器和奶牛之间都有一定距离. 求使C头奶牛头奶牛需要走的路程的最大 ...
随机推荐
- Day3 目录结构及文件管理
Windows:以多根的方式组织文件C : D: E: F: linux:以单根的方式组织文件 / 2.存放命令相关的目录 /bin 普通用户的使用的命令 /bin /ls ,/bin/da ...
- Java8虚拟机(JVM)内存溢出实战
前言 相信很多JAVA中高级的同学在面试的时候会经常碰到一个面试题 你是如何在工作中对JVM调优和排查定位问题的? 事实上,如果用户量不大的情况下,在你的代码还算正常的情况下,在工作中除非真正碰到与J ...
- .Net Core 3.0 gRPC部署问题解决
前言 .Net Core3.0终于如约而至的来了.在3.0中增加了许多东西.也有了许多的变化.今天我们看的就是在3.0中使用gRPC并遇到的问题.gRPC现在可以非常方便简洁的在.Net Core中使 ...
- 使用Git工具批量拉取代码
公司项目比较多,每天上班第一件事就是拉取代码,cd A 目录 git pull cd .. cd B ...... 一个项目一个项目的拉取,感觉也是很费劲的,那么有没有什么一键操作呢 现在执行一个命令 ...
- Python 之父的解析器系列之七:PEG 解析器的元语法
原题 | A Meta-Grammar for PEG Parsers 作者 | Guido van Rossum(Python之父) 译者 | 豌豆花下猫("Python猫"公众 ...
- web前端开发面试题(附答案)-1
1.浏览器中输入url到网页显示,整个过程发生了什么 域名解析 发起tcp三次握手 建立tcp连接之后发起htttp请求 服务器端响应http请求,浏览器得到html代码 浏览器器解析html代码,并 ...
- Flume系列一之架构介绍和安装
Flume架构介绍和安装 写在前面 在学习一门新的技术之前,我们得知道了解这个东西有什么用?我们可以使用它来做些什么呢?简单来说,flume是大数据日志分析中不能缺少的一个组件,既可以使用在流处理中, ...
- XLNet预训练模型,看这篇就够了!(代码实现)
1. 什么是XLNet XLNet 是一个类似 BERT 的模型,而不是完全不同的模型.总之,XLNet是一种通用的自回归预训练方法.它是CMU和Google Brain团队在2019年6月份发布的模 ...
- You can't specify target table 'sys_user_function' for update in FROM clause
mysql数据库在执行同时查询本表数据并删除本表数据时候,报错! 报错原因: DELETE from sys_user_function where User_Id = 19 and Function ...
- FastDfs之TrackerServer的详细配置介绍
# is this config file disabled # false for enabled # true for disabled disabled=false #当前配置是否不可用fals ...