CSP-ST3保龄球调
  • 板块学术版
  • 楼主SafariMo
  • 当前回复3
  • 已保存回复3
  • 发布时间2023/10/22 07:57
  • 上次更新2023/11/2 12:02:29
查看原帖
CSP-ST3保龄球调
820807
SafariMo楼主2023/10/22 07:57
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;

typedef long long LL;
typedef string str;
typedef pair<int,string > PII;
typedef long double lb;


#define x first
#define y second

int n,m,k,i,j;

int read() {
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9') {
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9') {
		x=(x<<3)+(x<<1)+c-48;
		c=getchar();
	}
	return x*f;
}

void write(int x) {
	if(x<0) {
		x=-x;
		putchar('-');
	}
	if(x<10) putchar(x+48);
	else {
		write(x/10);
		putchar(x%10+48);
	}
}

void writes(const int x,const char c) {
	write(x);
	putchar(c);
}

void read_s(int n,int a[]) {
	for(int i=1; i<=n; ++i) a[i]=read();
}

void write_s(const int n,const int a[]) {
	for(int i=1; i<n; ++i) writes(a[i],' ');
	writes(a[n],endl);
}


const int N=102;
int Sizeof[N];


string lei[N][N],Name[N][N];

string M[N];
int tot=0;
int K[N],wei[N];
unordered_map<int,string>p1;
unordered_map<string,int>p2;
unordered_map<string,int>p;
inline void init() {
	register string s;
	cin>>s;
	M[++tot]=s;
	K[tot]=read();
	int Maxi=-1;
	for(int i=1; i<=K[tot]; ++i) {
		cin>>lei[tot][i]>>Name[tot][i];
		int res=p[lei[tot][i]];
		Maxi=max(Maxi,res);
	}
	Sizeof[tot]=Maxi*K[tot];
	writes(Maxi*K[tot],' ');
	writes(Maxi,endl);
	wei[tot]=Maxi;
}
inline void write_str(const string s){
	for(register int i=0;i<(int)s.size();++i){
		putchar(s[i]);
	}
	putchar(endl);
}
signed main() {
	freopen("struct.in","r",stdin);
	freopen("struct.out","w",stdout);
	p["byte"]=1;
	p["short"]=2;
	p["int"]=4;
	p["long"]=8;
	n=read();
	int Size=-1;
	while(n--) {
		int op=read();
		if(op==1) {
			init();
		} else if(op==2) {
			string type,name;
			cin>>type>>name;
			bool flg=0;
			for(register int qq=1;qq<=tot;++qq)
			if(type==M[qq]){
				for(register int i=1;i<=K[qq];++i){
					const int PASTE=Size+1;
					p2[name+"."+Name[qq][i]]=PASTE;
					Size=Size+p[lei[qq][i]];
					for(register int j=PASTE;j<=Size;++j){
						p1[j]=name+"."+Name[qq][i];
					}
					const int Pst=Size+1;
					for(int j=Pst;j<=PASTE+Sizeof[qq];++j){
						p1[j]="ERR";
					}
					Size=PASTE+wei[qq]-1;
				}
				flg=1; 
				break;
			}
			if(flg) continue;
			const int PASTE=Size+1;
			Size+=p[type];
			for(register int i=PASTE;i<=Size;++i){
				p1[i]=name;
			}
			p2[name]=PASTE;
		} else if(op==3) {
			string s;
			cin>>s;
			writes(p2[s],endl);
		} else {
			int addr=read();
			if(addr>Size) puts("ERR");
			else{
				write_str(p1[addr]);
			}
		}
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
/*
10
1 a 2
short aa
int ab
2 a h
2 int p
3 h.ab
4 5
4 7
4 3
3 p
4 8
4 9
*/

期望得分 65 pts ABC 性质。

暴力模拟但是保龄。

2023/10/22 07:57
加载中...