CSUOJ 1531 Jewelry Exhibition
Problem G
Jewelry Exhibition
To guard the art jewelry exhibition at night, the security agency has decided to use a new laser beam system, consisting of sender-receiver pairs. Each pair generates a strip of light of one unit width and guards all objects located inside the strip. Your task is to help the agency and to compute for each exhibition room the minimum number of sender-receiver pairs which are sufficient to protect all exhibits inside the room.
Any room has a rectangle shape, so we describe it as an [0,N] × [0,M] rectangle in the plane. The objects we need to guard are represented as points inside that rectangle. Each sender is mounted on a wall and the corresponding receiver on the opposite wall in such a way that the generated strip is a rectangle of unit width and length either N or M. Since the new laser beam system is still not perfect, each sender-receiver pair can only be mounted to generate strips the corners of which have integer coordinates. An additional drawback is that the sender-receiver pairs can protect only items inside the strips, but not those lying on their borders. Thus, the security agency arranged the exhibits in such a way that both coordinates of any point representing an exhibit are non-integers. The figure below (left) illustrates eight items arranged in [0,4]×[0,4] (the second sample input). In the room, up to eight sender-receiver pairs can be mounted. The figure to the right shows an area protected by three sender-receiver pairs.
Input
The input starts with the number of exhibition rooms R ≤ 10. Then the descriptions of the R rooms follow. A single description starts with a single line, containing three integers: 0 < N ≤ 100, 0 < M ≤ 100, specifying the size of the current room and 0 < K ≤ 104, for the number of exhibits. Next K lines follow, each of which consists of two real numbers x,y describing the exhibit coordinates. You can assume that 0 < x < N, 0 < y < M and that x and y are non-integer.
Output
For every room output one line containing one integer, that is the minimum number of sender-receiver pairs sufficient to protect all exhibits inside the room.
Sample Input Sample Output
2 1
1 5 3 3
0.2 1.5
0.3 4.8
0.4 3.5
4 4 8
0.7 0.5
1.7 0.5
2.8 1.5
3.7 0.5
2.2 3.6
2.7 2.7
1.2 2.2
1.2 2.7
解题:最大匹配
匈牙利算法
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = ;
bool e[maxn][maxn],used[maxn];
int linker[maxn],U,V;
bool dfs(int u) {
for(int i = ; i < V; ++i) {
if(e[u][i] && !used[i]) {
used[i] = true;
if(linker[i] == - || dfs(linker[i])) {
linker[i] = u;
return true;
}
}
}
return false;
}
int main() {
int ks,n;
double x,y;
scanf("%d",&ks);
while(ks--) {
scanf("%d%d%d",&U,&V,&n);
memset(linker,-,sizeof(linker));
memset(e,false,sizeof(e));
for(int i = ; i < n; ++i) {
scanf("%lf %lf",&x,&y);
e[(int)x][(int)y] = true;
}
int ans = ;
for(int i = ; i < U; ++i) {
memset(used,false,sizeof(used));
ans += dfs(i);
}
printf("%d\n",ans);
}
return ;
}
最大流
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
struct arc{
int to,flow,next;
arc(int x = ,int y = ,int z = -){
to = x;
flow = y;
next = z;
}
}e[maxn*maxn*];
int head[maxn],d[maxn],cur[maxn],tot,S,T;
void add(int u,int v,int flow){
e[tot] = arc(v,flow,head[u]);
head[u] = tot++;
e[tot] = arc(u,,head[v]);
head[v] = tot++;
}
bool bfs(){
queue<int>q;
memset(d,-,sizeof(d));
d[S] = ;
q.push(S);
while(!q.empty()){
int u = q.front();
q.pop();
for(int i = head[u]; ~i; i = e[i].next){
if(e[i].flow && d[e[i].to] == -){
d[e[i].to] = d[u] + ;
q.push(e[i].to);
}
}
}
return d[T] > -;
}
int dfs(int u,int low){
if(u == T) return low;
int tmp = ,a;
for(int &i = cur[u]; ~i; i = e[i].next){
if(e[i].flow && d[e[i].to] == d[u] + &&(a=dfs(e[i].to,min(low,e[i].flow)))){
e[i].flow -= a;
e[i^].flow += a;
low -= a;
tmp += a;
if(!low) break;
}
}
if(!tmp) d[u] = -;
return tmp;
}
int solve(){
int ans = ;
while(bfs()){
memcpy(cur,head,sizeof(head));
ans += dfs(S,INF);
}
return ans;
}
int main(){
int ks,n,m,k;
double x,y;
scanf("%d",&ks);
while(ks--){
scanf("%d %d %d",&n,&m,&k);
memset(head,-,sizeof(head));
for(int i = tot = ; i < k; ++i){
scanf("%lf %lf",&x,&y);
add((int)x,n+(int)y,);
}
S = n + m;
T = S + ;
for(int i = ; i < n; ++i)
add(S,i,);
for(int i = ; i < m; ++i)
add(i+n,T,);
printf("%d\n",solve());
}
return ;
}
CSUOJ 1531 Jewelry Exhibition的更多相关文章
- Jewelry Exhibition(最小点覆盖集)
Jewelry Exhibition 时间限制: 1 Sec 内存限制: 64 MB提交: 3 解决: 3[提交][状态][讨论版] 题目描述 To guard the art jewelry e ...
- CSU-1531 Jewelry Exhibition —— 二分图匹配(最小覆盖点)
题目链接:https://vjudge.net/problem/CSU-1531 Input Output Sample Input 2 1 5 3 0.2 1.5 0.3 4.8 0.4 3.5 4 ...
- HDU 3592 World Exhibition(线性差分约束,spfa跑最短路+判断负环)
World Exhibition Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdoj--3592--World Exhibition(差分约束)
World Exhibition Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- (01背包变形) Cow Exhibition (poj 2184)
http://poj.org/problem?id=2184 Description "Fat and docile, big and dumb, they look so stupid ...
- POJ2184 Cow Exhibition[DP 状态负值]
Cow Exhibition Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12420 Accepted: 4964 D ...
- codevs 1531 山峰
codevs 1531 山峰 题目描述 Description Rocky山脉有n个山峰,一字排开,从西向东依次编号为1, 2, 3, --, n.每个山峰的高度都是不一样的.编号为i的山峰高度为hi ...
- csuoj 1511: 残缺的棋盘
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1511 1511: 残缺的棋盘 时间限制: 1 Sec 内存限制: 128 MB 题目描述 输入 ...
- 山峰(codevs 1531)
1531 山峰 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Description Rocky山脉有n个山峰,一字排开,从 ...
随机推荐
- 每一个人都懂得敏捷开发 (软件project), 为何产品开发的效率与质量还是这么的烂?
敏捷开发(软件project)是 "设计" 出来的.不是 "学" 来的-- 很多人都一直在质疑敏捷开发能否提高效率与质量? 更有不少人以嘲讽.不屑的口吻看待软件 ...
- SVN管理工具的使用(实习第9天)
最后就是我进行提交代码的时候要记得写注释,自己写了那些方法要标明,或者自己修改了哪些功能也要表明.不然我会被骂的. 2>代码冲突解决的问题: 服务器上的代码跟自己代码改动的地方不同 这种情况比较 ...
- C# Winform 模拟QQ新闻弹出框
一开始做的时候,觉得这个太简单了.真心做的时候还是遇到了不少的坑啊. 1)循环播放新闻内容,建议使用showdialog(),不要用show(),不太好控制前后之间的停顿. 2)窗口的初始位置为有下角 ...
- angularjs 事件向上向下传播
<!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv="C ...
- ubuntu16.04下snort的安装(官方文档安装)(图文详解)
不多说,直接上干货! 最近为了科研,需要安装和使用Snort. snort的官网 https://www.snort.org/ Snort作为一款优秀的开源主机入侵检测系统,在windows和Linu ...
- Method Swizzing中一般替换方法都写在Category类别里吗?有没有别的实现方式
Method Swizzing中一般替换方法都写在Category类别里吗?有没有别的实现方式 Method Swizzing中一般替换方法都写在Category类别里吗?有没有别的实现方式 > ...
- ReactiveCocoa结合了几种编程风格
函数式编程(Functional Programming):使用高阶函数,例如函数用其他函数作为参数.响应式编程(Reactive Programming):关注于数据流和变化传播.所以,你可能听说过 ...
- mac ssh报错处理
总结一下 1.The authenticity of host '[192.168.1.100]:22 ([192.168.1.100]:22)' can't be established. RSA ...
- [POI2015]WIL-Wilcze doły(单调队列)
题意 给定一个长度为n的序列,你有一次机会选中一段连续的长度不超过d的区间,将里面所有数字全部修改为0.请找到最长的一段连续区间,使得该区间内所有数字之和不超过p. (1<=d<=n< ...
- pip命令使用方法 与 错误处理
这里把学习到的pip命令写一个汇总,方便想不起来时使用 通过cmd输入pip可以显示提示信息,中文翻译如下: 1)显示某个包的信息 pip show selenium #显示selenium模块的信息 ...