codecomb 2092【课程选择】
题目描述
大学选课总是烦恼着很多人。现在X同学选出了很多备选课,但是有的课程之间是有时间冲突的。X不会分身,自然无法在同一个时间上不同的课。每个课可能有很多备选时间,但是每个课只需要选一个时间上就可以了。当然X没有必要在不同时间上相同的课。
现在把X的备选课及相应的上课时间告诉你,请你求出X一星期最多可以上多少课。
输入格式
第一行输入一个n,表示X将提供给你n个备选课。
接下来n行,每行包含若干个整数来描述每个备选课信息。
对于第i行,首先读入一个k,表示第i个备选课有k个时间可以选择。接下来读入k对数p,q,表示在第i个备选课在星期p的第q节课可以上。
输出格式
输出仅包含一个整数,表示X最多可以选多少节课来上。
样例数据 1
备注
对于100%的数据:n<=300,1<=t<=84,1<=p<=7,1<=q<=12。
比第一题更裸的网络流
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
#define S 0
#define T 1000
using namespace std;
struct edge{
int to,next,v;
}e[200010];
int head[10010];
int n,m,cnt=1,t,w,ans;
int h[10010];
int q[100010];
inline void ins(int u,int v,int w)
{
e[++cnt].to=v;
e[cnt].v=w;
e[cnt].next=head[u];
head[u]=cnt;
}
inline void insert(int u,int v,int w)
{
ins(u,v,w);
ins(v,u,0);
}
inline bool bfs()
{
memset(h,-1,sizeof(h));
t=0;w=1;h[S]=0;q[1]=S;
while (t<w)
{
int now=q[++t];
for(int i=head[now];i;i=e[i].next)
if (e[i].v&&h[e[i].to]==-1)
{
h[e[i].to]=h[now]+1;
q[++w]=e[i].to;
}
}
if (h[T]==-1)return 0;
return 1;
}
inline int dfs(int x,int f)
{
if (x==T||!f)return f;
int used=0,w;
for (int i=head[x];i;i=e[i].next)
if (e[i].v&&h[e[i].to]==h[x]+1)
{
w=used;
w=dfs(e[i].to,min(e[i].v,f-w));
e[i].v-=w;
e[i^1].v+=w;
used+=w;
if (!f)return used;
}
if (!used)h[x]=-1;
return used;
}
inline void dinic()
{
while (bfs())ans+=dfs(S,inf);
}
inline LL read()
{
LL x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int main()
{
n=read();
for (int i=1;i<=n;i++)
insert(S,i,1);
for (int i=n+1;i<=n+84;i++)
insert(i,T,1);
for (int i=1;i<=n;i++)
{
int t=read();
for (int j=1;j<=t;j++)
{
int p=read(),q=read();
int tru=(p-1)*12+q;
insert(i,n+tru,1);
}
}
dinic();
printf("%d\n",ans);
}
codecomb 2092【课程选择】的更多相关文章
- C#实例,熟练使用泛型数组等,课程选择小软件
CourseItem.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; ...
- 利用javascript实现课程选择
最终实现的效果如下图所示: 代码如下所示: HTML代码部分: <body> <div class="page" style="overflow: hi ...
- [自学] MIT的EECS本科+研究生课程【持续更新中-2020.06.02】
前言 我的本科是读的电子信息工程,研究生跟着老师做项目,参与到深度学习中来,毕业后做了算法工程师,工作之后愈发发现,不论从事什么岗位,基础都很重要,但现在也没有时间再读一遍本科了,自学的话也不知道从何 ...
- 设计模式(十一)外观模式(Facade Pattern)
一.引言 在软件开发过程中,客户端程序经常会与复杂系统的内部子系统进行耦合,从而导致客户端程序随着子系统的变化而变化,然而为了将复杂系统的内部子系统与客户端之间的依赖解耦,从而就有了外观模式,也称作 ...
- C#设计模式-外观模式
在软件开发过程中,客户端程序经常会与复杂系统的内部子系统进行耦合,从而导致客户端程序随着子系统的变化而变化,然而为了将复杂系统的内部子系统与客户端之间的依赖解耦,从而就有了外观模式,也称作 ”门面“模 ...
- Working with Data » Getting started with ASP.NET Core and Entity Framework Core using Visual Studio » 更新关系数据
Updating related data¶ 7 of 7 people found this helpful The Contoso University sample web applicatio ...
- 第二次作业——C++学习
课程选择: 以往在自学的过程就比较留意一些自学的网站,所以这次"C++自学"感觉找课程还是比较轻松的. 因为之前网页等学习都是在慕课网(视频学习个人感觉有时挺费时间的,特别是有时以 ...
- 在线考试系统(Online Exam System)--ASP.NET
用户设计 -|学生 -|老师 -|管理员 学生结构设计 -|个人信息管理 -|修改个人信息 -|修改登录密码 -|选课中心 -|显示所有老师所开课的信息可进行选课 -|显示自己已选课程 -|在线考试 ...
- [渣译文] 使用 MVC 5 的 EF6 Code First 入门 系列:为ASP.NET MVC应用程序更新相关数据
这是微软官方教程Getting Started with Entity Framework 6 Code First using MVC 5 系列的翻译,这里是第八篇:为ASP.NET MVC应用程序 ...
随机推荐
- 极简AWR报告收集指导
1.以oracle用户登录oracle数据库,执行如下命令登录数据库: sqlplus / as sysdba 2.运行如下命令: @?/rdbms/admin/awrrpt.sql 3.出现如下信息 ...
- poj 3262 Protecting the Flowers 贪心
题意:给定n个奶牛,FJ把奶牛i从其位置送回牛棚并回到草坪要花费2*t[i]时间,同时留在草地上的奶牛j每分钟会消耗d[j]个草 求把所有奶牛送回牛棚内,所消耗草的最小值 思路:贪心,假设奶牛a和奶牛 ...
- hdu 5676 ztr loves lucky numbers(dfs+离线)
Problem Description ztr loves lucky numbers. Everybody knows that positive integers are lucky if the ...
- Gym Class(拓扑排序)
Gym Class Time Limit: 6000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total ...
- [AngualrJS] Using Angular-Cache for caching http request
Check the website: https://jmdobry.github.io/angular-cache/#using-angular-cache-with-http Install: n ...
- [HeadFist-HTMLCSS学习笔记][第七章CSS入门:加一点样式]
CSS入门 style元素设置CSS 基本格式 <style type="text/css"> body { background-color: #eaf3da; } ...
- Python 线程(threading) 进程(multiprocessing)
*:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...
- Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was made to load a program with an incorrect format.
I have installed a Web application on IIS 7.0 windows server 2008 R2 64 bit OS I am refering a oracl ...
- 初识Treap
Treap,简单的来说就是Tree+Heap,是一颗平衡树,每个节点有两个信息:1.key:当前节点的关键字 :2.fix:当前节点优先级.key满足二叉排序数的性质,即左儿子都比当前节点小,右儿子都 ...
- 指针参数的传递(节选 C++/C 高质量编程 林锐)
指针参数是如何传递内存的 如果函数的参数是一个指针,不要指望用该指针去申请动态内存.示例7-4-1中,Test函数的语句GetMemory(str, 200)并没有使str获得期望的内存,str依旧是 ...