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,开发微信支付填坑。
接触微信支付之前听说过这是一个坑,,,心里已经有了准备...我以为我没准跳坑出不来了,没有想到我填上了,调用成功之后我感觉公司所有的同事都是漂亮的,隔着北京的大雾霾我仿佛看见了太阳~~~好了,装逼结束 ...
随机推荐
- servlet温故知新
重新学习了一遍servlet-api的文档,做一些记录. 有道云的笔记直接复制到博客上格式会乱,因此直接放上有道云的链接:http://note.youdao.com/noteshare?id=915 ...
- flask学习笔记(二)
一.视图函数的传参方式 修改前: 目标: 传参方式改成 途径: 通过request获取参数 注意:args并不是地点类型,而是dict的一个子类,如图: immutable意思是不可变 不可变的字典转 ...
- 微软Project Online落地中国
1月18日,微软中国宣布,从即日起,Project Online服务将正式落地中国,通过由世纪互联运营的Office 365向中国用户提供卓越的项目组合管理(PPM)联机解决方案,助力团队迅速启动项目 ...
- SaltStack数据系统之Grains、Pillar
SaltStack数据系统之Grains.Pillar 1.什么是Grains? Grains是saltstack的组件,用于收集salt-minion在启动时候的信息,又称为静态信息.Grains是 ...
- 【阅读笔记】Ranking Relevance in Yahoo Search (一)—— introduction & background
ABSTRACT: 此文在相关性方面介绍三项关键技术:ranking functions, semantic matching features, query rewriting: 此文内容基于拥有百 ...
- centos6.5宽带拨号上网
CentOS6以后要安装rp-pppoe这个软件,centos之前的版本是adsl-setup命令安装. (1)查看是否安装 #rpm -qa|grep rp-pppoe 没有内容输出则没安装,若可以 ...
- vue做商品选择如何保持样式
是这样的情况:我知道,在vue里,实现点击高亮,可以使用诸如: <div class="static" v-bind:class="{defaultClass ,a ...
- 使用docker搭建自己的博客(一)
购买服务器 首先服务器选择腾讯云学生服务器,25岁以下实名认证后月租10块,还是很适合我这种简约派的 又财大气粗买了个一年的域名,后面涨价再说吧 安装docker 使用xshell连上服务器 安装必要 ...
- T - zxa and leaf HDU - 5682 二分+dfs
T - zxa and leaf HDU - 5682 题目大意是:给你一颗树,这棵树有些节点已经设置了它的美丽值,然后剩下一些节点需要我们设置美丽值. 一条边的丑陋程度等于被定义为由这个边缘连接的两 ...
- 手把手教你进行Scrapy中item类的实例化操作
接下来我们将在爬虫主体文件中对Item的值进行填充. 1.首先在爬虫主体文件中将Item模块导入进来,如下图所示. 2.第一步的意思是说将items.py中的ArticleItem类导入到爬虫主体文件 ...