poj1486二分匹配 待填坑
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 4777 | Accepted: 1867 |
Description
The situation is like this. The slides all have numbers written on them according to their order in the talk. Since the slides lie on each other and are transparent, one cannot see on which slide each number is written. 
Well, one cannot see on which slide a number is written, but one may deduce which numbers are written on which slides. If we label the slides which characters A, B, C, ... as in the figure above, it is obvious that D has number 3, B has number 1, C number 2 and A number 4.
Your task, should you choose to accept it, is to write a program that automates this process.
Input
This is followed by n lines containing two integers each, the x- and y-coordinates of the n numbers printed on the slides. The first coordinate pair will be for number 1, the next pair for 2, etc. No number will lie on a slide boundary.
The input is terminated by a heap description starting with n = 0, which should not be processed.
Output
If no matchings can be determined from the input, just print the word none on a line by itself.
Output a blank line after each test case.
Sample Input
4
6 22 10 20
4 18 6 16
8 20 2 18
10 24 4 8
9 15
19 17
11 7
21 11
2
0 2 0 2
0 2 0 2
1 1
1 1
0
Sample Output
Heap 1
(A,4) (B,1) (C,2) (D,3) Heap 2
none 贪心WA 二分又WA一次 5
1 4 1 4
2 7 2 7
5 11 5 11
8 13 9 14
9 14 8 13
3 3
3 3
6 6
10 10
12 12 结果应该是(C,3),但贪心的结果是none
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
int used[N],x[N],y[N];
bool vis[N],mp[N][N];
vector<int>G[N];
struct node
{
int xi,xx,yi,yx;
} e[N];
struct point
{
int x,y;
bool operator < (const point &A)const
{
return x<A.x;
}
} al[N];
bool findx(int x)
{
for(int i=; i<(int)G[x].size(); ++i)
{
int v=G[x][i];
if(vis[v]||mp[x][v]) continue;
vis[v]=;
if(!used[v]||findx(used[v]))
{
used[v]=x;
return true;
}
}
return false;
}
int ctx[N],cty[N];
int main()
{
int n,tas=;
while(scanf("%d",&n),n)
{
for(int i=; i<=n; ++i) G[i].clear();
for(int i=; i<=n; ++i) scanf("%d%d%d%d",&e[i].xi,&e[i].xx,&e[i].yi,&e[i].yx);
for(int i=; i<=n; ++i) scanf("%d%d",&x[i],&y[i]);
for(int i=; i<=n; ++i) for(int j=; j<=n; ++j) if(e[i].xi<=x[j]&&x[j]<=e[i].xx&&e[i].yi<=y[j]&&e[i].yx>=y[j]) G[i].push_back(j);
memset(used,,sizeof(used));
memset(mp,,sizeof(mp));
int tot=,maxmatch=,fx=;
for(int i=; i<=n; ++i)
{
memset(vis,,sizeof(vis));
if(findx(i)) ++maxmatch;
}
for(int i=; i<=n; ++i) if(used[i]) ctx[tot]=used[i],cty[tot++]=i;
printf("Heap %d\n",tas++);
if(!tot) puts("none");
else
{
/*for(int i=0; i<tot; ++i)
{
mp[ctx[i]][cty[i]]=1;
memset(vis,0,sizeof(vis));
used[cty[i]]=0;
if(!findx(ctx[i])) al[fx].x=ctx[i],al[fx++].y=cty[i];
mp[ctx[i]][cty[i]]=0;
used[cty[i]]=ctx[i];
}这么写不对的*/
for(int i=; i<tot; ++i)
{
int now=;
mp[ctx[i]][cty[i]]=;
memset(used,,sizeof(used));
for(int i=; i<=n; ++i)
{
memset(vis,,sizeof(vis));
if(findx(i)) ++now;
}
if(now!=maxmatch) al[fx].x=ctx[i],al[fx++].y=cty[i];
mp[ctx[i]][cty[i]]=;
}
if(!fx) puts("none");
else
{
sort(al,al+fx);
for(int i=; i<fx; ++i) printf("(%c,%d) ",al[i].x+'A'-,al[i].y);
puts("");
}
}
puts("");
}
}
poj1486二分匹配 待填坑的更多相关文章
- Cython的用法以及填坑姿势
因为项目需要,需要优化已有的Python代码.目前Python代码的执行过程是将Python代码转变成一行行指令,然后解释器解释指令的执行,调用到C代码层.如果去掉指令解释这个阶段,直接进入C代码层, ...
- Android项目开发填坑记-Fragment的onBackPressed
Github版 CSDN版 知识背景 Fragment在当前的Android开发中,有两种引用方式,一个是 Android 3.0 时加入的,一个是supportV4包中的.这里简称为Fragment ...
- Android Studio 3.0正式版填坑之路
原文:https://www.jianshu.com/p/9b25087a5d7d Android Studio 3.0启动图 序言 总看别人的文章,今天尝试着自己来写一篇.在逛论坛时候,无意间发 ...
- Vue2.0 新手完全填坑攻略——从环境搭建到发布
Jinkey原创感谢 showonne.yubang 技术指导Demo 地址:http://demo.jinkey.io/vue2源码:https://github.com/Jinkeycode/vu ...
- 动归专题QAQ(两天创造的刷题记录哟!✿✿ヽ(°▽°)ノ✿✿)(未填坑)
1092 采药:由于没有限制开始时间和结束时间,01背包就好了 1095 开心的金明:01背包,无fuck说 1104 摆花:f[i][j]表示摆了i种花,第i种花摆了j种的方案数,乱转移0.0(感觉 ...
- [react-native]react-native填坑笔记
填坑笔记 开始入坑RN,从最开始的学起难免有不少乱七八糟的问题,记录在这里. 1. 8081端口占用问题 按照官网教程搭建开发环境并按照下面代码运行时候有报错,显示8081端口的问题 react-na ...
- hdu 2444 The Accomodation of Students(二分匹配 匈牙利算法 邻接表实现)
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- Vue3+Typescript+Node.js实现微信端公众号H5支付(JSAPI v3)教程--各种填坑
----微信支付文档,不得不说,挺乱!(吐槽截止) 功能背景 微信公众号中,点击菜单或者扫码,打开公众号中的H5页面,进行支付. 一.技术栈 前端:Vue:3.0.0,typescript:3.9.3 ...
- Android—基于微信开放平台v3SDK,开发微信支付填坑。
接触微信支付之前听说过这是一个坑,,,心里已经有了准备...我以为我没准跳坑出不来了,没有想到我填上了,调用成功之后我感觉公司所有的同事都是漂亮的,隔着北京的大雾霾我仿佛看见了太阳~~~好了,装逼结束 ...
随机推荐
- Spring Boot 整合 Spring Security,用户登录慢
场景 Spring Boot + Spring Security搭建一个Web项目. 临时用了inMemoryAuthentication. @EnableWebSecurity public cla ...
- 【三剑客】sed命令
1. Sed 简介 sed 是Stream Editor(流编辑器)的缩写,是操作.过滤和转换文本内容的强大工具.常用功能有增删改查,过滤,取行. sed 是一种新型的,非交互式的编辑器. 它能执 ...
- Angular 7开发环境配置
目录 前言 一.搭建项目 1.安装Angular CLI 2.创建项目 3.集成Element Angular 二.设置路由 1.创建路由模块 2.导入.导出RouterModule类 3 ...
- 前端存储 (5) - service worker 离线存储
service worker 离线存储 简介: 一般的网站 在我们无法访问的 时候 一般 回出现 如下 该网页无法访问 service worker 构建的网站不会出现这个错误,因为所有的 请求都是先 ...
- 谁需要GUI?快看Linux 终端生存之道
完全在 Linux 终端中生存并不容易,但这绝对是可行的. 处理常见功能的最佳 Linux shell 应用 你是否曾想像过完完全全在 Linux 终端里生存?没有图形桌面,没有现代的 GUI 软件, ...
- SAAS 何以“免费”实现盈利
本文讲的是SAAS 何以"免费"实现盈利,[IT168 资讯]"天下没有免费的午餐",然而众多厂商却恰恰打出了免费这张王牌,且做出了不小的成绩,淘宝就凭借免费淘 ...
- #Week8 Advice for applying ML & ML System Design
一.Evaluating a Learning Algorithm 训练后测试时如果发现模型表现很差,可以有很多种方法去更改: 用更多的训练样本: 减少/增加特征数目: 尝试多项式特征: 增大/减小正 ...
- 洛谷 P 4180 次小生成树
题目描述 小C最近学了很多最小生成树的算法,Prim算法.Kurskal算法.消圈算法等等.正当小C洋洋得意之时,小P又来泼小C冷水了.小P说,让小C求出一个无向图的次小生成树,而且这个次小生成树还得 ...
- CRT 连接AWS-EC2
crt使用.pem登录AWS服务器 网上看到方案如下,看到大部分人都成功了,一头雾水,我的crt不需要pub文件.... chmod xxx.pem ssh-keygen -p -f xxx.pem ...
- 网络流 O - Marriage Match IV
题目链接:https://vjudge.net/contest/299467#problem/O 题目思路:网络流+最短路 这个是一个最短路+最大流,最短路容易,就是跑起点到每一个点的距离. 但是这个 ...