A.字符串

Catalan数不能再裸了

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
const ll mod=;
const int N=;
ll n,m;
ll fac[N];
ll qpow(ll a,ll b)
{
ll res=;a=a%mod;
while(b)
{
if(b&)res=res*a%mod;
a=a*a%mod;
b>>=;
}
return res;
}
ll C(ll x,ll y)
{
if(y>x)return ;
return fac[x]*(qpow(fac[y]*fac[x-y]%mod,mod-))%mod;
}
ll lucas(ll x,ll y)
{
if(!y)return ;
return C(x%mod,y%mod)*lucas(x/mod,y/mod)%mod;
}
void ini()
{
fac[]=;
for(ll i=;i<=m+n;i++)
fac[i]=fac[i-]*1LL*i%mod; }
int main()
{
scanf("%lld%lld",&n,&m);
ini();
ll ans=(lucas(m+n,m)-lucas(m+n,m-)+mod)%mod;
cout<<ans<<endl;
return ;
}

B.乌鸦喝水

很能开阔思路的乱搞题。对于每一个缸算出它最多下降的次数,连同它所在的位置进行二元组排序。设rest表示剩下多少缸还能喝,now表示过了几轮,total表示一共喝了多少次水,num[]表示每个缸喝的次数。显然所求即为$\sum num[i]$

对于每一个缸,二分它还能被喝几轮,如果第i个缸还能喝cnt轮,后面(排序后)的缸自然也可以喝cnt轮。易得$num[i]=now+cnt$,之后用树状数组判断位置在i之前的缸能否让它再喝一次,即剩下的次数是否大于等于在该缸之前(包括)的缸数,如果是的话now和num[]都要++。

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
using namespace std;
typedef long long ll;
#define pa pair<ll,ll>
const int N=;
int n,m,tot,rest,now;
ll x,w[N],a[N],num[N],cnt,total,ans;
pa bu[N];
namespace bit
{
ll c[N];
int lb(int x){return x&-x;}
void add(int x)
{
for( ;x<=n;x+=lb(x))
c[x]++;
}
int ask(int x)
{
int res=;
for( ;x;x-=lb(x))
res+=c[x];
return res;
}
}
int main()
{
scanf("%d%d%lld",&n,&m,&x);
for(int i=;i<=n;i++)
scanf("%lld",&w[i]);
for(int i=;i<=n;i++)
scanf("%lld",&a[i]);
for(int i=;i<=n;i++)
if(x>=w[i])bu[++tot]=make_pair((x-w[i])/a[i]+,tot);
sort(bu+,bu+tot+);
rest=tot;
for(int i=;i<=tot;i++)
{
int l=,r=m-now;
while(l<=r)
{
int mid=l+r>>;
if(1LL*rest*mid<bu[i].first-total)l=mid+,cnt=mid;
else r=mid-;
}
if(now+cnt==m)
{
ans+=(tot-i+)*m;
cout<<ans<<endl;
exit();
}
num[i]=now+cnt;
int pre=bu[i].second-bit::ask(bu[i].second);
bit::add(bu[i].second);
if(bu[i].first-rest*cnt-total>=pre)total++,num[i]++;
total+=cnt*rest,now+=cnt;
rest--;
ans+=num[i];
}
cout<<ans<<endl;
return ;
}

C.所驼门王的宝藏

十分不敢相信居然会有这么水的省选题……

可以发现跳过去再跳过来的情况对统计答案造成了困难,所以考虑缩点。把整张图缩成一个森林之后我们要让它经过的点尽量多,所以找联通的最长链。

一句话题解:将每个格子和它能到达的格子暴力连边,然后Tarjan缩点,最后跑一遍拓扑求树上最长链就是答案。

#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
const int M=,N=1e5+;
int read()
{
int x=,f=;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-;ch=getchar();}
while(isdigit(ch))x=x*+ch-'',ch=getchar();
return x*f;
}
struct room_
{
int x,y,op;
}a[N];
int n,R,C;
vector<int> h[M],l[M],g[N];
int tot,head[M<<],nxt[M<<],to[M<<],deg[N],ans[N];
void add(int x,int y)
{
to[++tot]=y;
nxt[tot]=head[x];
head[x]=tot;
}
int dfn[N],low[N],st[N],top=,vis[N],bel[N],scc,ind,size[N];
void tarjan(int x)
{
dfn[x]=low[x]=++ind;
vis[x]=;
st[++top]=x;
for(int i=head[x];i;i=nxt[i])
{
int y=to[i];
if(!dfn[y])tarjan(y),low[x]=min(low[x],low[y]);
else if(vis[y])low[x]=min(low[x],dfn[y]);
}
if(low[x]==dfn[x])
{
scc++;int now=;
do
{
now=st[top--];
size[scc]++;
bel[now]=scc;
vis[now]=;
}while(now!=x);
}
}
int main()
{
n=read();R=read();C=read();
for(int i=;i<=n;i++)
{
a[i].x=read(),a[i].y=read(),a[i].op=read();
h[a[i].x].push_back(i);l[a[i].y].push_back(i);
}
for(int i=;i<=n;i++)
{
int op=a[i].op;
if(op==)
{
int sz=h[a[i].x].size();
for(int j=;j<sz;j++)
{
if(h[a[i].x][j]==i)continue;
add(i,h[a[i].x][j]);
}
}
else if(op==)
{
int sz=l[a[i].y].size();
for(int j=;j<sz;j++)
{
if(l[a[i].y][j]==i)continue;
add(i,l[a[i].y][j]);
}
}
else if(op==)
{
int sz;
if(a[i].x>)
{
sz=h[a[i].x-].size();
for(int j=;j<sz;j++)
{
if(a[h[a[i].x-][j]].y>=a[i].y-&&a[h[a[i].x-][j]].y<=a[i].y+)
add(i,h[a[i].x-][j]);
}
}
sz=h[a[i].x].size();
for(int j=;j<sz;j++)
{
if(h[a[i].x][j]==i)continue;
if(a[h[a[i].x][j]].y>=a[i].y-&&a[h[a[i].x][j]].y<=a[i].y+)
add(i,h[a[i].x][j]);
}
if(a[i].x<R)
{
sz=h[a[i].x+].size();
for(int j=;j<sz;j++)
{
int now=h[a[i].x+][j];
if(a[now].y>=a[i].y-&&a[now].y<=a[i].y+)
add(i,now);
}
}
}
}
for(int i=;i<=n;i++)
if(!dfn[i])tarjan(i);
for(int x=;x<=n;x++)
for(int i=head[x];i;i=nxt[i])
{
int y=to[i];
if(bel[y]!=bel[x])
g[bel[x]].push_back(bel[y]),deg[bel[y]]++;
} //debug();
//puts("----------------------------------------");
/* for(int i=1;i<=scc;i++)
if(!v[i])
{
num=0,dfs(i);
}*/
queue<int> q;
for(int i=;i<=scc;i++)
if(!deg[i])q.push(i),ans[i]=size[i];
while(!q.empty())
{
int x=q.front();
q.pop();int sz=g[x].size();
for(int i=;i<sz;i++)
{
int y=g[x][i];
ans[y]=max(ans[y],ans[x]+size[y]);
if(!(--deg[y]))q.push(y);
}
}
cout<<*max_element(ans+,ans++scc)<<endl;
return ;
}

[NOIP模拟25]题解的更多相关文章

  1. 大家AK杯 灰天飞雁NOIP模拟赛题解/数据/标程

    数据 http://files.cnblogs.com/htfy/data.zip 简要题解 桌球碰撞 纯模拟,注意一开始就在袋口和v=0的情况.v和坐标可以是小数.为保险起见最好用extended/ ...

  2. 「题解」NOIP模拟测试题解乱写II(36)

    毕竟考得太频繁了于是不可能每次考试都写题解.(我解释个什么劲啊又没有人看) 甚至有的题目都没有改掉.跑过来写题解一方面是总结,另一方面也是放松了. NOIP模拟测试36 T1字符 这题我完全懵逼了.就 ...

  3. HZOJ 20190818 NOIP模拟24题解

    T1 字符串: 裸的卡特兰数题,考拉学长讲过的原题,就是bzoj3907网格那题,而且这题更简单,连高精都不用 结论$C_{n+m}^{n}-C_{n+m}^{n+1}$ 考场上10min切掉 #in ...

  4. 「题解」NOIP模拟测试题解乱写I(29-31)

    NOIP模拟29(B) T1爬山 简单题,赛时找到了$O(1)$查询的规律于是切了. 从倍增LCA那里借鉴了一点东西:先将a.b抬到同一高度,然后再一起往上爬.所用的步数$×2$就是了. 抬升到同一高 ...

  5. HGOI NOIP模拟4 题解

    NOIP国庆模拟赛Day5 题解 T1 马里奥 题目描述 马里奥将要参加 NOIP 了,他现在在一片大陆上,这个大陆上有着许多浮空岛,并且其中一座浮空岛上有一个传送门,马里奥想要到达传送门从而前往 N ...

  6. [NOIP模拟13]题解

    A.矩阵游戏 其实挺水的? 考场上根本没有管出题人的疯狂暗示(诶这出题人有毛病吧这么简单的东西写一大堆柿子),而且推公式能力近乎没有,所以死掉了. 很显然乘法有交换率结合率所以操作顺序对最终结果没什么 ...

  7. 2021.7.27考试总结[NOIP模拟25]

    罕见的改完了题 T1 random 一堆概率,一堆函数,一堆递归,一眼不可做, 但它只有一个参数,所以.. 熠神本着"只有20太难看"的心态,通过样例三个出规律,口胡了一波$\fr ...

  8. 8.3 NOIP 模拟12题解

    话说这次考试T1和T2是真的水,然而T1CE,T2TLE,T3CE 这不就是在侮辱我的智商啊!之前本机编译都是c++,以后要用c++11. 这次的T1就是一个大型找规律,我的规律都找出来了,但是竟然用 ...

  9. 『7.5 NOIP模拟赛题解』

    T1 Gift Description ​ 人生赢家老王在网上认识了一个妹纸,然后妹纸的生日到了,为了表示自己的心 意,他决定送她礼物.可是她喜爱的东西特别多,然而他的钱数有限,因此他想 知道当他花一 ...

随机推荐

  1. element table 通过selection-change选中的索引删除

    <el-table :row-class-name="tableRowClassName" @selection-change="handleSelectionCh ...

  2. codeforces 111A/112C Petya and Inequiations

    题目:Petya and Inequiations传送门: http://codeforces.com/problemset/problem/111/A http://codeforces.com/p ...

  3. [CSP-S模拟测试]:折射(DP)

    题目描述 小$Y$十分喜爱光学相关的问题,一天他正在研究折射. 他在平面上放置了$n$个折射装置,希望利用这些装置画出美丽的折线. 折线将从某个装置出发,并且在经过一处装置时可以转向,若经过的装置坐标 ...

  4. 【SpringBoot】 一种解决接口返回慢的方式

    前言 使用springboot开发后台代码的时候,很核心的一个功能是为前端提供接口,那么很可能你会遇到如下问题: 1. 接口里面调用的service层是第三方库或者第三方后台程序,导致访问很慢. 2. ...

  5. laravel 简单应用 redis

    1.连接配置 database.php 中 测试用 都没做修改 2.创建测试路由及控制器 //添加路由 Route::get('testRedis','RedisController@testRedi ...

  6. spring boot 尚桂谷学习笔记06 异常处理 ---Web

    ------错误处理机制------ 默认效果 1 返回一个默认的错误页面 浏览器发送请求的请求头:优先接收 text/html 数据 客户端则默认响应json数据 : accept 没有说明返回什么 ...

  7. Spring 官方文档笔记---Bean

    In Spring, the objects that form the backbone of your application and that are managed by the Spring ...

  8. css浮动以及清除

    首先要知道,div是块级元素,在页面中独占一行,自上而下排列,也就是传说中的流.如下图: 可以看出,即使div1的宽度很小,页面中一行可以容下div1和div2,div2也不会排在div1后边,因为d ...

  9. Linux GNU GAS introduction

    Linux汇编语法简介(GNU GAS)     声明:本教程不是介绍汇编语言和CPU指令的书籍,只是对gas的用法做一简单介绍.市面上所有讲汇编的书都是在微软的环境下,使用的是Intel的语法格式, ...

  10. [fw]IDT表的初始化

    IDT表的初始化  linux内核的中断描述符表IDT是一个全局的数据,在i386平台上被定义为: struct desc_struct idt_table[256] __attribute__((_ ...