2020 ICPC银川 个人题解


title : 2020 ICPC银川 个人题解
date : 2022-11-21
tags : ACM,题解,练习记录
author : Linno


2020 ICPC银川 个人题解

题目链接:https://codeforces.com/gym/104022

补题进度:5/13

A-Best Player

#include 
using namespace std;
int n,x,y,z,a[500][500],b[500][500],c[500][500],X,Y,Z;
int main()
{
	cin>>n;
	for (int i=1;i<=n;++i)
	{
		scanf("%d%d%d",&x,&y,&z);
		a[x+100][y+100]++;
		if (a[x+100][y+100]==1) Z++;
		b[x+100][z+100]++;
		if (b[x+100][z+100]==1) Y++;
		c[y+100][z+100]++;
		if (c[y+100][z+100]==1) X++;
	}
	int maxi=max(Z,max(X,Y));
	if (X==maxi) puts("X");
	else if (Y==maxi) puts("Y");
	else puts("Z");
	return 0;
}

B-The Great Wall

#include 
using namespace std;
string st[]={"-F","-Cl","-Br","-I","-CH3","-CH2CH3","-CH2CH2CH3","-H"};
string s1,s2,s3,s4;
int T,a1,a2,a3,a4;
int main()
{
	cin>>T;
	while (T--)
	{
		cin>>s1>>s2>>s3>>s4;
		if (s1==s3||s2==s4) { puts("None"); continue; }
		else
		if (s1==s2||s3==s4) { puts("Cis"); continue; }
		else 
		if (s1==s4||s2==s3) { puts("Trans"); continue; }
		else
		{
			for (int i=0;i<=7;++i)
			{
				if (s1==st[i]) a1=i;
				if (s2==st[i]) a2=i;
				if (s3==st[i]) a3=i;
				if (s4==st[i]) a4=i;
			}
			if (a1<a3)
			{
				if (a2<a4) puts("Zasamman");
				else puts("Entgegen");
			}
			else
			{
				if (a2>a4) puts("Zasamman");
				else puts("Entgegen");
			}
		}
	}
	return 0;
}

E-Isomerism

#include 
using namespace std;
string st[]={"-F","-Cl","-Br","-I","-CH3","-CH2CH3","-CH2CH2CH3","-H"};
string s1,s2,s3,s4;
int T,a1,a2,a3,a4;
int main()
{
	cin>>T;
	while (T--)
	{
		cin>>s1>>s2>>s3>>s4;
		if (s1==s3||s2==s4) { puts("None"); continue; }
		else
		if (s1==s2||s3==s4) { puts("Cis"); continue; }
		else 
		if (s1==s4||s2==s3) { puts("Trans"); continue; }
		else
		{
			for (int i=0;i<=7;++i)
			{
				if (s1==st[i]) a1=i;
				if (s2==st[i]) a2=i;
				if (s3==st[i]) a3=i;
				if (s4==st[i]) a4=i;
			}
			if (a1<a3)
			{
				if (a2<a4) puts("Zasamman");
				else puts("Entgegen");
			}
			else
			{
				if (a2>a4) puts("Zasamman");
				else puts("Entgegen");
			}
		}
	}
	return 0;
}

J-Let’s Play Jigsaw Puzzles!

#include
#define pii pair<int,int>
#define mk make_pair
using namespace std;
const int N=1e6+7;

int dx[]={-1,1,0,0},dy[]={0,0,-1,1};
int n,m,mp[1005][1005],vis[N];

struct E{
	int s[5];
	E(){memset(s,0,sizeof(s));} 
	void in(){cin>>s[0]>>s[1]>>s[2]>>s[3];}
}p[N];

struct Nod{
	int x,y,id;
};

pii getid(int id){
	int x=(id-1)/m+1,y=id%m+1; 
}

void solve(){
	cin>>m;
	n=m*m;
	queue<Nod>q;
	for(int i=1;i<=n;++i){
		p[i].in();
		int idx=0;
		for(int j=0;j<4;++j) if(p[i].s[j]==-1) ++idx;
		if(idx>=2){
			if(p[i].s[0]==-1&&p[i].s[2]==-1) q.emplace((Nod){1,1,i});
			if(p[i].s[0]==-1&&p[i].s[3]==-1) q.emplace((Nod){1,m,i});
			if(p[i].s[1]==-1&&p[i].s[2]==-1) q.emplace((Nod){m,1,i});
			if(p[i].s[1]==-1&&p[i].s[3]==-1) q.emplace((Nod){m,m,i});
			vis[i]=1;
		}
	}
	while(q.size()){
		Nod fro=q.front();
		q.pop();
		mp[fro.x][fro.y]=fro.id;
		for(int d=0;d<4;++d){
			int nx=fro.x+dx[d],ny=fro.y+dy[d];
			if(nx>=1&&nx<=m&&ny>=1&&ny<=m&&!vis[p[fro.id].s[d]]){
				vis[p[fro.id].s[d]]=1;
				q.emplace((Nod){nx,ny,p[fro.id].s[d]});
			}
		}
	}
	for(int i=1;i<=m;++i){
		for(int j=1;j<=m;++j){
			cout<<mp[i][j]<<" \n"[j==m];
		}
	}
}

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int T=1;
	while(T--){
		solve();
	}
	return 0;
}

K-Browser Games

#include
#define int long long 
using namespace std;
const int N=10007;

int n,a[N],dp[2][N][5];

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;++i) cin>>a[i];
	for(int i=0;i<=1;++i) for(int j=0;j<=n;++j) for(int k=0;k<=3;++k) dp[i][j][k]=-0x3f3f3f3f;
	dp[0][0][3]=0;
	int fg=1;
	for(int i=1;i<=n;++i){ //枚举前i个数 
		for(int j=1;j<=n;++j){ //枚举段数j
			dp[fg][j][0]=max(dp[fg][j][0],dp[fg^1][j-1][3]);
			dp[fg][j][0]=max(dp[fg][j][0],dp[fg^1][j][0]);
			
			dp[fg][j][1]=max(dp[fg][j][1],dp[fg^1][j-1][3]-a[i]);
			dp[fg][j][1]=max(dp[fg][j][1],dp[fg^1][j][1]);
			dp[fg][j][1]=max(dp[fg][j][1],dp[fg^1][j][0]-a[i]);
			
			dp[fg][j][2]=max(dp[fg][j][2],dp[fg^1][j-1][3]+a[i]);
			dp[fg][j][2]=max(dp[fg][j][2],dp[fg^1][j][2]);
			dp[fg][j][2]=max(dp[fg][j][2],dp[fg^1][j][0]+a[i]);

			dp[fg][j][3]=max(dp[fg][j][3],dp[fg^1][j][3]);
			dp[fg][j][3]=max(dp[fg][j][3],dp[fg^1][j-1][3]);
			dp[fg][j][3]=max(dp[fg][j][3],dp[fg^1][j][2]-a[i]);
			dp[fg][j][3]=max(dp[fg][j][3],dp[fg^1][j][1]+a[i]);
			//cout<
		}
		fg^=1;
	}
	for(int i=1;i<=n;++i){
		cout<<dp[fg^1][i][3]<<"\n";
	}
	return 0;
}

你可能感兴趣的:(数学,ACM,练习记录,算法,c++,图论,深度优先,动态规划)