题目描述

Taro is a student of Ibaraki College of Prominent Computing. In this semester, he takes two courses, mathematics and informatics. After each class, the teacher may assign homework. Taro may be given multiple assignments in a single class, and each assignment may have a different deadline. Each assignment has a unique ID number.

Everyday after school, Taro completes at most one assignment as follows. first, he decides which course’s homework to do at random by flipping a coin. Let S be the set of all the unfinished assignments of the chosen course whose deadline has not yet passed. If S is empty, he plays a video game without doing any homework on that day even if there are unfinished assignments of the other course. Otherwise, with T ⊆ S being the set of assignments with the nearest deadline among S, he completes the one with the smallest assignment ID among T.

The number of assignments Taro will complete until the end of the semester depends on the result of coin flips. Given the schedule of homework assignments, your task is to compute the maximum and the minimum numbers of assignments Taro will complete.

输入

The input consists of a single test case in the following format.

n m

s1 t1

.

.

.

sn tn

The first line contains two integers n and m satisfying 1 ≤ m < n ≤ 400. n denotes the total number of assignments in this semester, and m denotes the number of assignments of the mathematics course (so the number of assignments of the informatics course is n − m).

Each assignment has a unique ID from 1 to n; assignments with IDs 1 through m are those of the mathematics course, and the rest are of the informatics course. The next n lines show the schedule of assignments. The i-th line of them contains two integers si and ti satisfying 1 ≤ si ≤ ti ≤ 400, which means that the assignment of ID i is given to Taro on the si-th day of the semester, and its deadline is the end of the ti-th day.

输出

In the first line, print the maximum number of assignments Taro will complete. In the second line, print the minimum number of assignments Taro will complete.

样例输入

6 3

1 2

1 5

2 3

2 6

4 5

4 6

样例输出

6

2


不得不说,日本人的英语真难懂.

题意很简单,就是你有两项作业,一个是数学,一个是信息学,以及布置时间和结束时间。你每天就做一项,然后是抛硬币选作业。假如说你数学做完了,信息学作业还没写,但是天意告诉你要学数学,于是乎你打起了游戏。

  • 完成的最多:

    知道起始时间,用贪心做,先做快结束的。单调队列维护。
  • 完成的最少:

    就是这天你数学作业写完了,信息学作业还没写,但是天意告诉你要学数学。建图:跑网络流

sic->数学作业 f=1

数学作业->天 f=1

天->天 拆点 f=1

天->信息作业 f=1

信息作业->sink f=1

这就意味着如果这天你如果只有一项作业,那就不写

有两项 那就写一项。

  • 为什么拆点? 这样就限制了一天只写一份作业。
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e5+7;
const int maxm=1e6+7;
int n,m,src,sink;
int head[maxn],tol=1,ans;
int cur[maxn],dep[maxn];
const int inf=0x3f3f3f3f;
struct Edge{int to,next,val;}e[maxm];
struct node{int s,t;}s[maxn];
void add(int u,int v,int f){
tol++;
e[tol].to=v;
e[tol].next=head[u];
e[tol].val=f;
head[u]=tol;
}
bool bfs(int s,int t){
queue<int>q;
memset(dep,-1,sizeof(dep));
q.push(s);
dep[s]=0;
while(!q.empty()){
int now=q.front();
q.pop();
for(int v,i=head[now];i;i=e[i].next){
v=e[i].to;
if(dep[v]==-1&&e[i].val){
dep[v]=dep[now]+1;
if(v==t) return true;
q.push(v);
}
}
}
return false;
}
int dfs(int x,int maxx){
if(x==sink) return maxx;
for(int& i=cur[x];i;i=e[i].next){
if(dep[e[i].to]==dep[x]+1&&e[i].val){
int flow=dfs(e[i].to,min(maxx,e[i].val));
if(flow){
e[i].val-=flow;
e[i^1].val+=flow;
return flow;
}
}
}
return 0;
}
void dinic(int s,int t){
ans=0;
while(bfs(s,t)){
for(int i=0;i<=t;i++) cur[i]=head[i];
while(int d=dfs(s,inf)) ans+=d;
}
}
bool cmp(node a,node b)
{
return a.s<b.s;
}
int main()
{
int n,math;
scanf("%d%d",&n,&math);
src=0;
sink=1201;
for(int i=1;i<=math;i++){
scanf("%d%d",&s[i].s,&s[i].t);
add(src,i,1);
add(i,src,0);
for(int j=s[i].s;j<=s[i].t;j++){
add(i,j+400,1);
add(j+400,i,0);
}
}
for(int i=1;i<=400;i++){
add(i+400,i+800,1);
add(i+800,i+400,0);
}
for(int i=math+1;i<=n;i++){
scanf("%d%d",&s[i].s,&s[i].t);
add(i,sink,1);
add(sink,i,0);
for(int j=s[i].s;j<=s[i].t;j++){
add(j+800,i,1);
add(i,j+800,0);
}
}
priority_queue<int, vector<int>, greater<int> > Q;
sort(s+1,s+n+1,cmp);
int now=1,ans1=0;
for(int i=1;i<=400;i++){
while(now<=n&&i==s[now].s) {Q.push(s[now].t);now++;}
if(!Q.empty()&&i<=Q.top()){Q.pop();ans1++;}
while(!Q.empty()&&i>=Q.top()){Q.pop();}
}
dinic(src,sink);
printf("%d\n",ans1);
printf("%d\n",ans);
return 0;
}

【网络流+贪心】Homework的更多相关文章

  1. 洛谷P1251 餐巾(网络流)

    P1251 餐巾 15通过 95提交 题目提供者该用户不存在 标签网络流贪心 难度提高+/省选- 提交该题 讨论 题解 记录 最新讨论 为什么我全部10个测试点都对… 题目描述 一个餐厅在相继的N天里 ...

  2. woj1008feedinganimals2-贪心-网络流

    title: woj1008feedinganimals2-贪心-网络流 date: 2020-03-07 categories: acm tags: [acm,woj,网络流,贪心] 中等题. 标准 ...

  3. bzoj3661

    网络流/贪心 网络流做法是对于每一列,如果一个兔子下一天继续可以存在,那么连一条容量为1的边,然后设立一个中转站,来控制可以换的数量,容量限制l.时限100s,能跑过去我的太慢了,一个点100s 正解 ...

  4. HDU 1789 Doing Homework again(贪心)

    Doing Homework again 这只是一道简单的贪心,但想不到的话,真的好难,我就想不到,最后还是看的题解 [题目链接]Doing Homework again [题目类型]贪心 & ...

  5. 【CodeForces 589F】Gourmet and Banquet(二分+贪心或网络流)

    F. Gourmet and Banquet time limit per test 2 seconds memory limit per test 512 megabytes input stand ...

  6. HDU 1789 Doing Homework again(贪心)

    在我上一篇说到的,就是这个,贪心的做法,对比一下就能发现,另一个的扣分会累加而且最后一定是把所有的作业都做了,而这个扣分是一次性的,所以应该是舍弃扣分小的,所以结构体排序后,往前选择一个损失最小的方案 ...

  7. hdu--1798--Doing Homework again(贪心)

    Doing Homework again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  8. ACM-ICPC 2018 沈阳赛区网络预赛 F Fantastic Graph(贪心或有源汇上下界网络流)

    https://nanti.jisuanke.com/t/31447 题意 一个二分图,左边N个点,右边M个点,中间K条边,问你是否可以删掉边使得所有点的度数在[L,R]之间 分析 最大流不太会.. ...

  9. 【BZOJ3716】[PA2014]Muzeum(贪心,网络流)

    [BZOJ3716][PA2014]Muzeum(贪心,网络流) 题面 BZOJ 题解 很明显可以写最大权闭合子图,然后会\(TLE\)成傻逼. 为了方便,就把一个警卫能够看到的范围处理一下(把坐标系 ...

随机推荐

  1. VUE.js入门学习(2)-基础精讲

    1.VUE 实例 - 一个项目是有很多的vue实例拼装的.每一个组建就是vue的实例. var vm = new Vue() 2.VUE 实例生命周期钩子 生命周期函数:VUE实例在某一个时间点会自动 ...

  2. SeetaFaceQt:写一个简单的界面

    关于这个界面,我用到了几个控件,这些控件通过Qt是非常容易构建的,窗口的话用的是QWidget,之前说了,QWidget是Qt里面几乎大部分控件的父类,QWidget的布局我使用了简单的水平布局(QH ...

  3. nginx下第一次使用thinkphp5遇到的坑

    最近面试php很多都在问会不会tp5所以借机了解了一下,刚在本地搭建了个就遇到了问题. 这里总结一下: 问题1.tp5+nginx=500 internal server error 我用的是phps ...

  4. Django2.0——Form组件简单总结

    Django提供了一个Form组件来配和前端的表单进行使用,Form有两个强大的功能,分别是生成HTML代码和验证数据的合法性.通常我们不会用其第一个功能,因为前端的设计可以做出更加精美且多样的表单页 ...

  5. Centos配置NAT模式下的静态ip

    一.查看所在的ip段 点击 编辑-->虚拟网卡编辑器 选中vmware8网卡,点击 DHCP设置 二.编辑网卡配置文件 查看网卡 ip addr 命令打开配置文件 vi /etc/sysconf ...

  6. 基于SSM开发在线考试系统 Java源码

    实现的关于在线考试的功能有:用户前台:用户注册登录.查看考试信息.进行考试.查看考试成绩.查看历史考试记录.回顾已考试卷.修改密码.修改个人信息等,后台管理功能(脚手架功能不在这里列出),科目专业管理 ...

  7. spring hystrix和内置tomcat组件的参数调优解析

    1. springboot内置tomcat容器的参数配置 server: port: 12021 # server端的socket超时间(毫秒),使用值-1表示没有(即无限)超时,默认值为60000( ...

  8. 京东云数据库RDS SQL Server高可用概述

    数据库的高可用是指在硬件.软件故障发生时,可以将业务从发生故障的数据库节点迁移至备用节点.本文主要讲述SQL Server高可用方案,以及京东云RDS数据库的高可用实现. 一.高可用解决方案总览 1. ...

  9. JavaScript mixins

    mixin 是一个类,该类的方法被添加,混合进另外一个类.一个基础类会包含mixin类的方法而不是继承它.这样你就可以使用不同的mixin类来增加或者增强基础类的功能. 这编内容包含怎么样使用java ...

  10. oracle学习笔记(六)——函数&存储过程的异同

    我看的书上除了能看出来函数有返回值,存储过程没有,其他啥也看不出来... 网上大大的总结