Codeforces737E. Tanya is 5!
$n \leq 40$个人玩$m \leq 10$台游戏机,每台游戏机一秒内只能一人玩,每人一秒内只能玩一台。每台游戏机有个价格,在规定总价格内可以把一部分游戏机复制一次,每台只能复制一次。给每个人对在每台游戏机上的需求时间,求一种方案使得所有玩游戏结束的时间尽量早。每个人每台游戏需求时间$\leq 2500$。
先不考虑复制。$R_i$表示人$i$玩游戏总时间,$C_j$表示机器$j$被玩总时间。可以发现答案的下界是$max(max(R_i),max(C_j))$,叫$T$。然后把人和机器建一个二分图,保证每个点的度数为$T$,就能在上面不停地做最大匹配,就可以把答案定为$T$。这里这么搞:左边$n$个人和$m$个假人,右边$m$台机器和$n$个假机器,假的东西用来补度数。然后,两边会连四种边:(1)真人真机器,连很多条边,边数为对应时间(其实可以连一条边记一个边权);(2)假人真机器,如果那个机器的度数不到$T$,那它肯定有一段空闲时间为$T-C_j$,这么多条边连向他对应的假人;(3)真人假机器,同(2);(4)假人假机器,这时假人和假机器的度数不到$T$,可以把真人真机器的图复制一遍把每个点度数补到$T$。把“连很多条边”搞成“连一条边,记个边权”,每次做完最大匹配后把所有边权减去匹配边中最小的那一个,然后把边权为0的边删掉。此时如果一条匹配边左右两边都是真人真机器,把这个操作记录下来,以此输出方案。
然后是钱的问题。当$T$为某个$C_j$时钱有用,此时若有钱就复制他,把机器的被玩时间均分成两份,使得$T$变小。
//#include<iostream>
#include<cstring>
#include<cstdio>
//#include<time.h>
//#include<complex>
//#include<set>
//#include<queue>
//#include<vector>
#include<algorithm>
#include<stdlib.h>
using namespace std; #define LL long long
int qread()
{
char c; int s=,f=; while ((c=getchar())<'' || c>'') (c=='-') && (f=-);
do s=s*+c-''; while ((c=getchar())>='' && c<=''); return s*f;
} //Pay attention to '-' , LL and double of qread!!!! int n,m,B;
int a[],t[][],R[],C[]; bool co[];
struct Node{int a,b,c,d;}ans[]; int lans=; struct BG
{
int mp[][],p[],q[],n; bool vis[];
void clear(int N) {n=N;}
bool Pei(int x)
{
vis[x]=;
for (int i=;i<=n;i++) if (mp[x][i] && !q[i])
{
p[x]=i; q[i]=x;
return ;
}
for (int i=;i<=n;i++) if (mp[x][i] && q[i] && !vis[q[i]] && Pei(q[i]))
{
p[x]=i; q[i]=x;
return ;
}
return ;
}
void pei(int x) {memset(vis,,sizeof(vis)); Pei(x);}
}g; int main()
{
n=qread(); m=qread(); B=qread();
for (int i=;i<=m;i++) a[i]=qread();
for (int i=,x;i<=n;i++)
{
x=qread();
for (int j=,u,v;j<=x;j++)
{
u=qread(); v=qread();
t[i][u]=v;
}
} for (int i=;i<=n;i++)
for (int j=;j<=m;j++)
R[i]+=t[i][j],C[j]+=t[i][j];
int T=,maxr=;
for (int i=;i<=n;i++) maxr=max(maxr,R[i]);
for (int j=;j<=m;j++) T=max(T,C[j]); T=max(T,maxr);
while (B)
{
int id=;
for (int j=;j<=m;j++) if (T==C[j] && co[j]) {id=-; break;}
if (id==-) break;
for (int j=;j<=m;j++) if (T==C[j]) {id=j; break;}
if (!id) break;
if (a[id]>B) break; int tot=T>>;
for (int i=;i<=n;i++)
{
if (tot<t[i][id]) {t[i][id+m]=tot; t[i][id]-=tot; break;}
else {tot-=t[i][id]; t[i][id+m]=t[i][id]; t[i][id]=;}
} co[id]=; B-=a[id];
C[id]=; for (int i=;i<=n;i++) C[id]+=t[i][id];
C[id+m]=; for (int i=;i<=n;i++) C[id+m]+=t[i][id+m];
T=; for (int j=;j<=m;j++) T=max(T,C[j]); T=max(T,maxr);
} g.clear(n+m+m);
for (int i=;i<=n;i++)
for (int j=;j<=m+m;j++) if (t[i][j])
g.mp[i][j]=g.mp[j+n][i+m+m]=t[i][j];
for (int i=;i<=n;i++) if (R[i]<T) g.mp[i][i+m+m]=T-R[i];
for (int j=;j<=m+m;j++) if (C[j]<T) g.mp[j+n][j]=T-C[j]; printf("%d\n",T);
for (int j=;j<=m;j++) printf("%d",co[j]); puts("");
lans=;
for (int i=;i<=n+m+m;i++) g.pei(i);
while (T)
{
int tmp=0x3f3f3f3f;
for (int i=;i<=n+m+m;i++) tmp=min(tmp,g.mp[i][g.p[i]]);
for (int i=;i<=n;i++) if (g.p[i]<=m+m)
ans[++lans]=(Node){i,g.p[i]<=m?g.p[i]:g.p[i]-m,T-tmp,tmp};
for (int i=;i<=n+m+m;i++) g.mp[i][g.p[i]]-=tmp;
for (int i=;i<=n+m+m;i++) if (g.mp[i][g.p[i]]==) {g.q[g.p[i]]=; g.p[i]=; g.pei(i);}
T-=tmp;
} printf("%d\n",lans);
for (int i=;i<=lans;i++) printf("%d %d %d %d\n",ans[i].a,ans[i].b,ans[i].c,ans[i].d);
return ;
}
Codeforces737E. Tanya is 5!的更多相关文章
- CodeForces 518B. Tanya and Postcard
B. Tanya and Postcard time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- codeforces 518B. Tanya and Postcard 解题报告
题目链接:http://codeforces.com/problemset/problem/518/B 题目意思:给出字符串 s 和 t,如果 t 中有跟 s 完全相同的字母,数量等于或者多过 s,就 ...
- Codeforces Round #288 (Div. 2)D. Tanya and Password 欧拉通路
D. Tanya and Password Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/508 ...
- CF Tanya and Postcard
Tanya and Postcard time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #324 (Div. 2) B. Kolya and Tanya 快速幂
B. Kolya and Tanya Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/pro ...
- CodeForces - 508D Tanya and Password(欧拉通路)
Description While dad was at work, a little girl Tanya decided to play with dad characters. She has ...
- Codeforces Round #346 (Div. 2) C Tanya and Toys
C. Tanya and Toys 题目链接http://codeforces.com/contest/659/problem/C Description In Berland recently a ...
- 2016NEFU集训第n+3场 G - Tanya and Toys
Description In Berland recently a new collection of toys went on sale. This collection consists of 1 ...
- codeforce round#466(div.2) B. Our Tanya is Crying Out Loud
B. Our Tanya is Crying Out Loud time limit per test1 second memory limit per test256 megabytes input ...
随机推荐
- HTML5<picture>元素
HTML5<picture>元素可以设置多张图片 <!DOCTYPE html><html><head><meta http-equiv=&quo ...
- 如何禁用Visual Studio的Browser Link功能
在Web.Config的AppSetting节点添加<add key="vs:EnableBrowserLink" value="false"/>
- 【贪心 思维题】[USACO13MAR]扑克牌型Poker Hands
看似区间数据结构的一道题 题目描述 Bessie and her friends are playing a unique version of poker involving a deck with ...
- django第五天(虚拟环境安装和视图层相关)
django第5天 虚拟环境安装 ''' 1.通过pip3安装虚拟环境: -- pip3 install virtualenv 2.前往目标文件夹: -- cd 目标文件夹 (C:\Virtualen ...
- The North American Invitational Programming Contest 2018 E. Prefix Free Code
Consider nn initial strings of lower case letters, where no initial string is a prefix of any other ...
- 163 AJAX
// 163 AJAX Tab // update 2006.10.18 // 增加鼠标延迟感应特性. // update 2006.10.8 // A 标签 href 属性将保持原有HTML功能.增 ...
- 【LeetCode】Intersection of Two Linked Lists(相交链表)
这道题是LeetCode里的第160道题. 题目讲的: 编写一个程序,找到两个单链表相交的起始节点. 如下面的两个链表: 在节点 c1 开始相交. 示例 1: 输入:intersectVal = 8, ...
- 【LeetCode】Count and Say(报数)
这道题是LeetCode里的第38道题. 题目要求: 报数序列是一个整数序列,按照其中的整数的顺序进行报数,得到下一个数.其前五项如下: 1. 1 2. 11 3. 21 4. 1211 5. 111 ...
- Leetcode 400.第n个数
第n个数 在无限的整数序列 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...中找到第 n 个数字. 为整形范围内 ( n < 231). 示例 1: 输入: 3 输出 ...
- pytorch中Math operation操作:torch.ger()
torch.ger(vec1, vec2, out=None) → Tensor Outer product of vec1 and vec2. If vec1 is a vector of size ...