【Noip模拟By yxj】
1.random
Description
给定4个参数A0,N,c,p,你需要按下式构造A1~AN:
A[i]=(A[i-1]2+c)mod p
之后,你需要求出A1~AN中,第K大的数值。
Input
一行五个正整数A0,N,c,p,K。
Output
一行一个整数,描述答案。
Sample Input
123 10 435 3451 5
Sample Output
2936
Range
测试点 范围
1~3 K<=N<=105
4~10 K<=N<=5*106
直接stl
1 #include<algorithm> 2 #include<iostream> 3 #include<cstdlib> 4 #include<cstring> 5 #include<cstdio> 6 #include<cmath> 7 using namespace std; 8 9 typedef long long LL; 10 11 #define N 5000010 12 13 LL n,c,p,k; 14 15 LL a[N]; 16 17 bool cmp(const int & a,const int & b) 18 { 19 return a>b; 20 } 21 22 int main() 23 { 24 freopen("random.in","r",stdin);freopen("random.out","w",stdout); 25 scanf("%lld%lld%lld%lld%lld",&a[0],&n,&c,&p,&k); 26 for (LL i=1;i<=n;i++) 27 a[i]=((a[i-1]*a[i-1])%p+c%p)%p; 28 nth_element(a+1,a+k,a+n+1,cmp); 29 printf("%I64d",a[k]); 30 return 0; 31 }
2.sequence
Description
给一个长度为n的序列a,以及q个询问。每次询问给出两个参数l,r,你需要输出子 序列al~ar的最大连续字段和。
Input
第一行两个正整数n,q。
` 接下来一行n个整数,描述序列a。
接下来q行,每行两个参数l,r,描述一个询问。
Output
对于每个询问,输出一行一个整数,描述答案。
Sample Input
4 3
1 -2 3 2
1 4
1 2
2 2
Sample Output
5
1
0
Range
测试点 范围
1~3 N,Q<=1000
4~7 N,Q<=105
8~10 N<=105,Q<=106
线段树维护。
1 #include<algorithm> 2 #include<iostream> 3 #include<cstdlib> 4 #include<cstring> 5 #include<cstdio> 6 #include<cmath> 7 using namespace std; 8 9 #define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout); 10 #define maxn 100010 11 #define IN inline 12 #define RE register 13 14 typedef long long llg; 15 16 int n,m,zhi[maxn*3],now=maxn*3-2,ll,rr,D; 17 int sumv[maxn*3],le[maxn*3],ri[maxn*3]; 18 19 20 IN int getint() 21 { 22 int w=0,q=0; 23 char c=getchar(); 24 while((c<'0'||c>'9')&&c!='-') c=getchar(); 25 if(c=='-') q=1,c=getchar(); 26 while(c>='0'&&c<='9') w=w*10+c-'0',c=getchar(); 27 return q?-w:w; 28 } 29 30 IN void update(int u,int lc,int lv) 31 { 32 sumv[u]=sumv[lc]+sumv[lv]; 33 le[u]=max(le[lc],sumv[lc]+le[lv]); 34 ri[u]=max(ri[lv],sumv[lv]+ri[lc]); 35 zhi[u]=max(zhi[lc],zhi[lv]); 36 zhi[u]=max(zhi[u],ri[lc]+le[lv]); 37 } 38 39 IN void build(int u,int l,int r) 40 { 41 int lc=u<<1,lv=u<<1|1,mid=l+r>>1; 42 if (l==r) 43 { 44 sumv[u]=getint(); 45 if (sumv[u]>0) 46 zhi[u]=le[u]=ri[u]=sumv[u]; 47 return; 48 } 49 build(lc,l,mid); 50 build(lv,mid+1,r); 51 update(u,lc,lv); 52 } 53 54 IN void query(int u,int l,int r) 55 { 56 int lc=u<<1,lv=u<<1|1,mid=l+r>>1; 57 if (l>=ll && r<=rr) 58 { 59 if (!D) 60 { 61 zhi[now]=zhi[u];sumv[now]=sumv[u]; 62 le[now]=le[u];ri[now]=ri[u];D++; 63 } 64 else 65 { 66 now^=1; 67 update(now,now^1,u); 68 } 69 return; 70 } 71 if (ll<=mid) 72 query(lc,l,mid); 73 if (rr>mid) 74 query(lv,mid+1,r); 75 } 76 77 78 79 int main(){ 80 File("sequence"); 81 n=getint();m=getint(); 82 build(1,1,n); 83 while(m--) 84 { 85 ll=getint();rr=getint(); 86 D=0;query(1,1,n); 87 printf("%d\n",zhi[now]); 88 } 89 }
3.tree
Description
给一棵n个节点的无根树,求路径长度=K的简单路径数。
Input
第一行两个正整数n,K。
接下来n-1行,每行两个正整数x,y,描述一条边(x,y)。
Output
一行一个整数,描述答案。
Sample Input
4 2
1 2
2 3
2 4
Sample Output
3
Range
测试点 范围
1~3 2<=K<=N<=1000
4~10 2<=K<=N<=105
1 #include<algorithm> 2 #include<iostream> 3 #include<cstdlib> 4 #include<cstring> 5 #include<cstdio> 6 #include<cmath> 7 using namespace std; 8 9 #define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout); 10 #define maxn 100010 11 12 typedef long long llg; 13 14 int head[maxn],next[maxn<<1],to[maxn<<1],tt,n,ans,D; 15 int a[maxn],c1[maxn],c2[maxn],siz[maxn],val[maxn]; 16 bool w[maxn]; 17 18 void link() 19 { 20 int x,y; 21 scanf("%d%d",&x,&y); 22 to[++tt]=y;next[tt]=head[x];head[x]=tt; 23 to[++tt]=x;next[tt]=head[y];head[y]=tt; 24 } 25 26 void dfs1(int u,int fa) 27 { 28 siz[u]=1;a[++tt]=u;val[u]=0; 29 for (int i=head[u],v;v=to[i],i;i=next[i]) 30 if (v!=fa && !w[v]) 31 { 32 dfs1(v,u);siz[u]+=siz[v]; 33 val[u]=max(val[u],siz[v]); 34 } 35 } 36 37 void dfs2(int u,int fa,int now){ 38 c1[now]++; 39 if (now>=D) 40 return; 41 for (int i=head[u],v;v=to[i],i;i=next[i]) 42 if (v!=fa && !w[v]) 43 dfs2(v,u,now+1); 44 } 45 46 void solve(int u) 47 { 48 int x=u;tt=0; 49 dfs1(u,0); 50 for (int i=2;i<=tt;i++) 51 { 52 val[a[i]]=max(val[a[i]],siz[u]-siz[a[i]]); 53 if (val[a[i]]<val[x]) 54 x=a[i]; 55 } 56 w[x]=1; 57 for (int i=head[x],v;v=to[i],i;i=next[i]) 58 if (!w[v]) 59 { 60 dfs2(v,0,1); 61 ans+=c1[D]; 62 for (int j=1;c1[j];j++) 63 ans+=c2[D-j]*c1[j]; 64 for (int j=1;c1[j];j++) 65 c2[j]+=c1[j],c1[j]=0; 66 } 67 for (int i=1;c2[i];i++) 68 c2[i]=0; 69 for (int i=head[x],v;v=to[i],i;i=next[i]) 70 if (!w[v]) 71 solve(v); 72 } 73 74 int main() 75 { 76 File("tree"); 77 scanf("%d%d",&n,&D); 78 for(int i=1;i<n;i++) 79 link(); 80 solve(1); 81 printf("%d",ans); 82 }
转载于:https://www.cnblogs.com/yangjiyuan/p/5361462.html
【Noip模拟By yxj】相关推荐
- NOI.AC NOIP模拟赛 第六场 游记
NOI.AC NOIP模拟赛 第六场 游记 queen 题目大意: 在一个\(n\times n(n\le10^5)\)的棋盘上,放有\(m(m\le10^5)\)个皇后,其中每一个皇后都可以向上.下 ...
- 【noip模拟赛4】Matrix67的派对 暴力dfs
[noip模拟赛4]Matrix67的派对 描述 Matrix67发现身高接近的人似乎更合得来.Matrix67举办的派对共有N(1<=N<=10)个人参加,Matrix67需要把他们安排 ...
- 【HHHOJ】NOIP模拟赛 捌 解题报告
点此进入比赛 得分: \(30+30+70=130\)(弱爆了) 排名: \(Rank\ 22\) \(Rating\):\(-31\) \(T1\):[HHHOJ260]「NOIP模拟赛 捌」Dig ...
- 闵梓轩大佬のnoip模拟题D1 总结 2017/10/26
背景 题目概括 T1 题面 分析 90分算法 满分算法 T2 题面 分析 部分分算法 满分算法 满分代码 T3 题面 分析 代码 总结 背景 这道题目是去年的金牌大佬闵梓轩在一年前出的一套noip模拟 ...
- jyzy noip模拟赛5.22-2
不知道哪来的题 jyzy noip模拟赛5.22-2 样例输入 1 2 3 4 样例输出 0.200000000000000 数据 |a|,|b|,|c|,|d|<=1e9 很多大佬迅速想到二分 ...
- NOIP模拟赛csy2021/10/30
NOIP模拟赛csy2021/10/30 比赛时间规划 赛后反思与总结 这..总的来说感觉打的很不好,根本没有状态,有一部分原因是今天来晚了,太慌,更多的还是这次题感觉很难o(╥﹏╥)o 比赛时间规划 ...
- NOIP模拟(10.22)T2 杆子的排列
杆子的排列 题目背景: 10.22 NOIP模拟作业T2 分析:DP 定义状态dp[i][j][k]表示,目前枚举到第i大的数(即n - i + 1)那么显然如果这一个数放在左边,可以在左边被看到,放 ...
- Noip 模拟练习5
Noip 模拟练习5 满分300,本人240.修正后300. 难度中等. 太空密码 Description 人类一直致力于探索地外文明,为此科学家们建造了一个巨大的射电望远镜 用于接收宇宙射线.一天从 ...
- NOIP模拟赛 四校联考 递推 + 分类讨论 + 树上期望
NOIP 模拟题 题目名称兔子被子蚊子 源程序文件名rabbit.cpp quilt.cpp mosquito.cpp 输入文件名rabbit.in quilt.in mosquito.in 输出文件 ...
最新文章
- 1154:LETTERS
- 教科书上的LDA为什么长这样?
- FFMPEG音视频解码
- FZU Problem 2030 括号问题
- 私有5g网络_Verizon与诺基亚合作部署私有5G网络
- 为什么现在的很多酒店都不收押金,只收房费了?
- 物联网工程课程设计论文
- 为什么抖音网红城市都在西部?
- 新入手了台IBM Thinkpad T60笔记本 重装系统
- QNX 在车机系统中的应用
- 蓝牙配对,解决蓝牙多次连接不上的问题
- Web网站模板-横向滚动个人简历响应式网站模板(HTML+CSS+JavaScript)
- Android制作简单的计算器
- CPLEX中导入excel数据
- 【数学建模入门】时间序列|山猫数量预测
- TinyBERT论文及代码详细解读
- 记一次讲座与前辈的对话
- 基于spring boot 的学生科研项目共享平台 毕业设计-附源码271611
- 【每日新闻】Gartner:2017年CRM跃升为规模最大、增速最快的软件市场 | 中国科学家发现神奇半导体材料...
- 产品经理项目流程(二)——需求管理
热门文章
- sparkmllib scala NaiveBayes Demo
- 【问链-区块链基础知识系列】 第十五课 数字货币交易所的前世、今生和未来(二)
- JZOJ 5253. 排列与交换
- 【NOIP2013模拟】粉刷匠 题解代码
- js 数组修改watch_前端面试:专注Vue.js常见的问题答疑,掌握了基本上Vue就过关了...
- matlab中随机函数的具体使用方法
- AtCoder AGC022E Median Replace (字符串、自动机、贪心、计数)
- AtCoder AGC032F One Third (组合计数、DP、概率期望、微积分)
- vue赋值与ajax什么区别,Vue中ajax返回的结果赋值
- bugly怎么读_高级功能