NOIP2017金秋冲刺训练营杯联赛模拟大奖赛第一轮Day1

T1 天天去哪儿吃

直接枚举

#include<cstdio>
#include<algorithm>
using namespace std;
#define N 100001
int d[N<<];
bool g[N];
int main()
{
int n,m;
long long a,b;
scanf("%d%d%lld%lld",&n,&m,&a,&b);
scanf("%d%d",&d[],&d[]);
int now;
int len=n/;
for(int i=;i>=max(-len,);i--) g[d[i]]=true;
for(int i=;i<=m;i++)
{
now=(a*d[i-]+b*d[i-])%n;
while(g[now])
{
now++;
if(now==n) now=;
}
d[i]=now;
if(i-len>) g[d[i-len]]=false;
g[now]=true;
}
for(int i=;i<=m;i++) printf("%d ",d[i]);
}

T2 天天和树tree

找除去最长链之后的最长半链

3遍dfs即可

#include<cstdio>
#include<algorithm>
#define N 100001
using namespace std;
int front[N],nxt[N<<],to[N<<],tot;
int maxn,wh1,wh2;
int pre[N],d[N];
bool in[N];
void add(int u,int v)
{
to[++tot]=v; nxt[tot]=front[u]; front[u]=tot;
to[++tot]=u; nxt[tot]=front[v]; front[v]=tot;
}
void dfs1(int x,int fa,int dis)
{
if(dis>maxn) maxn=dis,wh1=x;
for(int i=front[x];i;i=nxt[i])
if(to[i]!=fa) dfs1(to[i],x,dis+);
}
void dfs2(int x,int fa,int dis)
{
pre[x]=fa;
if(dis>maxn) maxn=dis,wh2=x;
for(int i=front[x];i;i=nxt[i])
if(to[i]!=fa) dfs2(to[i],x,dis+);
}
void dfs3(int x,int fa,int dis)
{
d[x]=dis;
for(int i=front[x];i;i=nxt[i])
if(to[i]!=fa) dfs3(to[i],x,dis+);
}
int main()
{
int n;
scanf("%d",&n);
int u,v;
for(int i=;i<n;i++)
{
scanf("%d%d",&u,&v);
add(u,v);
}
dfs1(,,);
maxn=;
dfs2(wh1,wh1,);
in[wh1]=true;
for(int i=wh2;i!=pre[i];i=pre[i]) in[i]=true;
for(int i=;i<=n;i++)
if(in[i])
for(int j=front[i];j;j=nxt[j])
if(!in[to[j]]) dfs3(to[j],i,);
int ans=;
for(int i=;i<=n;i++) ans=max(ans,d[i]);
printf("%d",ans);
}

T3 摆摊

求区间的mex,主席树

防止出现0,1,,开始在1号位置加入一个无穷大

#include<cstdio>
#include<algorithm>
#define N 200011
using namespace std;
int n,m,q,tot,a[N];
int root[N],lc[],rc[],minn[];
void insert(int &x,int y,int l,int r,int pos,int w)
{
x=++tot;
minn[x]=minn[y];
lc[x]=lc[y],rc[x]=rc[y];
if(l==r)
{
minn[x]=max(minn[x],w);
return;
}
int mid=l+r>>;
if(pos<=mid) insert(lc[x],lc[y],l,mid,pos,w);
else insert(rc[x],rc[y],mid+,r,pos,w);
minn[x]=min(minn[lc[x]],minn[rc[x]]);
}
int query(int x,int l,int r,int w)
{
if(l==r) return l;
int mid=l+r>>;
if(minn[lc[x]]<w) return query(lc[x],l,mid,w);
else return query(rc[x],mid+,r,w);
}
int main()
{
scanf("%d%d%d",&n,&m,&q);
insert(root[],root[],,n+,,2e9);
for(int i=;i<=m;i++)
{
scanf("%d",&a[i]);
insert(root[i],root[i-],,n+,a[i],i);
insert(root[i],root[i],,n+,a[i]+,i);
}
int u,v,ans;
while(q--)
{
scanf("%d%d",&u,&v);
ans=query(root[v],,n+,u);
if(ans==n+) printf("-1 -1\n");
else printf("%d %d\n",ans-,ans);
}
}

NOIP模拟赛15的更多相关文章

  1. noip模拟赛#15

    #15 T1:a[i]>=a[i/2].输出a的最大字典序 =>可以发现这是二叉树的情况那么就先预处理出每个点有多少个儿子然后递归处理就可以了. #include<cstdio> ...

  2. contesthunter暑假NOIP模拟赛第一场题解

    contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...

  3. NOIP模拟赛 by hzwer

    2015年10月04日NOIP模拟赛 by hzwer    (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...

  4. CH Round #48 - Streaming #3 (NOIP模拟赛Day1)

    A.数三角形 题目:http://www.contesthunter.org/contest/CH%20Round%20%2348%20-%20Streaming%20%233%20(NOIP模拟赛D ...

  5. 【noip模拟赛5】细菌 状压dp

    [noip模拟赛5]细菌   描述 近期,农场出现了D(1<=D<=15)种细菌.John要从他的 N(1<=N<=1,000)头奶牛中尽可能多地选些产奶.但是如果选中的奶牛携 ...

  6. 【HHHOJ】NOIP模拟赛 玖 解题报告

    点此进入比赛 得分: \(100+20+100=220\)(还不错) 排名: \(Rank\ 16\) \(Rating\):\(+20\) \(T1\):[HHHOJ263]「NOIP模拟赛 玖」三 ...

  7. 【HHHOJ】NOIP模拟赛 捌 解题报告

    点此进入比赛 得分: \(30+30+70=130\)(弱爆了) 排名: \(Rank\ 22\) \(Rating\):\(-31\) \(T1\):[HHHOJ260]「NOIP模拟赛 捌」Dig ...

  8. NOIP模拟赛 6.29

    2017-6-29 NOIP模拟赛 Problem 1 机器人(robot.cpp/c/pas) [题目描述] 早苗入手了最新的Gundam模型.最新款自然有着与以往不同的功能,那就是它能够自动行走, ...

  9. NOIP模拟赛20161022

    NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...

随机推荐

  1. Binary Tree(生成二叉树)

    Description Background Binary trees are a common data structure in computer science. In this problem ...

  2. HDU 1874 畅通工程续-- Dijkstra算法详解 单源点最短路问题

    参考 此题Dijkstra算法,一次AC.这个算法时间复杂度O(n2)附上该算法的演示图(来自维基百科): 附上:  迪科斯彻算法分解(优酷) problem link -> HDU 1874 ...

  3. HDU 5234 Happy birthday 01背包

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5234 bc:http://bestcoder.hdu.edu.cn/contests/con ...

  4. Struts2(二)

    以下内容是基于导入struts2-2.3.32.jar包来讲的 1.关于StrutsPrepareAndExecuteFilter 启动StrutsPrepareAndExecuteFilter时加载 ...

  5. spring表单—乱码解决方案

    1.POST方式提交 A.jsp页面POST方式提交表单 B.web.xml配置过滤器 <!-- spring过滤器解决乱码问题 --> <filter> <filter ...

  6. eclipse中jsp页面Invalid location of tag 解决办法分析小结

    在jsp页面使用标签过程中有时候不注意规则的话,eclipse会提示一些错误,下面针对这些错误提出相应的解决办法: <form></form>标签 1. Invalid loc ...

  7. 使用Kettle导出excel

    1.开发背景 在web项目中,经常会需要查询数据导出excel,以前比较常见的就是用poi.使用poi的时候也有两种方式,一种就是直接将集合一次性导出为excel,还有一种是分批次追加的方式适合数据量 ...

  8. 主流的RPC框架有哪些

    RPC是远程过程调用的简称,广泛应用在大规模分布式应用中,作用是有助于系统的垂直拆分,使系统更易拓展.Java中的RPC框架比较多,各有特色,广泛使用的有RMI.Hessian.Dubbo等.RPC还 ...

  9. jquery弹出层开源框架layer

    高度自适应参考:layer.open如何让高度自适应? 高度自适应修改layer.js代码如下: r.iframeAuto = function(e) { if (e) { var t = r.get ...

  10. 第73天:jQuery基本动画总结

    一.DOM对象跟jQuery对象相互转换 jQuery对象转换成DOM对象: 方式一:$(“#btn”)[0] 方式二:$(“#btn”).get(0) DOM对象转换成jQuery对象: $(doc ...