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,开发微信支付填坑。
接触微信支付之前听说过这是一个坑,,,心里已经有了准备...我以为我没准跳坑出不来了,没有想到我填上了,调用成功之后我感觉公司所有的同事都是漂亮的,隔着北京的大雾霾我仿佛看见了太阳~~~好了,装逼结束 ...
随机推荐
- java中Locks的使用
文章目录 Lock和Synchronized Block的区别 Lock interface ReentrantLock ReentrantReadWriteLock StampedLock Cond ...
- 【Linux常见问题】CentOS 6 root用户密码忘记,找回密码方法
1.Linux的root密码修改不像Windows的密码修改找回,Windows的登录密码忘记需要介入工具进行解决.CentOS6和CentOS7的密码方法也是不一样的,具体如下: 2.centos ...
- 《Python游戏编程快速上手》——1.3 如何使用本书
本节书摘来自异步社区<Python游戏编程快速上手>一书中的第1章,第1.3节,作者[美] Al Sweigart(斯维加特),李强 译,更多章节内容可以访问云栖社区"异步社区& ...
- Netty(一):ByteBuf读写过程图解
我们知道ByteBuf通过读写两个索引分离,避免了NIO中ByteBuffer中读写模式切换时,需要flip等繁琐的操作. 今天就通过一段测试代码以及图例来直观的了解下ByteBuf中的readInd ...
- Vue项目中设置每个单页面的标题
两种实现方法,第一种方法引入插件,第二种为编程方式实现(推荐) 首先在路由文件index.js中给每个单页面路由添加title routes: [{ path: '/', name: ...
- STL--priority_queue--自定义数据类型
STL中priority_queue的声明模板有3个参数priority_queue<Type,Container,Functional>. 当使用的数据类型Type为自定义数据类型时有以 ...
- POJ - 2387 Til the Cows Come Home (最短路入门)
Bessie is out in the field and wants to get back to the barn to get as much sleep as possible before ...
- Entity Framework使用EntityState和Attach来保存数据变化以及更新实体的个别字段
在使用Entity Framework作为ORM来存取数据的过程中,最常规的操作就是对数据对象的更新.本文将会包含如何Attach Entity到一个数据Context中,以及如何使用EntitySt ...
- Jmeter 性能测试(需求/指标分析与定义)
1.一般而言,被测对象的性能需求,会在用户需求规格说明书中给出,如单位时间内的访问量需达到多少?业务响应时间不超过多少?业务成功率不低于多少?硬件资源耗用要在一个合理的范围中. 如下性能指标非常明确 ...
- MySQL——视图/触发器/事务/存储过程/函数/流程控制
一 视图 视图是一个虚拟表(非真实存在),其本质是[根据SQL语句获取动态的数据集,并为其命名],用户使用时只需使用[名称]即可获取结果集,可以将该结果集当做表来使用. 使用视图我们可以把查询过程中的 ...