Ural 1997-Those are not the droids you're looking for 二分图匹配
2014-04-01 01:03
513 查看
挺水的一道模板题让我硬生生错了10发,不想说什么了。
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; int a,b; int n; int t,d; int count1,count2; bool visit[1111]; int p[1111],q[1111]; int link[1111]; bool map[1111][1111]; bool dfs(int k)//寻找从k出发的可增广路 { int i,j; for(int i=1;i<=count2;i++) { if(map[k][i]&&!visit[i])//和cap关联的点,且不在增广路上 { visit[i]=1;//加入增广路 j=link[i]; if(j==-1||dfs(j))//j是未盖点 或者 从j的对应项出发有可增广路) { link[i]=k; return true;//k有可增广路,返回true; } } } return false;//则从k没有可增广路,返回false; } int hungary() { int num=0; memset(link,-1,sizeof(link));//初始化 for(int i=1;i<=count1;i++) { memset(visit,0,sizeof(visit)); if(dfs(i))//有增广路 { num++;//匹配数++ } } return num; } int main() { count1=0;count2=0; scanf("%d%d",&a,&b); scanf("%d",&n); memset(p,0,sizeof(p)); memset(q,0,sizeof(q)); memset(map,0,sizeof(map)); for(int i=1;i<=n;i++) { scanf("%d%d",&t,&d); if(d==0) { count1++; p[count1]=t; } else { count2++; q[count2]=t; } } for(int i=1;i<=count1;i++) { for(int j=1;j<=count2;j++) { if(p[i]>=q[j]) continue;//进去时间必须小于出去的时间 int cnt=q[j]-p[i]; if(cnt<=b||cnt>=a)//不加上面那个判断存在cnt<0的情况 { map[i][j]=1; } } } int ans=hungary(); if(ans*2!=n) { printf("Liar\n"); } else { printf("No reason\n"); for(int i=1;i<=count2;i++) { printf("%d %d\n",p[link[i]],q[i]); } } return 0; }
相关文章推荐
- URAL 1997 Those are not the droids you're looking for(二分图)
- URAL1997-Those are not the droids you're looking for
- ACM ICPC 2013-2014 H. Those are not the droids you're looking for(二分匹配-Dinic)
- Those are not the droids you're looking for Gym - 100285H 二分图 最大流
- 让国外邮件服务商不再拒收你的邮件,The IP you're using to send mail is not authorized
- The IP you're using to send email is not authorized
- Sorry, the page you are looking for could not be found.
- [转]让国外邮件服务商不再拒收你的邮件,The IP you're using to send mail is not authorized
- Invalid 'Count of Targets Not Uploading Exceeded the Critical Threshold' Alerts are Raised for Agent
- A definition for the symbol '<symbolName>' could not be located
- Trouble shooting:login failed for user 'sa' ,the user is not associated with a trusted SQL Server
- 'Could not apply the stored configuration for the monitor'解决方法-fedora19
- Could not find schema information for the element 'supportedRuntime'.
- 编译错误“The run destination My Mac 64-bit is not valid for Running the scheme '***',解决办法
- The bundle does not contain an app icon for iPhone / iPod Touch of exactly '120x120' pixels, in .pn
- nginx+php-fpm运行php "The page you are looking for is temporarily unavailable. Please try again later"
- The SQL Site Map Provider You've Been Waiting For
- MySQL报错“ you can't specify the target table for ‘update’ in from clause”
- An error occurred. Sorry, the page you are looking for is currently unavailable. Please try again later.
- fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module