CH Round #51 - Shinrein祭 #1
A.Phorni
题目:http://www.contesthunter.org/contest/CH%20Round%20%2351%20-%20Shinrein祭%20%231/Phorni
没做。。。
B.Arietta
题目:http://www.contesthunter.org/contest/CH%20Round%20%2351%20-%20Shinrein祭%20%231/Arietta
想到了网络流,所以每次暴力算出哪些点能被弹奏,就从这次弹奏向哪些点连容量为1的边
最后由s向所有力度连容量为该力度最多能被弹多少次的边,由每个节点连t容量为1的边
求最大流,得到了暴力分30分。正解还不会
代码:
const inf=maxlongint;maxn=+;maxm=;
type node=record
go,next,v:longint;
end;
var tot,i,n,m,maxflow,l,r,s,t,x,y,tot2:longint;
h,head,head2,q,cur,v:array[..maxn] of longint;
e:array[..maxm] of node;
e2:array[..maxn] of node;
function min(x,y:longint):longint;
begin
if x<y then exit(x) else exit(y);
end;
procedure ins(x,y,z:longint);
begin
inc(tot);
e[tot].go:=y;e[tot].v:=z;e[tot].next:=head[x];head[x]:=tot;
end;
procedure insert(x,y,z:longint);
begin
ins(x,y,z);ins(y,x,);
end;
function bfs:boolean;
var i,x,y:longint;
begin
fillchar(h,sizeof(h),);
l:=;r:=;q[]:=s;h[s]:=;
while l<r do
begin
inc(l);
x:=q[l];
i:=head[x];
while i<> do
begin
y:=e[i].go;
if (e[i].v<>) and (h[y]=) then
begin
h[y]:=h[x]+;
inc(r);q[r]:=y;
end;
i:=e[i].next;
end;
end;
exit (h[t]<>);
end;
function dfs(x,f:longint):longint;
var i,y,used,tmp:longint;
begin
if x=t then exit(f);
used:=;
i:=cur[x];
while i<> do
begin
y:=e[i].go;
if (h[y]=h[x]+) and (e[i].v<>) then
begin
tmp:=dfs(y,min(e[i].v,f-used));
dec(e[i].v,tmp);if e[i].v<> then cur[x]:=i;
inc(e[i xor ].v,tmp);
inc(used,tmp);
if used=f then exit(f);
end;
i:=e[i].next;
end;
if used= then h[x]:=-;
exit(used);
end;
procedure dinic;
var i:longint;
begin
while bfs do
begin
for i:=s to t do cur[i]:=head[i];
inc(maxflow,dfs(s,inf));
end;
end;
procedure insert2(x,y:longint);
begin
inc(tot2);
e2[tot2].go:=y;e2[tot2].next:=head2[x];head2[x]:=tot2;
end;
procedure init;
begin
tot:=;
readln(n,m);
for i:= to n do begin read(x);insert2(x,i);end;readln;
for i:= to n do read(v[i]);readln;
end;
procedure dfss(x:longint);
var j,y:longint;
begin
if (v[x]>=l) and (v[x]<=r) then insert(i,x,);
j:=head2[x];
while j<> do
begin
y:=e2[j].go;
dfss(y);
j:=e2[j].next;
end;
end; procedure main;
begin
s:=;t:=n+m+;
for i:= to n do insert(i,t,);
for i:=n+ to n+m do
begin
readln(l,r,x,y);
insert(s,i,y);
dfss(x);
end;
maxflow:=;
dinic;
writeln(maxflow);
end; begin
init;
main;
end.
C。Falsita
题目:http://www.contesthunter.org/contest/CH%20Round%20%2351%20-%20Shinrein祭%20%231/Falsita
我下午刚做了POI的大都市,然后看到这题的对子树的修改就想到了用dfs序+线段树懒惰标记的做法,
最后回答的时候我是O(该点分叉数)求出总数,再用同样时间复杂度的时间求出总代价,使用子树和算的
我想出题人的要求回答询问的该点的分叉树一定很多,就会卡我到超时,结果真是的。。。
于是我又很愉快的拿到了30分。。。正解还不会
代码:
const maxn=+;
type node=record
go,next:longint;
end;
node2=record
l,r,lch,rch,mid,tag,sum:int64;
end;
var e:array[..*maxn] of node;
t:array[..*maxn] of node2;
head,l,r,s,a,b:array[..*maxn] of longint;
i,n,m,x,y,tot,clock:longint;
ch:char;
procedure insert(x,y:longint);
begin
inc(tot);
e[tot].go:=y;e[tot].next:=head[x];head[x]:=tot;
end;
procedure dfs(x:longint);
var i,y:longint;
begin
inc(clock);l[x]:=clock;a[clock]:=x;
i:=head[x];
while i<> do
begin
y:=e[i].go;
dfs(y);
i:=e[i].next;
end;
inc(clock);r[x]:=clock;a[clock]:=x;
end;
procedure pushup(k:longint);
begin
with t[k] do
begin
sum:=t[lch].sum+t[rch].sum;
end;
end;
procedure build(k,x,y:longint);
begin
with t[k] do
begin
l:=x;r:=y;mid:=(l+r)>>;lch:=k<<;rch:=k<<+;tag:=;
if l=r then begin sum:=b[a[l]];exit;end;
build(lch,l,mid);build(rch,mid+,r);
pushup(k);
end;
end;
procedure update(k:longint;val:int64);
begin
with t[k] do
begin
inc(tag,val);
inc(sum,(r-l+)*val);
end;
end;
procedure pushdown(k:longint);
begin
with t[k] do
begin
if tag= then exit;
update(lch,tag);update(rch,tag);
tag:=;
end;
end;
procedure change(k,x,y:longint);
begin
with t[k] do
begin
if l=r then begin inc(sum,y);exit;end;
pushdown(k);
if x<=mid then change(lch,x,y) else change(rch,x,y);
pushup(k);
end;
end;
procedure change2(k,x,y:longint;z:int64);
begin
with t[k] do
begin
if (l=x) and (r=y) then
begin
update(k,z);exit;
end;
pushdown(k);
if y<=mid then change2(lch,x,y,z)
else if x>mid then change2(rch,x,y,z)
else
begin
change2(lch,x,mid,z);
change2(rch,mid+,y,z);
end;
pushup(k);
end;
end;
function query(k,x,y:longint):int64;
begin
with t[k] do
begin
if (l=x) and (r=y) then exit(sum);
pushdown(k);
if y<=mid then exit(query(lch,x,y))
else if x>mid then exit(query(rch,x,y))
else exit(query(lch,x,mid)+query(rch,mid+,y));
end;
end;
procedure init;
begin
readln(n,m);
for i:= to n do begin read(x);insert(x,i);end;readln;
for i:= to n do read(b[i]);readln;
dfs();
build(,,*n);
for i:= to n do s[i]:=(r[i]-l[i]+)>>;
end;
procedure getans;
var ans:double;
a,b,c:array[..maxn] of int64;
i,x,y,cnt:longint;
tot:int64;
begin
readln(x);a[]:=x;b[]:=s[x];c[]:=trunc(query(,l[x],r[x])/);
cnt:=;
i:=head[x];
while i<> do
begin
y:=e[i].go;
inc(cnt);
a[cnt]:=y;b[cnt]:=s[y];c[cnt]:=trunc(query(,l[y],r[y])/);
dec(c[],c[cnt]);
i:=e[i].next;
end;
tot:=b[]-;
for i:= to cnt do inc(tot,b[i]*(b[]-b[i]));
tot:=tot>>;
ans:=c[]*(b[]-)/tot;
for i:= to cnt do ans:=ans+c[i]*(b[]-b[i])/tot;
writeln(ans::);
end;
procedure main;
begin
for i:= to m do
begin
read(ch);
case ch of
'S':begin
readln(x,y);
change(,l[x],y);change(,r[x],y);
end;
'M':begin
readln(x,y);
change2(,l[x],r[x],y);
end;
'Q':getans;
end;
end;
end;
begin
init;
main;
end.
CH Round #51 - Shinrein祭 #1的更多相关文章
- CH Round #52 还教室[线段树 方差]
还教室 CH Round #52 - Thinking Bear #1 (NOIP模拟赛) [引子]还记得 NOIP 2012 提高组 Day2 中的借教室吗?时光飞逝,光阴荏苒,两年过去了,曾经借教 ...
- CH Round #72树洞[二分答案 DFS&&BFS]
树洞 CH Round #72 - NOIP夏季划水赛 描述 在一片栖息地上有N棵树,每棵树下住着一只兔子,有M条路径连接这些树.更特殊地是,只有一棵树有3条或更多的路径与它相连,其它的树只有1条或2 ...
- CH Round #30 摆花[矩阵乘法]
摆花 CH Round #30 - 清明欢乐赛 背景及描述 艺术馆门前将摆出许多花,一共有n个位置排成一排,每个位置可以摆花也可以不摆花.有些花如果摆在相邻的位置(隔着一个空的位置不算相邻),就不好看 ...
- contesthunter CH Round #64 - MFOI杯水题欢乐赛day1 solve
http://www.contesthunter.org/contest/CH Round %2364 - MFOI杯水题欢乐赛 day1/Solve Solve CH Round #64 - MFO ...
- CH Round #17 舞动的夜晚
舞动的夜晚 CH Round #17 描述 L公司和H公司举办了一次联谊晚会.晚会上,L公司的N位员工和H公司的M位员工打算进行一场交际舞.在这些领导中,一些L公司的员工和H公司的员工之间是互相认识的 ...
- CH Round #45 能量释放
能量释放 CH Round #45 - alan有一些陷阱 III 题目描述 alan得到一块由个能量晶体构成的矿石,对于矿石中的每一个能量晶体,如果用化学物质刺激某一个能量晶体,就能使它释放能量. ...
- CH Round #57 - Story of the OI Class 凯撒密码
很有意思的一道题目 考场上想的是HASH成一个整数,把末位asicc码值*1,依次乘*10,得到一个整数,然后利用等差性.唯一性快排Nlogn乱搞的 证明如下: 对于明文abcde 密文 bcdef ...
- 判素数+找规律 BestCoder Round #51 (div.2) 1001 Zball in Tina Town
题目传送门 /* 题意: 求(n-1)! mod n 数论:没啥意思,打个表能发现规律,但坑点是4时要特判! */ /***************************************** ...
- BestCoder Round #51 (div.2)
明显是无良心的数学round= = 1000 Zball in Tina Town #include<iostream> #include<cstdio> #include&l ...
随机推荐
- JavaScript函数的四种存在形态
函数的四种存在形态: 1.函数形态 2.方法形态 将函数赋值给某一个对象的成员,那么就称为方法 3.构造器形态 4.上下文形态 1.函数形态: var foo = function() { ale ...
- 编程基础-msdn编程指南笔记
此博仅为笔记,摘自msdn编程指南文档,链接地址:http://msdn.microsoft.com/zh-cn/library/67ef8sbd.aspx 注释:// 单行注释 /* 多行注释*/ ...
- .NET Core的介绍
ASP.NET5应用程序默认使用.net core来构建应用程序,.net core是一个小的,优化过的.net运行时应用程序. 1. 什么是的.NET Core .NET Core 5 是一由模块化 ...
- ASP.NET Web API 文件產生器 - 使用 Swagger
转帖:http://kevintsengtw.blogspot.hk/2015/12/aspnet-web-api-swagger.html Swagger 是一套 API 互動文件產生器,使用 HT ...
- xcode7 icon图标设置
- Linux fork操作之后发生了什么?又会共享什么呢?
今天我在阅读<Unix网络编程>时候遇到一个问题:accept返回时的connfd,是父子进程之间共享的?我当时很不理解,难道打开的文件描述符不是应该在父子进程间相互独立的吗?为什么是共享 ...
- Linux ./configure && make && make install 编译安装和卸载
正常的编译安装/卸载: 源码的安装一般由3个步骤组成:配置(configure).编译(make).安装(make install). configure文件是一个可执行的脚本文件,它有很多选项, ...
- PHP框架_ThinkPHP数据库
目录 1.ThinkPHP数据库配置 2.ThinkPHP数据库实例化模型 3.ThinkPHP数据库CURD操作 4.ThinkPHP数据库连贯操作 1.ThinkPHP数据库配置 App/Conf ...
- asp.net MVC 从其它项目复制过来的Area里面的Controllers文件读取不到
从其实项目复制过来的Controllers,在访问时显示不存在文件 检查一下对应的area里面的AreaRegistration文件的命名空间是否一致
- Java环境配置出现的问题及解决办法
我使用的安装文件,从博客园一个童鞋那里找到的,连接是http://www.cnblogs.com/SelectError/p/3205582.html#commentform 开发基础环境,版本为Ja ...