UVALive - 6868 Facility Locations 想法题
2024-10-22 09:52:15
题目链接:
http://acm.hust.edu.cn/vjudge/problem/88634
Facility Locations
Time Limit: 3000MS
题意
给你一个m*n的矩阵,上面的数满足cij ≤ ci′j + ci′j′ + cij′。现在要选出k行,使得这k行上面的0刚好能够覆盖所有的列。
样例
sample input
3 2 2
0 2
1 1
2 0
3 3 2
0 2 2
1 1 1
2 2 0sample output
yes
no
题解
“cij ≤ ci′j + ci′j′ + cij′”决定:如果两行在同一列都有零,那么这两行其他列的零的分布情况也会完全相同。所以我们可以枚举每一列,如果该列我们还没标记过,就任意选一个在该列为0的行(如果一个都找不到,那肯定无解),并标记该行其他列为0的位置,然后继续做,如果最后选k个以内就能做完,那么就输出yes,否则输出no。
代码
#include<map>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define X first
#define Y second
#define mkp make_pair
#define lson (o<<1)
#define rson ((o<<1)|1)
#define mid (l+(r-l)/2)
#define sz() size()
#define pb(v) push_back(v)
#define all(o) (o).begin(),(o).end()
#define clr(a,v) memset(a,v,sizeof(a))
#define bug(a) cout<<#a<<" = "<<a<<endl
#define rep(i,a,b) for(int i=a;i<(b);i++)
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<pair<int,int> > VPII;
const int INF=0x3f3f3f3f;
const LL INFL=0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-8;
//start----------------------------------------------------------------------
const int maxn=111;
int vis[maxn];
int arr[maxn][maxn];
int n,m,k;
int main() {
while(scanf("%d%d%d",&n,&m,&k)==3){
rep(i,1,n+1){
rep(j,1,m+1){
scanf("%d",&arr[i][j]);
}
}
clr(vis,0);
int cnt=0,su=1;
rep(j,1,m+1){
if(vis[j]) continue;
rep(i,1,n+1){
if(arr[i][j]==0){
vis[j]=1;
cnt++;
rep(k,1,m+1){
if(arr[i][k]==0) vis[k]=1;
}
break;
}
}
if(!vis[j]){
su=0; break;
}
}
if(!su||cnt>k) puts("no");
else puts("yes");
}
return 0;
}
//end-----------------------------------------------------------------------
最新文章
- matlab中pcolorh函数作用
- linux常用命令-用户管理命令
- 存储过程详解与java调用(转)
- tomcat源码剖析
- 视图(View)与部分视图(Partial View)之间数据传递
- Android中View的绘制过程 onMeasure方法简述 附有自定义View例子
- An Implementation of Double-Array Trie
- Python笔记本
- UNIX网络编程——网络IPC:套接字
- Java包的命名规则
- Chrome Apps将可以打包成iOS或Android应用
- mysql配置优化测试
- hdu5072(鞍山regional problem C):容斥,同色三角形模型
- 第九十一节,html5+css3pc端固定布局,完成首页
- mongoDB7--游标cursor
- XML读取两种方法
- [模拟赛] T2 不等数列
- MyDAL - .Where() 之 .WhereSegment 根据条件 动态设置 Select查询条件 使用
- python基础一 ------字符串的多种分隔符分隔
- Luncene介绍