Codeforces Round #279 (Div. 2) B F
来源:互联网 发布:0712.com 棋牌源码 编辑:程序博客网 时间:2024/05/17 07:59
B.Queue
题目链接:http://codeforces.com/contest/490/problem/B
思路:存一个序列的表 然后直接分别从最左边的点,和最左边第二个点开始进行填充即可。
code:
#include <cstdio>#include <cstdlib>#include <iostream>#include <cstring>using namespace std;const int maxn=1000100;const int maxm=200100;int a[maxn];int aa[maxm];int flag[maxn];int main(){ int n,t1,t2,t3; int s,t,cnt; cin>>n; memset(a,-1,sizeof(a)); memset(flag,0,sizeof(flag)); for(int i=0;i<n;i++){ cin>>s>>t; if(s==0) t2=t; if(t==0) t3=s; if(t!=0&&s!=0) a[s]=t; if(t!=0&&s!=0){ flag[s]++; flag[t]+=2; } } cnt=1; aa[cnt]=t2; flag[t2]=0; for(int i=a[t2];i!=-1;i=a[i]){ cnt+=2; aa[cnt]=i; flag[i]=0; } aa[n-2]=t3; if(n>=3){ for(int i=0;i<1000000;i++) if(flag[i]==1) t1=i; cnt=0; aa[cnt]=t1; for(int i=a[t1];i!=-1;i=a[i]){ cnt+=2; aa[cnt]=i; } } for(int i=0;i<n;i++) printf("%d%c",aa[i],i==n-1? '\n':' '); return 0;}
F. Treeland Tour
题目链接:http://codeforces.com/contest/490/problem/F
题意:给一棵树,求出树上所有路径的最长上升子序列的最大值。
思路:因为序列肯定是越长越好 所以我们可以枚举每个叶子节点作为每个序列的起点 然后再用正常的做最长上升子序列的方法dfs回溯就行,其复杂度为n^2logn,感觉还是很好想的。
code:
By io07, contest: Codeforces Round #279 (Div. 2), problem: (F) Treeland Tour, Accepted, # #include <bits/stdc++.h>#define INF 1000000000using namespace std;const int maxn=6050;const int maxe=20500;struct edge{ int to,next;} P[maxe];int head[maxn],si;void add_edge(int s,int t){ P[si].to=t; P[si].next=head[s]; head[s]=si++;}//dp[i]表示长度为i+1的上升子序列中末尾元素的最小值int dp[maxn],res;int val[maxn],du[maxn];int V;void dfs(int v,int fa){ int pos=lower_bound(dp,dp+V,val[v])-dp; res=max(res,pos+1); int mid=dp[pos]; dp[pos]=val[v]; for(int i=head[v];i!=-1;i=P[i].next){ int u=P[i].to; if(u==fa) continue; dfs(u,v); } dp[pos]=mid;}void solve(){ res=0; for(int i=1;i<=V;i++){ if(du[i]==1){ fill(dp,dp+V,INF); dfs(i,-1); } } printf("%d\n",res);}int main(){ int s,t; scanf("%d",&V); for(int i=1;i<=V;i++) scanf("%d",&val[i]); memset(head,-1,sizeof(head)); memset(du,0,sizeof(du)); si=0; for(int i=1;i<V;i++){ scanf("%d%d",&s,&t); add_edge(s,t); add_edge(t,s); du[s]++; du[t]++; } solve(); return 0;}
0 0
- Codeforces Round #279 (Div. 2) B F
- Codeforces Round #279 (Div. 2) F
- Codeforces Round #279 (Div. 2) F
- Codeforces Round #279 (Div. 2)B. Queue
- Codeforces Round #279 (Div. 2) B. Queue
- Codeforces Round #279 (Div. 2) F. Treeland Tour
- Codeforces Round #277.5 (Div. 2) F
- Codeforces Round #277.5 (Div. 2)F题
- Codeforces Round #322 (Div. 2) F
- Codeforces Round #377 (Div. 2) F
- Codeforces Round #386 (Div. 2) F
- Codeforces Round #441 Div. 2 E,F
- Codeforces Round #442 (Div. 2) 877 F
- Codeforces Round #423 Div.2 A B C D E F
- Codeforces Round #424 Div.2 A B C D E F
- 解题报告:Codeforces Round #424 (Div. 2) A B C D E F
- Codeforces Round #279 (Div. 2) (B题)
- Codeforces Round #279 (Div. 2) —— B
- sprintf用法
- Solr入门之SolrServer实例化方式
- adMob iAd整合,随机根据网络状况自动显示。
- geotrace--机房网络质量一键测试利器
- java poi实现excel的导出
- Codeforces Round #279 (Div. 2) B F
- 杨氏矩阵的算法问题
- 我想和你一起,在某个小镇,风在风中淡淡的吹
- YUV420P 旋转90度(逆时针)
- Selenium WebDriver的操作说明
- Hibernate各种主键生成策略与配置详解(转)
- Java枚举类型的使用
- 《C#高级教程》学习笔记1
- Android相关各种开发工具下载地址