HDU - 3605 : acm.hdu.edu.cn/showproblem.php?pid=3605

题目:

    有1e5的的人,小于10个的星球,每个星球都有容量,每个人也有适合的星球和不适合的星球。问所有人是否能住到星球上去。

思路:

    这道题目如果直接用常用的建图方式是不行的,因为人太多了,相应的边就很多,会TLE。那要怎么做呢,因为只有十个星球,所以有很多人的特征是相同的,所以把这1e5个点可以缩成最多1024个点。这样建图跑dinic就行了。

//#pragma GCC optimize(3)
//#pragma comment(linker, "/STACK:102400000,102400000") //c++
// #pragma GCC diagnostic error "-std=c++11"
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("-fdelete-null-pointer-checks,inline-functions-called-once,-funsafe-loop-optimizations,-fexpensive-optimizations,-foptimize-sibling-calls,-ftree-switch-conversion,-finline-small-functions,inline-small-functions,-frerun-cse-after-loop,-fhoist-adjacent-loads,-findirect-inlining,-freorder-functions,no-stack-protector,-fpartial-inlining,-fsched-interblock,-fcse-follow-jumps,-fcse-skip-blocks,-falign-functions,-fstrict-overflow,-fstrict-aliasing,-fschedule-insns2,-ftree-tail-merge,inline-functions,-fschedule-insns,-freorder-blocks,-fwhole-program,-funroll-loops,-fthread-jumps,-fcrossjumping,-fcaller-saves,-fdevirtualize,-falign-labels,-falign-loops,-falign-jumps,unroll-loops,-fsched-spec,-ffast-math,Ofast,inline,-fgcse,-fgcse-lm,-fipa-sra,-ftree-pre,-ftree-vrp,-fpeephole2",3) #include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <cassert> using namespace std;
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue typedef long long ll;
typedef unsigned long long ull;
//typedef __int128 bll;
typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;
typedef pair<int,pii> p3; //priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
//#define endl '\n' #define OKC ios::sync_with_stdio(false);cin.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A) //用来压行
#define REP(i , j , k) for(int i = j ; i < k ; ++i)
#define max3(a,b,c) max(max(a,b), c);
//priority_queue<int ,vector<int>, greater<int> >que; const ll mos = 0x7FFFFFFF; //
const ll nmos = 0x80000000; //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //
const int mod = 1e9+;
const double esp = 1e-;
const double PI=acos(-1.0);
const double PHI=0.61803399; //黄金分割点
const double tPHI=0.38196601; template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
} /*-----------------------showtime----------------------*/ struct edge{
int u,v,cap,flag;
edge(){}
edge(int u,int v,int cap,int flag):u(u),v(v),cap(cap),flag(flag){}
}es[]; int tot,s,t;
vector<int>tab[];
int dis[],cur[];
void addedge(int u,int v,int cap){
// debug(u);
tab[u].pb(tot);
es[tot++] = edge(u,v,cap,);
tab[v].pb(tot);
es[tot++] = edge(v,u,,);
} bool bfs(){
queue<int>q; q.push(s);
memset(dis,inf,sizeof(dis));
dis[s] = ;
while(!q.empty()){
int h = q.front(); q.pop();
for(int i=; i<tab[h].size(); i++){
edge & e = es[tab[h][i]];
if(e.cap > && dis[e.v] >= inf){
dis[e.v] = dis[h] + ;
q.push(e.v);
}
}
}
return dis[t] < inf;
} int dfs(int x,int maxflow){
if(x == t || maxflow == ) return maxflow;
for(int i=cur[x] ; i<tab[x].size(); i++){
cur[x] = i;
edge & e = es[tab[x][i]];
if(dis[e.v] == dis[x] + && e.cap > ){
int flow = dfs(e.v, min(maxflow, e.cap));
if(flow){
e.cap -= flow; es[tab[x][i] ^ ].cap += flow;
return flow;
}
}
}
return ;
} int dinic(){
int ans = ;
while(bfs()){ int flow;
memset(cur,,sizeof(cur));
do{
flow = dfs(s,inf);
if(flow) ans += flow;
}while(flow); }
return ans;
}
int cnt[];
int main(){
int n,m;
while(~scanf("%d%d", &n, &m) && n+m){ tot = ;
s = , t = +m+m+;
for(int i=s; i<=t; i++)tab[i].clear();
memset(cnt,,sizeof(cnt));
for(int i=; i<=n; i++){
int tmp = ;
for(int j=; j<=m; j++){
int x; scanf("%d", &x);
tmp= tmp* + x;
}
cnt[tmp]++;
}
for(int i=; i<=; i++)
{
if(cnt[i] == )continue;
addedge(s,i,cnt[i]);
for(int j=; j<m; j++){
if((i>>j) & == ) addedge(i,+j,cnt[i]);
}
}
for(int i=; i<m; i++){
int x;scanf("%d", &x);
addedge(+i,+m+i,x);
addedge(+m+i,t,inf);
}
if(n == dinic()) puts("YES");
else puts("NO");
}
return ;
}

HDU - 3605

HDU- 3605 - Escape 最大流 + 二进制压位的更多相关文章

  1. HDU 3605 Escape 最大流+状压

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=3605 Escape Time Limit: 2000/1000 MS (Java/Others)    ...

  2. Hdu 3605 Escape (最大流 + 缩点)

    题目链接: Hdu 3605  Escape 题目描述: 有n个人要迁移到m个星球,每个星球有最大容量,每个人有喜欢的星球,问是否所有的人都能迁移成功? 解题思路: 正常情况下建图,不会爆内存,但是T ...

  3. HDU 3605 Escape 最大流

    题意: 如果这是2012年世界末日怎么办?我不知道该怎么做.但是现在科学家们已经发现,有些星球上的人可以生存,但有些人却不适合居住.现在科学家们需要你的帮助,就是确定所有人都能在这些行星上生活.输入多 ...

  4. HDU 3605 Escape (网络流,最大流,位运算压缩)

    HDU 3605 Escape (网络流,最大流,位运算压缩) Description 2012 If this is the end of the world how to do? I do not ...

  5. HDU 3605 Escape(状压+最大流)

    Escape Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Sub ...

  6. hdu 3605 Escape 二分图的多重匹配(匈牙利算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3605 Escape Time Limit: 4000/2000 MS (Java/Others)    ...

  7. HDU 3605 Escape(状态压缩+最大流)

    http://acm.hdu.edu.cn/showproblem.php?pid=3605 题意: 有n个人和m个星球,每个人可以去某些星球和不可以去某些星球,并且每个星球有最大居住人数,判断是否所 ...

  8. HDU - 3605 Escape (缩点+最大流/二分图多重匹配)

    题意:有N(1<=N<=1e5)个人要移民到M(1<=M<=10)个星球上,每个人有自己想去的星球,每个星球有最大承载人数.问这N个人能否移民成功. 分析:可以用最大流的思路求 ...

  9. hdu 4099 Revenge of Fibonacci 大数+压位+trie

    最近手感有点差,所以做点水题来锻炼一下信心. 下周的南京区域赛估计就是我的退役赛了,bless all. Revenge of Fibonacci Time Limit: 10000/5000 MS ...

随机推荐

  1. 二叉查找树(查找、插入、删除)——C语言

    二叉查找树 二叉查找树(BST:Binary Search Tree)是一种特殊的二叉树,它改善了二叉树节点查找的效率.二叉查找树有以下性质: (1)若左子树不空,则左子树上所有节点的值均小于它的根节 ...

  2. .NETCoreCSharp 中级篇2-3 Linq简介

    .NETCoreCSharp 中级篇2-3 本节内容为Linq及其拓展方法.Linq中表达式树的使用 简介 语言集成查询(LINQ)是一系列直接将查询功能集成到C#语言的技术统称.数据查询历来都表示为 ...

  3. 【Java例题】5.3 字符统计

    3.分别统计一个字符串中大写字母.小写字母.数字. 汉字以及其它字符的个数. package chapter5; import java.util.Scanner; public class demo ...

  4. Apache 80端口可以访问,8080却不可访问

    RT, 记录一下,后面看是否有解决方案.

  5. Tomcat源码分析 (二)----- Tomcat整体架构及组件

    前言 Tomcat的前身为Catalina,而Catalina又是一个轻量级的Servlet容器.在美国,catalina是一个很美的小岛.所以Tomcat作者的寓意可能是想把Tomcat设计成一个优 ...

  6. Letters Shop

    B. Letters Shop time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  7. 【作品】超实用C++分数类

    引言 我们说,编程语言的精髓在于封装,而面向对象语言完胜面向过程语言的原因就是具有更好的可封装性,而C++就是这样的一种多范型语言,常用而复杂的工作完全不必在每一份源文件中重敲,就好像我们不需要自己手 ...

  8. C#使用代理IP发送请求

    https://www.cnblogs.com/benbenfishfish/p/5830149.html   获取可代理的IP https://www.cnblogs.com/ShalenChe/p ...

  9. Java Web基础面试题整理

    Tomcat的缺省端口是多少,怎么修改 tomcat默认缺省端口是8080 修改方法: 找到Tomcat目录下的conf文件夹 进入conf文件夹里面找到server.xml文件 打开server.x ...

  10. I firmly believe

    I firmly believe, what you plant now, you will harvest later.