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 ...
随机推荐
- VS2012减负:加快启动速度,减少编辑卡壳
我公司的笔记本配置如下: CPU:i5-3210M @ 2.50 GHz 2.50 GHz mem: 4.00 GB OS: 64bit Win7 用VS2012编译Cocos2d-X项目时非常的卡. ...
- ICMP协议
1. ICMP简介: ICMP全名为(INTERNET CONTROL MESSAGE PROTOCOL)网络控制报文协议,协议号为1,网络层协议. 它是TCP/IP协议族的一个子协议,用于在IP主机 ...
- Android自定义Notification并没有那么简单
背景 最近需要实现一个自定义Notification的功能.网上找了找代码,解决方案就是通过RemoteViews来实现.但是在实现过程中遇到不少问题,网上也没有很好的文章描述这些问题,所以在这里做个 ...
- Android 中 SQLite 性能优化
数据库是应用开发中常用的技术,在Android应用中也不例外.Android默认使用了SQLite数据库,在应用程序开发中,我们使用最多的无外乎增删改查.纵使操作简单,也有可能出现查找数据缓慢,插入数 ...
- 关于oracle的函数,存储过程,触发器,序列,视图,左右连接一些的应用 带案例
CREATE TABLE STUDENT( --创建学生表 ID NUMBER(10) PRIMARY KEY, --主键ID NAME VARCHAR2(20), CLASSNAME VA ...
- day01-day04总结- Python 数据类型及其用法
Python 数据类型及其用法: 本文总结一下Python中用到的各种数据类型,以及如何使用可以使得我们的代码变得简洁. 基本结构 我们首先要看的是几乎任何语言都具有的数据类型,包括字符串.整型.浮点 ...
- HTML select 操作
今天遇到一个问题,就是想设置select的默认选择项.但是试了很多方法都不行: <fieldset data-role="contractstatus"> <la ...
- Oracle 左连接、右连接、全外连接、(+)号作用、inner join(等值连接) (转载)
Oracle 外连接 (1)左外连接 (左边的表不加限制) (2)右外连接(右边的表不加限制) (3)全外连接(左右两表都不加限制) 外连接(Outer Join) oute ...
- servlet 项目 ,,启动没问题,,但是,一请求也面就报错误。。。。求解决。。。。。。。。。。。。。各种百度,都没解决了啊。。。。。急急急急急急急急急急急急急急急急急急
信息: Server startup in 1674 mslog4j:WARN No appenders could be found for logger (com.mchange.v2.log.M ...
- 11g 创建asm磁盘组
[root@Oracle11g ~]# fdisk -l Disk /dev/sda: 21.4 GB, 21474836480 bytes255 heads, 63 sectors/track, 2 ...