ssl提高组国庆模拟赛【2018.10.5】

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

前言

竟然有半IOI赛制(雾)


成绩

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 m y s e l f 2017myself 150 150 60 60 90 90 0 0
2 2 2015 h j w 2015hjw 140 140 100 100 40 40 0 0
3 3 2015 z y f 2015zyf 100 100 80 80 20 20 0 0
4 4 2017 l r z 2017lrz 100 100 100 100 0 0 0 0
5 5 2017 z y c 2017zyc 90 90 0 0 90 90 0 0
6 6 2017 x j q 2017xjq 90 90 0 0 90 90 0 0
7 7 2017 x x y 2017xxy 90 90 0 0 90 90 0 0
8 8 2017 h j q 2017hjq 60 60 0 0 60 60 0 0
9 9 2015 z z y 2015zzy 50 50 0 0 50 50 0 0
10 10 2017 l w 2017lw 40 40 10 10 20 20 10 10

正题


T 1 : n s s l 1174 T1:nssl1174- 阶乘【 ! ! 基础 ! ! 数论】

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


T 2 : n s s l 1175 T2:nssl1175- S S 练跑步【 b f s bfs

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


T 3 : n s s l 1176 T3:nssl1176- 轨道【数论 , D p ,Dp

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


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


T1 60分code

#include<cstdio>
#define N 100010
using namespace std;
int n,a,p[N],m,ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a);
		for(int j=2;j*j<=a;j++)
		  while(!(a%j))
		  	p[j]++,a/=j,ans++;
		if(a>1) p[a]++,ans++;
	}
	m=1;
	while(true)
	{
		if(!ans) break;
		m++;a=m;
		for(int j=2;j*j<=a;j++)
		  while(!(a%j))
		  {
		    if(p[j])
		  	  p[j]--,ans--;
		  	a/=j;
		  }
		if(a<=100000&&p[a]) p[a]--,ans--;
	}
	printf("%d",m);
}

T2 50分SPFAcode

#include<cstdio>
#include<queue>
#include<algorithm>
#include<iostream>
#include<cstring>
#define N 510
using namespace std;
const int dx[5]={0,-1,0,0,1},dy[5]={0,0,-1,1,0};
struct node{
	int x,y,f;
};
queue<node> q;
int a[N][N],v[N][N][5],n,m,iq[N][N][5];
char c;
int bfs()
{
	memset(v,127/3,sizeof(v));
	if(a[1][1]==0) return 2147483647;
	if(a[1][1]!=1)
	{
		q.push((node){1,1,1});
		iq[1][1][1]=1;
		v[1][1][1]=0;
	}
	if(a[1][1]!=2)
	{
		q.push((node){1,1,2});
		iq[1][1][2]=1;
		v[1][1][2]=0;
	}
	if(a[1][1]!=3)
	{
		q.push((node){1,1,3});
		iq[1][1][3]=1;
		v[1][1][3]=0;
	}
	if(a[1][1]!=4)
	{
		q.push((node){1,1,4});
		iq[1][1][4]=1;
		v[1][1][4]=0;
	}
	while(!q.empty())
	{
		int x=q.front().x,y=q.front().y,f=q.front().f;
		for(int k=1;k<=4;k++)
		{
			if(a[x][y]!=k&&v[x][y][k]>v[x][y][f]+1)
			{
				//printf("Trun %d,%d %d->%d\n",x,y,f,k);
				v[x][y][k]=v[x][y][f]+1;
				if(!iq[x][y][k])
				{
					iq[x][y][k]=true;
					q.push((node){x,y,k});
				}
			}
		}
		if(x+dx[f]>0&&x+dx[f]<=n&&y+dy[f]>0&&y+dy[f]<=m
		&&a[x+dx[f]][y+dy[f]]&&a[x+dx[f]][y+dy[f]]!=f
		&&v[x+dx[f]][y+dy[f]][f]>v[x][y][f])
		{
			//printf("Go %d,%d->%d,%d\n",x,y,x+dx[f],y+dy[f]);
			v[x+dx[f]][y+dy[f]][f]=v[x][y][f];
			if(!iq[x+dx[f]][y+dy[f]][f])
			{
				iq[x+dx[f]][y+dy[f]][f]=true;
				q.push((node){x+dx[f],y+dy[f],f});
			}
		}
		iq[x][y][f]=false;
		q.pop();
	}
	return min(min(v[n][m][1],v[n][m][2]),min(v[n][m][3],v[n][m][4]));
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	  for(int j=1;j<=m;j++)
	  {
	  	cin>>c;
		if(c=='U') a[i][j]=1;
		else if (c=='D') a[i][j]=4;
		else if (c=='L') a[i][j]=2;
		else if (c=='R') a[i][j]=3;
		else a[i][j]=0;
	  }
	a[n][m]=1;
	int ans=bfs();
	if(ans>=707406000) printf("No Solution");
	else printf("%d",ans);
}

T2 90分code

#include<cstdio>
#include<queue>
#include<algorithm>
#include<iostream>
#define N 510
using namespace std;
const int dx[5]={0,-1,0,0,1},dy[5]={0,0,-1,1,0};
struct node{
	int x,y,w;
};
queue<node> q;
int a[N][N],path[N][N],n,m;
char c;
int bfs()
{
	q.push((node){1,1,-1});
	while(!q.empty())
	{
		int x=q.front().x,y=q.front().y,w=q.front().w;
		q.pop();
		for(int k=1;k<=4;k++)
		{
			int dis=1;
			while(x+dx[k]*dis<=n&&x+dx[k]*dis>0&&y+dy[k]*dis<=m&&y+dy[k]*dis>0
			&&a[x+dx[k]*(dis-1)][y+dy[k]*(dis-1)]!=k&&a[x+dx[k]*dis][y+dy[k]*dis])
			{
				if(!path[x+dx[k]*dis][y+dy[k]*dis])
				{
					q.push((node){x+dx[k]*dis,y+dy[k]*dis,w+1});
					path[x+dx[k]*dis][y+dy[k]*dis]=1;
					if(x+dx[k]*dis==n&&y+dy[k]*dis==m) 
					  return w+1;
				}
				dis++;
			}
		}
	}
	return -1;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	  for(int j=1;j<=m;j++)
	  {
	  	cin>>c;
		if(c=='U') a[i][j]=1;
		else if (c=='D') a[i][j]=4;
		else if (c=='L') a[i][j]=2;
		else if (c=='R') a[i][j]=3;
		else a[i][j]=0;
	  }
	int ans=bfs();
	if(ans==-1) printf("No Solution");
	else printf("%d",ans);
}

尾声

没了

猜你喜欢

转载自blog.csdn.net/Mr_wuyongcong/article/details/82947141