1A HDU1498 & poj3041
来源:互联网 发布:青岛华为软件开发 编辑:程序博客网 时间:2024/06/06 05:01
1A,这个是poj3041的升级版,做法很简单,而且很暴力哈哈哈,具体方法下面介绍。
AC代码:
#include <iostream>#include <cstring>#include <string>#include <cstdio>#include <cstring>#include <vector>using namespace std;const int maxn=1e2+10;const int inf=0x3f3f3f3f;int n,k;int ori[maxn][maxn];bool mp[maxn][maxn];int mate[maxn];bool used[maxn];bool Findm(int x){ for(int i=1;i<=n;i++) { if(!used[i]&&mp[x][i]) { used[i]=1; if(!mate[i]||Findm(mate[i])) { mate[i]=x; return 1; } } } return 0;}int main(){ while(scanf("%d%d",&n,&k)==2&&n&&k) { int maxnum=-1; memset(ori,0,sizeof(ori)); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { scanf("%d",&ori[i][j]); if(maxnum<ori[i][j]) maxnum=ori[i][j]; } vector<int> v; v.clear(); for(int p=1;p<=maxnum;p++) { memset(mp,0,sizeof(mp)); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(ori[i][j]==p) mp[i][j]=1; int temp=0; memset(mate,0,sizeof(mate)); for(int i=1;i<=n;i++) { memset(used,0,sizeof(used)); temp+=Findm(i); } if(temp>k) { v.push_back(p); } } if(v.size()) { for(int i=0;i<v.size();i++) { if(i) printf(" "); printf("%d",v[i]); } printf("\n"); } else printf("-1\n"); }}
poj 3041
只要把有asteroid的行和列连边就好了~然后直接跑匈牙利算法。
AC代码
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <cmath>using namespace std;const int maxn=5e2+10;int N,K;bool mp[maxn][maxn];bool used[maxn];int mate[maxn];bool Findm(int x){ for(int i=1;i<=N;i++) { if(!used[i]&&mp[x][i]) { used[i]=1; if(!mate[i]||Findm(mate[i])) { mate[i]=x; return 1; } } } return 0;}int main(){ while(scanf("%d%d",&N,&K)==2) { memset(mp,0,sizeof(mp)); for(int i=1;i<=K;i++) { int t1,t2; scanf("%d%d",&t1,&t2); mp[t1][t2]=1; } int ans=0; memset(mate,0,sizeof(mate)); for(int i=1;i<=N;i++) { memset(used,0,sizeof(used)); ans+=Findm(i); } printf("%d\n",ans); }}
阅读全文
0 0
- 1A HDU1498 & poj3041
- hdu1498
- hdu1498
- Hdu1498
- poj3041
- poj3041
- poj3041
- poj3041
- poj3041
- POJ3041
- POJ3041
- poj3041
- poj3041
- POJ3041
- poj3041
- poj3041
- poj3041
- poj3041
- 初学python之基础详解(二)
- 个人笔记_EEPROM在微控STM32F1外设IIC控制下的操作细节总结
- UIImage 颜色渲染imageWithRenderingMode
- 转自:AlbertHongXS
- Python脚本运行出现语法错误:IndentationError: unindent does not match any outer indentation level
- 1A HDU1498 & poj3041
- java虚拟机运行时数据区域
- IPC详解
- 【Android_View】ImageView源码简析笔记(五)
- js 遇到的坑clear
- 【JAVA】数据交换,java方法参数
- Is It A Tree? -- HDOJ
- sum-root-to-leaf-numbers
- mysql