数据包:http://pan.baidu.com/s/1pJNSkL9

T1:

我们先直接用矩阵快速幂暴力

首先是0维,f1=1,f2=1

然后推出下一维的f1'和f2'

下一维的f1'和f2'其实就是f1+f2+f3+....+fn和f2+f3+f4+...+fn+1

所以f1'=sn,f2'=s(n+1)-f1

所以可以klogn求出答案

但是我们做了很多相同的事情,求sn和s(n+1)的时候求出来的矩阵是一样的

所以可以是logn+k的

但是既然是一样的其实f1,f2推到f1'和f2'是可以快速幂的

于是就变成了logn+logk的了

 const
h=;
type
matrix=array[..,..]of int64;
const
d:matrix=((,,),(,,),(,,));
var
n,k:int64;
t:longint;
a,b,c:matrix; operator *(a,b:matrix)c:matrix;
var
i,j,k:longint;
begin
fillchar(c,sizeof(c),);
for i:= to do
for j:= to do
for k:= to do
c[i,j]:=(c[i,j]+a[i,k]*b[k,j])mod h;
end; procedure main;
var
i:longint;
begin
read(n,k);
b:=d;
fillchar(a,sizeof(a),);
for i:= to do
a[i,i]:=;
while n> do
begin
if n and = then a:=a*b;
b:=b*b;
n:=n>>;
end;
b:=a*d;
fillchar(c,sizeof(c),);
c[,]:=a[,];
c[,]:=a[,];
c[,]:=(b[,]-+h)mod h;
c[,]:=b[,];
fillchar(a,sizeof(a),);
for i:= to do
a[i,i]:=;
while k> do
begin
if k and = then a:=a*c;
c:=c*c;
k:=k>>;
end;
writeln((a[,]+a[,])mod h);
end; begin
read(t);
while t> do
begin
dec(t);
main;
end;
end.

T2:

首先有一个结论,那个函数是递增的

然后我们可以证明这样一个结论

假设现在sg最大为k,那么现在最后k+1个sg组成的集合一定是0...k

若现在P[m]>=k+1,那么显然sg[m]=k+1

若现在P[m]=k,那么sg[m]=sg[m-k]

可以用数学归纳法证明

又因为maxsg<=10^5

于是就维护这个sg的序列

T3:

又是合并的思想

首先我们想一下什么情况父亲会和儿子合并(首先把不可能有收益的儿子删掉,且按最低血量限制排序)

若合并之后血量最低限制不变就一定要合并

若父亲现在没有收益就一定要合并

用可并堆或者启发式合并维护

大概就是这样,具体看solution

 const
maxn=;
inf=;
type
node=record
size,lc,rc,pay,gain:longint;
end;
var
first,next,last,d:array[..maxn*]of longint;
f:array[..maxn]of node;
n,t,time,tot:longint; procedure swap(var x,y:longint);
var
t:longint;
begin
t:=x;x:=y;y:=t;
end; procedure insert(x,y:longint);
begin
inc(tot);
last[tot]:=y;
next[tot]:=first[x];
first[x]:=tot;
end; function max(x,y:longint):longint;
begin
if x>y then exit(x);
exit(y);
end; function merge(a,b:longint):longint;
begin
if (a=) or (b=) then exit(a+b);
if f[b].pay<f[a].pay then swap(a,b);
f[a].rc:=merge(f[a].rc,b);
if f[f[a].rc].size>f[f[a].lc].size then swap(f[a].lc,f[a].rc);
f[a].size:=f[f[a].lc].size+f[f[a].rc].size+;
exit(a);
end; procedure dfs(x,fa:longint);
var
i:longint;
begin
i:=first[x];
d[x]:=;
while i<> do
begin
if last[i]<>fa then
begin
dfs(last[i],x);
d[x]:=merge(d[x],d[last[i]]);
end;
i:=next[i];
end;
while (d[x]<>) and ((f[x].pay>=f[d[x]].pay) or (f[x].gain-f[x].pay<=)) do
begin
if f[x].gain>=f[d[x]].pay then inc(f[x].gain,f[d[x]].gain-f[d[x]].pay)
else
begin
f[x].pay:=f[x].pay+f[d[x]].pay-f[x].gain;
f[x].gain:=f[d[x]].gain;
end;
d[x]:=merge(f[d[x]].lc,f[d[x]].rc);
end;
if f[x].gain-f[x].pay<= then d[x]:=
else d[x]:=merge(d[x],x);
end; procedure main;
var
i,x,y,hp:longint;
begin
fillchar(first,sizeof(first),);
tot:=;
read(n,t);
for i:= to n do
begin
read(f[i].gain);
if f[i].gain> then f[i].pay:=
else f[i].pay:=-f[i].gain;
if f[i].gain< then f[i].gain:=;
f[i].lc:=;
f[i].rc:=;
f[i].size:=;
end;
for i:= to n- do
begin
read(x,y);
insert(x,y);
insert(y,x);
end;
inc(n);
f[n].pay:=;
f[n].gain:=inf;
f[n].size:=;
f[n].lc:=;
f[n].rc:=;
insert(t,n);
insert(n,t);
dfs(,);
hp:=;
while d[]<> do
begin
if hp<f[d[]].pay then break;
inc(hp,f[d[]].gain-f[d[]].pay);
d[]:=merge(f[d[]].lc,f[d[]].rc);
end;
if hp>=inf then writeln('escaped')
else writeln('trapped');
end; begin
read(time);
while time> do
begin
dec(time);
main;
end;
end.

NOI2014 全国互测Round2的更多相关文章

  1. 【loj2461】【2018集训队互测Day 1】完美的队列

    #2461. 「2018 集训队互测 Day 1」完美的队列 传送门: https://loj.ac/problem/2461 题解: 直接做可能一次操作加入队列同时会弹出很多数字,无法维护:一个操作 ...

  2. 【2018集训队互测】【XSY3372】取石子

    题目来源:2018集训队互测 Round17 T2 题意: 题解: 显然我是不可能想出来的……但是觉得这题题解太神了就来搬(chao)一下……Orzpyz! 显然不会无解…… 为了方便计算石子个数,在 ...

  3. 【CH 弱省互测 Round #1 】OVOO(可持久化可并堆)

    Description 给定一颗 \(n\) 个点的树,带边权. 你可以选出一个包含 \(1\) 顶点的连通块,连通块的权值为连接块内这些点的边权和. 求一种选法,使得这个选法的权值是所有选法中第 \ ...

  4. 洛谷 P4463 - [集训队互测 2012] calc(多项式)

    题面传送门 & 加强版题面传送门 竟然能独立做出 jxd 互测的题(及其加强版),震撼震撼(((故写题解以祭之 首先由于 \(a_1,a_2,\cdots,a_n\) 互不相同,故可以考虑求出 ...

  5. [bzoj3670][2014湖北省队互测week2]似乎在梦中见过的样子

    Description 已知一个字符串S,求它有多少个形如A+B+A的子串(len(A)>=k,len(B)>=1 ). Input 第一行一个字符串,第二行一个数 k. Output 仅 ...

  6. STOI补番队互测#2

    Round2轮到我出了>_<(目测总共10人参加 实际共七人) 具体情况: #1: KPM,360 #2:ccz181078,160 #3:child,150 可惜KPM没看到第一题样例里 ...

  7. LOJ3069. 「2019 集训队互测 Day 1」整点计数(min_25筛)

    题目链接 https://loj.ac/problem/3069 题解 复数真神奇. 一句话题意:令 \(f(x)\) 表示以原点 \((0, 0)\) 为圆心,半径为 \(x\) 的圆上的整点数量, ...

  8. Alpha2的项目互评互测

    目录 @(Alpha2项目测试) 这个作业属于哪个课程 课程链接 这个作业要求在哪里 作业要求的链接 团队名称 你的代码我的发 这个作业的目标 其他参考文献 软件测试用例 姓名 学号 团队名称 李涵 ...

  9. tree (一本通练习||清华集训互测)

    tree 内存限制:512 MiB 时间限制:3000 ms 标准输入输出 题目类型:传统 评测方式:文本比较   题目描述 给你一个无向带权连通图,每条边是黑色或白色.让你求一棵最小权的恰好有nee ...

随机推荐

  1. Android ListView动态改变Item高度

    在adapter的getView方法中进行设置,代码如下 @Override public View getView(int position, View convertView, ViewGroup ...

  2. 网络HTTP、JSON、XML解析等 复习

    一.一个HTTP请求的基本要素1.请求URL:客户端通过哪个路径找到服务器 2.请求参数:客户端发送给服务器的数据* 比如登录时需要发送的用户名和密码 3.返回结果:服务器返回给客户端的数据* 一般是 ...

  3. Objective-C 【电商APP应用代码-系统分析-详细注释-代码实现】

    ------------------------------------------- 电商APP应用 ************************************************ ...

  4. PHP调用WebService

    1.  环境配置 配置php.ini,把php_soap.dll前面的分号去掉, 配置完成,需要重启. 2.  PHP调用代码,如下 <?php try { $soap = new SoapCl ...

  5. RSA 加解密

    #region RSA public static byte[] GetBytes(String num) { BigInteger n = ); String s = n.ToString(); & ...

  6. tar 「解/壓」 包

    1.tar: short read tar壓縮包文件發生了損壞,或者说不完整. 最近,在寫下載程序的時候,發生了這個問題.初步猜測文件寫完沒有關閉,沒有寫完.

  7. NSURLConnection ignore unverified certificate error when sending a synchronise request

    Private API, use with caution. As we all know, it's easy to ignore the unverified certificate error ...

  8. 6.ipv6地址配置

    1. "nmcli connection modify 网卡名 ipv4.addresses "ipv6地址" ipv6.method manual ". 2. ...

  9. 什么是WEB服务器?

    简单的理解:  一个公用的服务器,你可以放置网站文件,让全世界浏览,可以放文件,全世界下载.web服务器一般指网站服务器.  web服务器是基于网站架设的服务器,我们平时可以浏览的网页都是在别人的服务 ...

  10. FPGA统计摄像头输出-基于MD9T112

    FPGA HDL源程序 FPGA统计摄像头的输出像素,窗口尺寸等等 //---------------------------------------------------------------- ...