ssl提高组周二备考赛【2018.10.30】

版权声明:原创,未经作者允许禁止转载 https://blog.csdn.net/Mr_wuyongcong/article/details/83541563

前言

依旧想去德育基地…


成绩

R a n k Rank P e r s o n Person S c o r e Score A A B B C C
1 1 2017 x x y 2017xxy 210 210 40 40 100 100 70 70
2 2 2017 m y s e l f 2017myself 190 190 20 20 100 100 70 70
3 3 2017 l x f 2017lxf 180 180 0 0 90 90 90 90
4 4 2017 z y c 2017zyc 170 170 0 0 100 100 70 70
5 5 2017 z y x 2017zyx 150 150 40 40 60 60 50 50
6 6 2017 x j q 2017xjq 130 130 0 0 100 100 30 30
7 7 2017 l r z 2017lrz 100 100 10 10 90 90 0 0
7 7 2013 l y k 2013lyk 100 100 0 0 100 100 0 0
9 9 2015 z y f 2015zyf 90 90 20 20 0 0 70 70
10 10 2013 l x h 2013lxh 90 90 0 0 90 90 0 0

正题


T 1 : n s s l 1254 A ( T1:nssl1254-A( 林下风气 ) ) 【树形 d p dp

博客链接:
https://blog.csdn.net/Mr_wuyongcong/article/details/83541098


T 2 : n s s l 1255 B ( T2:nssl1255-B( 轻功 ) ) S P F A , SPFA, 分层图】

博客链接:
https://blog.csdn.net/Mr_wuyongcong/article/details/83541258


T 3 : n s s l 1256 C ( T3:nssl1256-C( 盟主的忧虑 ) ) 【并查集】

博客链接:
https://blog.csdn.net/Mr_wuyongcong/article/details/83541476


s o m e   o f   c o d e some\ of\ code


T2 20分code

#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 4000
#define XJQ 19260817
using namespace std;
struct node{
	int to,next;
}a[N];
int ls[N],w[N],maxs,mins,ans,n,k,tot,x,y,in[N];
void addl(int x,int y)
{
	a[++tot].to=y;
	a[tot].next=ls[x];
	ls[x]=tot;
}
void dp1()
{
	for(int i=1;i<=n;i++)
	{
		maxs=0;
		mins=2147483647;
		for(int j=i;j<=n;j++)
		{
			maxs=max(maxs,w[j]);
			mins=min(mins,w[j]);
			if(maxs-mins==k) ans++;
		}
	}
	printf("%d",ans);
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	    scanf("%d",&w[i]);
	for(int i=1;i<n;i++)
	{
	    scanf("%d%d",&x,&y);
	    addl(x,y);addl(y,x);
	    in[x]++;in[y]++;
	    maxs=max(maxs,max(in[x],in[y]));
	}
	if(maxs<=2)
		dp1();
	else printf("0");
}

T3 70分code

#include<cstdio>
#include<algorithm>
#define N 100010
using namespace std;
struct node{
	int to,w,next,from;
}a[N];
int ls[N],tot,x,y,w,ans,dep[N],n,m,S,dfn[N],end[N],cnt;
void addl(int x,int y,int w)
{
	a[++tot].to=y;a[tot].w=w;
	a[tot].next=ls[x];ls[x]=tot;
	a[tot].from=x;
}
void dfs(int x,int fa)
{
	dfn[x]=++cnt;
	dep[x]=dep[fa]+1;
	for(int i=ls[x];i;i=a[i].next)
	  if(i<S)
	  {
		  int y=a[i].to;
		  if(y==fa) continue;
		  dfs(y,x);
	  }
	end[x]=cnt;
}
bool cmp(node x,node y)
{return x.from<y.from;}
int next(int x)
{
	while(dep[a[x].from]>dep[a[x].to]) x++;
	return x;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		addl(x,y,0);
		addl(y,x,0);
	}
	S=tot+1;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d%d",&x,&y,&w);
		addl(x,y,w);
	}
	dfs(1,0);
	for(int i=1;i<S;i+=2)
	{
		ans=2147483647;
		int x=a[i].to;
		if(dep[a[i].to]<dep[a[i+1].to]) x=a[i+1].to;
	    for(int j=S;j<=tot;j++)
	      if(dfn[a[j].to]>=dfn[x]&&dfn[a[j].to]<=end[x]&&
		  (dfn[a[j].from]<dfn[x]||dfn[a[j].from]>end[x])
		  ||
			dfn[a[j].from]>=dfn[x]&&dfn[a[j].from]<=end[x]&&
		  (dfn[a[j].to]<dfn[x]||dfn[a[j].to]>end[x]))
	           ans=min(ans,a[j].w);
	    if(ans==2147483647) printf("-1\n");
	    else printf("%d\n",ans);
	}
}

尾声

话说题目又ABC。老师改题面了

猜你喜欢

转载自blog.csdn.net/Mr_wuyongcong/article/details/83541563
今日推荐