ECNA 2013 部分题解 | 训练记录

Posted PushyTao

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ECNA 2013 部分题解 | 训练记录相关的知识,希望对你有一定的参考价值。

目录

提交链接

https://codeforces.com/gym/100291/submit

B . Cuckoo for Hashing [递归]


int n1, n2, m;
int a1[maxn], a2[maxn];
void modify(int f,int val) 
	if(f == 0) 
		if(a1[val % n1] == -1) a1[val % n1] = val;
		else 
			int pre = a1[val % n1];
			a1[val % n1] = val;
			modify(1,pre);
		
	 else 
		if(a2[val % n2] == -1) a2[val % n2] = val;
		else 
			int pre = a2[val % n2];
			a2[val % n2] = val;
			modify(0,pre);
		
	

int main() 
    int _ = 0;
    
    while (~scanf("%d%d%d", &n1, &n2, &m) && m) 
        memset(a1, -1, sizeof a1);
        memset(a2, -1, sizeof a2);
        printf("Case %d:\\n", ++_);
        for (int i = 1; i <= m; i++) 
  			modify(0,read);
        
        int c1 = 0,c2 = 0;
        for(int i=0;i<max(n1,n2);i++) 
        	if(a1[i] != -1) c1 ++;
        	if(a2[i] != -1) c2 ++;
        
        if(c1) 
        	puts("Table 1");
        	for(int i=0; i<n1; i++) 
				if(a1[i] != -1) 
					printf("%d:%d\\n",i,a1[i]);
				
			
        
        if(c2) 
        	puts("Table 2");
			for(int i=0; i<n2; i++) 
				if(a2[i] != -1) 
					printf("%d:%d\\n",i,a2[i]);
				
			
        
    
    return 0;

/**


**/

C . Playing Fair with Cryptography

队友传送门Code

#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;

char a[10][10];
int b[27];
int tx[27],ty[27];

char getNext(char ch,int &idx)
	if(idx==ch-'A') idx=(idx+1)%26;
	if(idx==9) idx++;
	ch=idx+'A';
	idx=(idx+1)%26;
	if(idx==9) idx++;
	return ch;


void cul(char u,char v,char &x,char &y)
	int tu=u-'A',tv=v-'A';
	if(tx[tu]==tx[tv])
		//cout<<"1"<<endl;
		//cout<<tu<<" "<<tx[tu]<<" "<<ty[tu]<<endl;
		//cout<<tv<<" "<<tx[tv]<<" "<<ty[tv]<<endl;
		//cout<<(ty[tu]+1)%5<<"***"<<(ty[tv]+1)%5<<endl;
		x=a[tx[tu]][(ty[tu]+1)%5];
		y=a[tx[tv]][(ty[tv]+1)%5];
		//cout<<x<<" "<<y<<endl;
	else if(ty[tu]==ty[tv])
		//cout<<"2"<<endl;
		x=a[(tx[tu]+1)%5][ty[tu]];
		y=a[(tx[tv]+1)%5][ty[tv]];
	else
		//cout<<"3"<<endl;
		x=a[tx[tu]][ty[tv]];
		y=a[tx[tv]][ty[tu]];
	


int main()
    int _,Case=1;cin>>_;
    while(_--)
    	string ss,s="",t="",tt;
    	if(Case==1) getchar();
    	getline(cin,ss);
    	getline(cin,tt);
    //	cout<<ss<<endl;
    //	cout<<tt<<endl;
    	for(int i=0;i<ss.size();i++)
    		if(ss[i]>='a'&&ss[i]<='z')
    			s+=ss[i]-'a'+'A';
			
			else if(ss[i]>='A'&&ss[i]<='Z')
				s+=ss[i];
			
		
		for(int i=0;i<tt.size();i++)
			if(tt[i]=='J') tt[i]='I';
			if(tt[i]>='a'&&tt[i]<='z') t+=tt[i]-'a'+'A';
			else if(tt[i]>='A'&&tt[i]<='Z') t+=tt[i];
		
		//cout<<s<<endl;
		//cout<<t<<endl;
    	int idx=0;
    	memset(b,0,sizeof b);
    	b[9]=1;
    	for(int i=0;i<5;i++)
    		for(int j=0;j<5;j++)
    			a[i][j]='*';
		for(int i=0;i<5;i++)
    		for(int j=0;j<5;j++)
    			while(b[s[idx]-'A']&&idx<s.size()) idx++;
    			if(idx<s.size())
    				a[i][j]=s[idx],b[s[idx]-'A']=1;
				
				else break;
			
		
		idx=0;
		for(int i=0;i<5;i++)
			for(int j=0;j<5;j++)
				if(a[i][j]!='*') continue;
				while(b[idx]) idx++;
				a[i][j]=idx+'A';
				b[idx]=1;
			
		for(int i=0;i<5;i++)
			for(int j=0;j<5;j++)
				//cout<<a[i][j]<<" ";
				tx[a[i][j]-'A']=i;
				ty[a[i][j]-'A']=j;
			
			//cout<<"\\n";
		
		idx=0;
		char x,y;
		string ans="";
		for(int i=0;i<t.size();i+=2)
			if(t[i]==t[i+1])
				cul(t[i],getNext(t[i],idx),x,y);
				i--;
			
			else if(i+2>t.size())
				cul(t[i],getNext(t[i],idx),x,y);
			
			else cul(t[i],t[i+1],x,y);
			ans=ans+x+y;
		
		cout<<"Case "<<Case++<<": "<<ans<<endl;
	
    return 0;

F . Super Phyllis

#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;

int n,a[1100][1100],Case=0,idx=0;
vector<int>g[1100]; 
map<string,int>mp;
map<int,string>mpp;
bool vis[1100];

void init()
	idx=0;mp.clear();mpp.clear();
	memset(a,0,sizeof a);
	for(int i=0;i<1100;i++) g[i].clear();


int cul(string s)
	if(!mp.count(s)) mp[s]=++idx,mpp[idx]=s;
	return mp[s];


bool bfs(int s,int t)
	queue<int>q;
	memset(vis,0,sizeof vis);
	vis[s]=1;q.push(s);
	while(!q.empty())
		int now=q.front();q.pop();
		if(now==t) return true;
		for(int i=0;i<g[now].size();i++)
			int j=g[now][i];
			if(!a[now][j]) continue;
			if(!vis[j])
				vis[j]=1;q.push(j);
			
		
	
	return false;


int main()
    while(~scanf("%d",&n))
    	if(n==0) break;
    	init();
    	for(int i=1;i<=n;i++)
    		string su,sv;
    		cin>>su>>sv;
    		int u=cul(su),v=cul(sv);
    		g[u].push_back(v);
    		a[u][v]=1;
		
		vector<string>ans;	
		for(int i=1;i<=idx;i++)
			for(int j=0;j<g[i].size();j++)
				int now=g[i][j];
				a[i][now]=0;
				if(!bfs(i,now))
					a[i][now]=1;
				else
					ans.push_back(mpp[i]+","+mpp[now]);
			
		
		sort(ans.begin(),ans.end());
		cout<<"Case "<<++Case<<": "<<ans.size();
		for(int i=0;i<ans.size();i++)
			cout<<" "<<ans[i];
		cout<<"\\n";
	
    return 0;

H . The Urge to Merge

#include <bits/stdc++.h>

typedef long long ll;

#pragma region Debug
template<typename T>
std::istream& operator>> (std::istream& in, std::vector<T>& vt)

以上是关于ECNA 2013 部分题解 | 训练记录的主要内容,如果未能解决你的问题,请参考以下文章

ECNA 2014 部分题解 | 训练记录0703

APAC 2013 部分题解 | 训练记录

APAC 2013 部分题解 | 训练记录

"蔚来杯"2022牛客暑期多校训练营6部分题题解

组队训练2013南京区域赛

组队训练2013长沙区域赛