Selecting Courses POJ - 2239(我是沙雕吧 按时间点建边 || 匹配水题)
呃呃呃呃呃
把每个课给了INF个容量。。。。我是沙雕把。。。。emm。。。。这题就是做着玩。。。呃呃呃别当真。。。。
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <cctype>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define rd(a) scanf("%d", &a)
#define rlld(a) scanf("%lld", &a)
#define rc(a) scanf("%c", &a)
#define rs(a) scanf("%s", a)
#define rb(a) scanf("%lf", &a)
#define rf(a) scanf("%f", &a)
#define pd(a) printf("%d\n", a)
#define plld(a) printf("%lld\n", a)
#define pc(a) printf("%c\n", a)
#define ps(a) printf("%s\n", a)
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = 1e5 + , INF = 0x7fffffff; int head[maxn], cur[maxn], d[maxn], nex[maxn << ];
int n, m, s, t;
int cnt; struct node
{
int u, v, c;
}Node[maxn << ]; void add_(int u, int v, int c)
{
Node[cnt].u = u;
Node[cnt].v = v;
Node[cnt].c = c;
nex[cnt] = head[u];
head[u] = cnt++;
} void add(int u, int v, int c)
{
add_(u, v, c);
add_(v, u, );
} bool bfs()
{
queue<int> Q;
mem(d, );
Q.push(s);
d[s] = ;
while(!Q.empty())
{
int u = Q.front(); Q.pop();
for(int i = head[u]; i != -; i = nex[i])
{
int v = Node[i].v;
if(!d[v] && Node[i].c > )
{
d[v] = d[u] + ;
Q.push(v);
if(v == t) return ;
}
}
}
return d[t] != ;
} int dfs(int u, int cap)
{
int ret = ;
if(u == t || cap == ) return cap;
for(int &i = cur[u]; i != -; i = nex[i])
{
int v = Node[i].v;
if(d[v] == d[u] + && Node[i].c > )
{
int V = dfs(v, min(Node[i].c, cap));
Node[i].c -= V;
Node[i ^ ].c += V;
ret += V;
cap -= V;
if(cap == ) break;
}
}
if(cap > ) d[u] = -;
return ret;
} int Dinic()
{
int ans = ;
while(bfs())
{
memcpy(cur, head, sizeof head);
ans += dfs(s, INF);
}
return ans;
} int main()
{
while(scanf("%d", &n) != EOF)
{
mem(head, -);
cnt = ;
int u, v;
s = , t = ;
rap(i, , n)
{
rd(m);
add(s, + i, );
rap(j, , m)
{
rd(u), rd(v);
add( + i, (u - ) * + v, );
}
}
rap(i, , )
add(i, t, );
cout << Dinic() << endl;
} return ;
}
Selecting Courses POJ - 2239(我是沙雕吧 按时间点建边 || 匹配水题)的更多相关文章
- POJ 1002 UVA 755 487--3279 电话排序 简单但不容易的水题
题意:给你许多串字符串,从中提取电话号码,输出出现复数次的电话号码及次数. 以下是我艰难的AC历程:(这题估计是我刷的题目题解次数排前的了...) 题目不是很难理解,刚开始想到用map,但stl的ma ...
- POJ 1936 All in All 匹配, 水题 难度:0
题目 http://poj.org/problem?id=1936 题意 多组数据,每组数据有两个字符串A,B,求A是否是B的子串.(注意是子串,也就是不必在B中连续) 思路 设置计数器cnt为当前已 ...
- POJ 3312 Mahershalalhashbaz, Nebuchadnezzar, and Billy Bob Benjamin Go to the Regionals (水题,贪心)
题意:给定 n 个字符串,一个k,让你把它们分成每组k个,要保证每组中每个字符串长度与它们之和相差不能超2. 析:贪心策略就是长度相差最小的放上块. 代码如下: #pragma comment(lin ...
- poj——2239 Selecting Courses
poj——2239 Selecting Courses Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10656 A ...
- poj 2239 Selecting Courses (二分匹配)
Selecting Courses Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8316 Accepted: 3687 ...
- POJ 2239:Selecting Courses 选课
Selecting Courses Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9380 Accepted: 4177 ...
- poj 2239 二分图最大匹配,基础题
1.poj 2239 Selecting Courses 二分图最大匹配问题 2.总结:看到一个题解,直接用三维数组做的,很巧妙,很暴力.. 题意:N种课,给出时间,每种课在星期几的第几节课上 ...
- [***]沙雕低错集(算起来因为低错挂掉的分快够我AK三场了……)
由于沙雕错太多了所以不想写了,看着就难受…… 各种沙雕错(自从上次考试开始各种犯沙雕低错……): !!!sort是不稳定的排序,如果排序结构题只按其中一个关键字排序,那么在关键字相等时,排序多次的结果 ...
- HDU 3697 Selecting courses(贪心)
题目链接:pid=3697" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=3697 Prob ...
随机推荐
- vue 饿了么项目笔记
vue 饿了么项目 1.图标字体引用 链接 2.scss 二三倍图切换 1像素边框 链接 3.better-scroll 4.布局 商品主页面 <div id="app"&g ...
- 第4次oo作业
作业概述 作业1:多项式加法 第一次作业理解上并不困难,简言之是一个多项式合并同类项,但对于我这个第一次使用java进行编程的小白,还是充满了血和泪. 在这次课程之前,我稍微对java有一些了解,但也 ...
- Python_每日习题_0007_copy
题目:将一个列表的数据复制到另一个列表中. 程序分析:使用列表[:],拿不准可以调用copy模块 import copy a = [,,,,['a','b']] b = a #赋值 c = a[:] ...
- hibernate坑边闲话
使用hibernate各种各样的坑 Remember that ordinal parameters are 1-based node to traverse cannot be null 这两个错误 ...
- NYOJ-16-矩形嵌套 记忆化搜索
#include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> ...
- c++入门之再次探讨类属性
精辟博文:https://blog.csdn.net/msdnwolaile/article/details/51923859(转载,仅供学习|!)
- 周末时间学习Linux
大家都是如何度过周末时光的呢?好多人都认为一周的工作后要好好休息下,于是在家疯狂的补觉,刷剧,打游戏,自我觉得很是正常,工作几天了,休息下不是当然嘛.是的,休息下很正常,但是把周末的时光都用到这些东西 ...
- Python_面向对象_单例模式
class A(object): pass a1 = A() a2 = A() print(a1 == a2)print(id(a1))print(id(a2)) 结果: False 23257231 ...
- 【Python3练习题 014】 一个数如果恰好等于它的因子之和,这个数就称为“完数”。例如6=1+2+3。编程找出1000以内的所有完数。
a.b只要数字a能被数字b整除,不论b是不是质数,都算是a的因子.比如:8的质因子是 2, 2, 2,但8的因子就包括 1,2,4. import math for i in range(2, 1 ...
- lumen 5.6 设置APP_KEY为32位长的随机字符串
在 App\Console\Commands下 添加以下内容的KeyGenerateCommand.php文件 <?php namespace App\Console\Commands; use ...