
牛客网
wwt9b15bs
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
【题解】牛客OI周赛1-提高组 A.分组 dfs
链接:https://www.nowcoder.com/acm/contest/199/A来源:牛客网将认识关系转化为图中的边。dfs这张图,对每一个没有被访问过的点,将它标记为源点的反色,回溯的时候统计每个点有多少同色相邻点,个数等于2时将其颜色转换。#include<cstdio>#include<cstring>const int N=1e5+10,M...原创 2018-10-02 13:23:28 · 433 阅读 · 0 评论 -
【题解】[牛客网NOIP赛前集训营-提高组(第六场)]A.最长路 拓扑排序
题目链接#include&lt;cstdio&gt;#include&lt;queue&gt;#include&lt;cstring&gt;using namespace std;const int N=1e6+10,mod=998244353;struct node{ int u,d,pre,rnk; node(){} node(int _u,int _d,i...原创 2018-11-01 08:37:10 · 239 阅读 · 0 评论 -
【题解】[牛客网NOIP赛前集训营-提高组(第二场)]B.分糖果 单调栈优化线性DP+容斥原理
题目链接#include<cstdio>#define re registertypedef long long ll;const int N=1e6+10;const int INF=0x3f3f3f3f;const int mod=1e9+7;template<typename tp>inline int getmin(tp&x,tp...原创 2018-10-30 09:30:54 · 2171 阅读 · 0 评论 -
【题解】[牛客网NOIP赛前集训营-提高组(第二场)]C.集合划分 状压DP
题目链接看了题解后还是没写对,只能去看Komachi大佬咋写的了。#include<cstdio>#include<cstring>const int N=18,MX=(1<<18)+5;int n,m,k,ban[N][MX],pre[MX],f[MX];int main(){ //freopen("in.txt","r",std...转载 2018-10-30 14:42:34 · 383 阅读 · 0 评论 -
【题解】[牛客网NOIP赛前集训营-提高组(第三场)]A.管道维修 数学期望
题目链接#include<cstdio>#include<algorithm>#include<cmath>using namespace std;typedef long long ll;#define re registerconst int mod=1e9+7;const int N=210;template<typenam...原创 2018-10-30 16:49:56 · 267 阅读 · 0 评论 -
【题解】[牛客网NOIP赛前集训营-提高组(第三场)]B.公平竞赛 bfs
题目链接#include<cstdio>#include<cstring>#include<queue>#include<algorithm>using namespace std;inline int read(){ int s=0,f=0;char ch=getchar(); while(ch<'0'||ch&g...原创 2018-10-30 17:31:23 · 317 阅读 · 0 评论 -
【题解】[牛客网NOIP赛前集训营-提高组(第六场)]B.选择题 期望DP
#include<cstdio>#include<algorithm>using namespace std;const int N=2e3+10;const int mod=998244353;int n,p[N][4],w[4][4],pre[N][N],suf[N][N],ans[N];int main(){ //freopen(...原创 2018-11-01 08:40:35 · 265 阅读 · 0 评论 -
【题解】[牛客网NOIP赛前集训营-提高组(第七场)]A.中国式家长2 模拟
题目链接#include&amp;lt;cstdio&amp;gt;#include&amp;lt;algorithm&amp;gt;using namespace std;const int N=210;int n,m,x,y,ans,t,nk,k,a[N][N],b[N][N],vis[N][N];int main(){ //freopen(&quot;in.txt&quot;,原创 2018-11-01 09:41:30 · 298 阅读 · 0 评论 -
【题解】[牛客网NOIP赛前集训营-提高组(第七场)]B.随机生成树 枚举
题目链接#include<cstdio>const int N=5e5+10;inline int read(){ int s=0,f=0;char ch=getchar(); while(ch<'0'||ch>'9')f|=ch=='-',ch=getchar(); while(ch>='0'&&ch<='9')s=(s...原创 2018-11-01 09:56:38 · 218 阅读 · 0 评论 -
【题解】[牛客网NOIP赛前集训营-提高组(第七场)]C.洞穴 倍增优化DP+bitset
题目链接#include<cstdio>#include<bitset>using namespace std;const int N=110;int n,m,q;bitset<N>f[N][31];int main(){ //freopen("in.txt","r",stdin); scanf("%d%d",&n,&原创 2018-11-01 10:15:05 · 248 阅读 · 0 评论 -
【题解】[牛客网NOIP赛前集训营-提高组(第三场)]C.急开锁 博弈论+打表
题目链接#include<cstdio>typedef long long ll;int t,k,l,r;ll len,f[4000010];int main(){ //freopen("in.txt","r",stdin); scanf("%d",&t);f[0]=1;f[1]=2; while(t--) { scanf("%d%lld",&原创 2018-10-30 19:45:03 · 291 阅读 · 0 评论 -
【题解】[牛客网NOIP赛前集训营-提高组(第四场)]A.动态点分治 模拟
题目链接#include<cstdio>typedef long long ll;int t,find;ll l,r,k,x;int main(){ //freopen("in.txt","r",stdin); scanf("%d",&t); while(t--) { find=0; scanf("%lld%ll...原创 2018-10-30 20:22:18 · 222 阅读 · 0 评论 -
【题解】[牛客网NOIP赛前集训营-提高组(第四场)]B.区间 乱搞
题目链接#include<cstdio>#include<algorithm>using namespace std;typedef long long ll;const int MAXN=1e7+10;ll a[MAXN];int r[MAXN],N,ans=1;#define RG register#define getc() (S == T ...原创 2018-10-30 22:11:37 · 203 阅读 · 0 评论 -
【题解】[牛客网NOIP赛前集训营-提高组(第四场)]C.灭虫 线性DP+堆优化
题目链接#include<cstdio>#include<algorithm>#include<queue>using namespace std;const int N=3e3+10;struct node{ int p,l,r; bool operator <(const node&rhs)const{ retur...原创 2018-10-30 22:50:58 · 256 阅读 · 0 评论 -
【题解】[牛客OI周赛4-提高组]A.K小生成树 枚举+前缀和+剪枝
题目链接#include<cstdio>#include<algorithm>using namespace std;const int N=1e6+10,Q=1e4+10,INF=0x3f3f3f3f;int n,m,a[N],fa[21],l,r,f1,f2,ans,tot,flag,q,askl[Q],askr[Q],minl=INF,maxr=-...原创 2018-11-01 16:59:13 · 885 阅读 · 0 评论 -
【题解】[牛客OI周赛2-提高组]C.好朋友 数位DP
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;template<typename tp>inline void read(tp&x){ x=0;int f=0;char ch=getchar(); while(ch<'...原创 2018-10-31 20:28:13 · 459 阅读 · 0 评论 -
【题解】[牛客OI周赛2-提高组]B.水果蛋糕 乱搞
题目链接#include<cstdio>#include<algorithm>using namespace std;int main(){ long long n,m; scanf("%lld%lld",&n,&m); if(n<m)swap(n,m); if(m<=2)printf("%lld\n",m*n);...原创 2018-10-31 15:19:22 · 227 阅读 · 0 评论 -
【题解】牛客OI周赛1-提高组 B.树 树上倍增+组合计数
链接:https://www.nowcoder.com/acm/contest/199/B来源:牛客网学习了大佬代码。对着这份代码看了一个多小时好像有点点明白。大概就是在这头选两个端点在那头选两个端点更新答案(说了等于没说)。选子树内那一头是不能在同一个子节点的子树内部选两个(会多占一些边),选子树外那头也得把共了边的部分减去,保证最后往上跳之后求出来的路径组合长度是在范围内的。#in...原创 2018-10-02 16:21:25 · 448 阅读 · 0 评论 -
【题解】牛客OI周赛1-提高组 C.序列 计数类DP+前缀和优化
链接:https://www.nowcoder.com/acm/contest/199/C来源:牛客网我们枚举不同数字的个数 xxx 。此时等价于这个问题,有 x 个箱子排成一排,任意两个箱子之间距离不超过 k(超过 k 意味着可以把这个间距减小到 k,且是一个等价的序列),第一个箱子和最后一个箱子的距离不超过 m 的方案数。设 F[i,j]F[i,j]F[i,j] 表示放置了 ii...原创 2018-10-02 18:55:59 · 433 阅读 · 1 评论 -
【题解】[牛客网NOIP赛前集训营-提高组(第一场)]A.中位数 二分+前缀和
题目链接构造一个序列 BBB 。每次二分一个答案 ansansans,构造 BBB 序列方法:Bi={−1Ai&lt;ans1Ai≥ansB_i=\begin{cases}-1\quad A_i&lt;ans\\1\quad A_i\geq ans\end{cases}Bi={−1Ai<ans1Ai≥ans然后维护 BBB 的前缀和,并记录前缀和的最小值。通...原创 2018-10-05 12:51:57 · 267 阅读 · 0 评论 -
【题解】[牛客OI周赛3-提高组]A.地斗主 矩阵快速幂
题目链接#include<cstdio>#include<cstring>typedef long long ll;int n,m,t,ans[5]={0,1,5,11,36};struct Matrix{ ll a[5][5];};Matrix operator *(Matrix a,Matrix b){ Matrix c;memset(c.a...原创 2018-10-28 19:59:41 · 328 阅读 · 0 评论 -
【题解】[牛客OI周赛3-提高组]B.1408 线性DP
题目链接#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;const int N=2e3+10;int n,dp[N][N],w[N],b[N],c1[N][N],c2[N][N];int main...原创 2018-10-28 20:06:11 · 309 阅读 · 0 评论 -
【题解】[牛客OI周赛3-提高组]C.爆瓶子 二分图匹配
题目链接学习了大佬代码,毕竟本蒟蒻至今写不来二分图匹配(NOIP退役预定qwq)#include<cstdio>#include<cstring>const int N=500;int t,n,m,g[N][N],hd[N],tot,To[N],match[N],vis[N],lim;struct Edge{ int v,nx;}e[N*N];...原创 2018-10-28 20:33:53 · 228 阅读 · 0 评论 -
【题解】[牛客网NOIP赛前集训营-提高组(第一场)]B.数数字 线性DP
题目链接#include<cstdio>#include<cstring>typedef long long ll;#define _rep(i,a,b) for(int i=(a);i<=(b);i++)#define _for(i,a,b) for(int i=(a);i<(b);i++)int co[10][10];ll pw[10]...原创 2018-10-28 21:06:43 · 275 阅读 · 0 评论 -
【题解】[牛客网NOIP赛前集训营-提高组(第一场)]C.保护 LCA+线段树动态开点+线段树合并
题目链接___#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int N=2e5+10;int n,m,hd[N],tot,dep[N],fa[N][20],ord[N],cnt,q;struct Edge{ int v,nx;...原创 2018-10-28 21:18:49 · 253 阅读 · 0 评论 -
【题解】[牛客网NOIP赛前集训营-提高组(第二场)]A.方差 前缀和
题目链接我们把方差公式进行化简。记 sum1sum_1sum1 为每个数的前缀和,sum2sum_2sum2 为每个数平方后的前缀和1m∑i=1m(bi−b‾)2=1m∑i=1m(bi2−2∗bi∗b‾+b‾2)=1m(sum2−2∗b‾∗sum1+m∗b‾2)=1m(sum2−2∗sum12m+sum12m)=sum2m−sum12m2\frac{1}{m}\sum_{i=1}^m...原创 2018-10-29 09:02:41 · 337 阅读 · 0 评论 -
【题解】[牛客网NOIP赛前集训营-提高组(第五场)]A.同余方程 位运算
#include<cstdio>#include<algorithm>using namespace std;typedef long long ll;const ll mod=998244353;ll m,l1,l2,r1,r2;ll get(ll l,ll r){return r/m-(l==0?-1:(l-1)/m);}ll cal(ll l,l...原创 2018-10-31 08:56:05 · 231 阅读 · 0 评论 -
【题解】[牛客网NOIP赛前集训营-提高组(第五场)]B.旅游 最小生成树
题目链接#include<cstdio>#include<algorithm>using namespace std;typedef long long ll;const int N=5e5+10,mod=998244353;inline int read(){ int s=0,f=0;char ch=getchar(); while(ch<...原创 2018-10-31 11:20:12 · 262 阅读 · 0 评论 -
【题解】[牛客网NOIP赛前集训营-提高组(第五场)]C.串串 组合数
题目链接#include<cstdio>const int N=4e3+10,mod=1e9+7;int a,b,c,d,fac[N],inv[N],ans;int C(int n,int m){ if(n<0||m<0)return 0; return 1ll*fac[n]*inv[m]%mod*inv[n-m]%mod;}int main()...原创 2018-10-31 13:28:51 · 387 阅读 · 0 评论 -
【题解】[牛客OI周赛2-提高组]A.游戏 乱搞
题目链接#include<cstdio>const int N=1e3+10;char s[N][N];int n,m,t;int main(){ //freopen("in.txt","r",stdin); scanf("%d",&t); while(t--) { scanf("%d%d",&n,&原创 2018-10-31 14:07:19 · 233 阅读 · 1 评论 -
【题解】[牛客OI周赛4-提高组]B.最后的晚餐 组合数+容斥原理
题目链接#include<cstdio>typedef long long ll;const int mod=1e9+7;int n;ll ans=1,a,b,c;int main(){ scanf("%d",&n); if(n==1){puts("0");return 0;} a=1;b=n-2; for(int i=...原创 2018-11-01 17:51:12 · 400 阅读 · 0 评论