Elementary Math Gym
来源:互联网 发布:蓝月传奇龙魂数据 编辑:程序博客网 时间:2024/06/03 22:02
居然没有看出是二分图匹配。。
还是题目做的 太少勒
#include<bits/stdc++.h>#include<iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;#define sf scanf#define pf printf#define mem(a,b) memset(a,b,sizeof(a));#define rep(i,a,b) for(int i=(a);i<=(b);++i)#define MP make_pair#define ULL unsigned long long#define LL long long#define inf 0x3f3f3f3f#define md ((ll+rr)>>1)#define ls (i<<1)#define rs (ls|1)#define eps 1e-5#define ree freopen("in.txt","r",stdin);#define bug pf("----------------");#define N 10030#define M 1000020#define INF 1e9int n;int a[N],b[N];LL c[N];LL san[N];int fst[N],nxt[M],e,vv[M];int match[N];int cnt;int vis[N];void add(int u,int v){ vv[e]=v;nxt[e]=fst[u];fst[u]=e++;}void init(){ mem(fst,-1);e=0;}bool dfs(int x){ for(int i=fst[x];~i;i=nxt[i]){ int v=vv[i]; if(vis[v])continue; vis[v]=1; if(match[v]==-1||dfs(match[v])){ match[v]=x;return 1; } } return 0;}int haxi(LL x){ return lower_bound(san+1,san+1+cnt,x)-san;}int main(){ //ree init(); sf("%d",&n); cnt=0; rep(i,1,n){ sf("%d%d",&a[i],&b[i]); san[++cnt]=a[i]-b[i]; san[++cnt]=a[i]+b[i]; san[++cnt]=1LL*a[i]*b[i]; } sort(san+1,san+1+cnt); cnt=unique(san+1,san+1+cnt)-san-1; for(int i=1;i<=n;++i){ add(i,haxi(a[i]+b[i])); add(i,haxi(a[i]-b[i])); add(i,haxi(1LL*a[i]*b[i])); } int ans=0; mem(match,-1); for(int i=1;i<=n;++i){ mem(vis,0); if(dfs(i)){ ++ans; } } if(ans==n){ for(int i=1;i<=cnt;++i){ if(match[i]==-1)continue; c[match[i]]=i; } for(int i=1;i<=n;++i){ LL u=san[c[i]]; if(a[i]+b[i]==u) pf("%d + %d = %lld\n",a[i],b[i],u); else if(a[i]-b[i]==u) pf("%d - %d = %lld\n",a[i],b[i],u); else if(1LL*a[i]*b[i]==u) pf("%d * %d = %lld\n",a[i],b[i],u); } } else puts("impossible");}
阅读全文
0 0
- Elementary Math Gym
- Elementary Math、
- UVALive 7427Elementary Math
- NWERC2015 Elementary Math
- NWERC2015-Elementary Math
- CF Elementary Math【网络流】
- 【NWERC2015】【BZOJ4429】Elementary Math小学数学
- bzoj4429: [Nwerc2015] Elementary Math小学数学
- 【bzoj4429】[Nwerc2015] Elementary Math小学数学
- BZOJ 4429: [Nwerc2015] Elementary Math小学数学
- Codeforces Eyad and Math Gym
- Codeforces Eyad and Math Gym
- 【BZOJ4429】[Nwerc2015] Elementary Math小学数学【二分图匹配】
- BZOJ4429 Elementary Math小学数学 (二分图匹配)
- bzoj 4429: [Nwerc2015] Elementary Math小学数学 网络流
- CodeFroces NWERC 2015 E.Elementary Math(二分图)
- BZOJ 4429 [Nwerc2015] Elementary Math小学数学 二分图匹配
- Gym 101061G Repeat it(Math)
- 剑指Offer------包含min函数的栈
- leetcode: Minimum Window Substring
- AngularJS的自定义模板
- 常规的排序算法
- Linux线程的使用策略
- Elementary Math Gym
- Android 项目路径过长 引起error Error:too long on Windows, keep below 240 characters :
- Elasticsearch+python学习
- linux下的系统管理及系统安全命令
- 架构 理论 设计原则 分布式 总结
- QT学习过程中重难点总结
- Ubuntu16.04 常用软件集锦[超实惠]
- 【GarsiaWachs算法】bzoj3229: [Sdoi2008]石子合并
- 如何准备阿里的社招