2023天梯赛题解

L1

最好的文档

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
const ll maxn=1e5+10;

int main()
{
	cout<<"Good code is its own best documentation."<<endl; 
	return 0;
}

什么是机器学习

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
const ll maxn=1e5+10;

int main()
{
	ll a,b;
	cin>>a>>b;
	cout<<a+b-16<<endl;
	cout<<a+b-3<<endl;
	cout<<a+b-1<<endl; 
	cout<<a+b<<endl;
	return 0;
}

程序员买包子

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
const ll maxn=1e5+10;

int main()
{
	string x;
	ll n,m,k;
	cin>>n>>x>>m>>k;
	if(k==n) cout<<"mei you mai "<<x<<" de" <<endl;
	else if(k==m) cout<<"kan dao le mai "<<x<<" de"<<endl;
	else cout<<"wang le zhao mai "<<x<<" de"<<endl; 
	return 0;
}

进化论

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
const ll maxn=1e5+10;
void solve(){
	ll a,b,c;
	cin>>a>>b>>c;
	if(c==a*b){
		cout<<"Lv Yan"<<endl;
	}else if(c==a+b) cout<<"Tu Dou"<<endl;
	else cout<<"zhe du shi sha ya!"<<endl;
}
int main()
{
	ll t;
	cin>>t;
	while(t--){
		solve();
	}
	
	return 0;
}

猜帽子游戏

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
const ll maxn=1e5+10;
ll a[maxn];
ll n;
void solve(){
	ll cai=0;
	ll dui=0;
	ll cuo=0;
	for(ll i=1;i<=n;i++){
		ll x;
		cin>>x;
		if(x==0) continue;
		cai=1;
		if(x==a[i]) dui=1;
		else cuo=1;
	}
	if(cuo==0&&dui==1) cout<<"Da Jiang!!!"<<endl;
	else cout<<"Ai Ya"<<endl;
}
int main()
{
	cin>>n;
	for(ll i=1;i<=n;i++) cin>>a[i];
	ll t;
	cin>>t;
	while(t--){
		solve();
	}
	
	return 0;
}

剪切粘贴

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
const ll maxn=1e5+10;
string s; 
void solve(){
	ll l,r;
	string sl,sr;
	cin>>l>>r>>sl>>sr;
	string t=s.substr(l-1,r-l+1);
	s.erase(l-1,r-l+1);
	string slr=sl+sr;
	ll loc=s.find(slr);
	if(loc==string::npos){
		s+=t;
	}else s.insert(loc+sl.length(),t);
}
int main()
{
	getline(cin,s);
	ll t;
	cin>>t;
	while(t--){
		solve();
	} 
	cout<<s<<endl;
	return 0;
}

分寝室

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
const ll maxn=1e5+10;
ll n0,n1,n;
ll ans=maxn;
void solve(){
	cin>>n0>>n1>>n;
	ll f,m,nf,nm,ansf,ansm;
	for(ll i=2;i<=n0;i++){//人数 
		nf=i;//人数 
		if(n0%nf==0){
			f=n0/nf;//房间数量 
			m=n-f;
			if(n1%m==0){
				nm=n1/m;//人数
				if(nm!=1&&ans>abs(nm-nf)){
					ans=abs(nm-nf);
					ansf=f,ansm=m;
				} 	
			}
		}
	}
	if(ans==maxn){
		cout<<"No Solution"<<endl;
		return ;
	}
	cout<<ansf<<' '<<ansm<<endl;
//	cout<<ans<<endl;
}
int main()
{
	
	solve(); 
	return 0;
}

谁管谁叫爹

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
const ll maxn=1e5+10;
ll cal(ll x){
	ll sum=0;
	while(x!=0){
		sum+=x%10;
		x/=10;
	}
	return sum;
}
void solve(){
	ll na,nb; 
	cin>>na>>nb;
	ll sa=cal(na);
	ll sb=cal(nb);
	if((na%sb==0&&nb%sa==0)||(na%sb!=0&&nb%sa!=0)){
		if(na>nb) cout<<"A"<<endl;
		else cout<<"B"<<endl;
	}
	else if(na%sb==0) cout<<"A"<<endl;
	else if(nb%sa==0) cout<<"B"<<endl;
}
int main()
{
	ll t; 
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

L2

堆宝塔

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
const ll maxn=1e5+10;
ll n,ans,num=0;
stack<ll>a,b;
ll c[maxn];
void a_pop(){
	num++;
	ans=max(ans,(ll)(a.size()));
	while(a.empty()!=1){
		a.pop();
	}
}
void b_push(ll x){
	while(b.empty()!=1){
		ll t=b.top();
		if(t>x){
			b.pop();
			a.push(t);
		}else break;
	}
	a.push(x);
}
void solve(){
	cin>>n;
	for(ll i=1;i<=n;i++) cin>>c[i];
	for(ll i=1;i<=n;i++){
		if(a.empty()==1||(a.top()>c[i])){
			a.push(c[i]);
		}else if(b.empty()==1||b.top()<c[i]){
			b.push(c[i]);
		}else {
			a_pop();
			b_push(c[i]);
		}
	}
	if(a.empty()!=1){
		num++;
		ans=max(ans,(ll)(a.size()));
	}
	if(b.empty()!=1){
		num++;
		ans=max(ans,(ll)(b.size()));
	}
	cout<<num<<' '<<ans<<endl;
}
int main()
{
	ll t; 
	t=1;
	while(t--){
		solve();
	}
	return 0;
}

天梯赛的赛场安排

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
const ll maxn=1e6+9e5;
ll ct=0;
ll n,c,idx=0;
ll ans[maxn];
string name[maxn];
ll place[maxn];
map<string ,ll>mp;
struct cmp{
	bool operator()(const pair<ll,ll> &x,const pair<ll,ll> & y)const {
		if(x.second!=y.second) return x.second<y.second;
		return x.first>y.first;
	}
};
pair<ll,ll>p;
priority_queue<pair<ll,ll>,vector<pair<ll,ll> > ,cmp>pr;
ll find(ll x){
	for(ll i=1;i<=idx;i++){
		if(place[i]>=x){
			return i;
		}
	}
	return -1;
}
void solve(){
	cin>>n>>c;
	for(ll i=1;i<=n;i++){
		string s;
		ll x;
		cin>>s>>x;
		name[i]=s;
		p=make_pair(i,x);
		pr.push(p);
	}
	while(pr.empty()!=1){
		p=pr.top();
		pr.pop();
		ll pn=p.first,pp=p.second;
		if(pp==0) continue;
		ans[pn]++;
		if(pp>=c){
			ct++;
			p.second-=c;
			pr.push(p);
		}else if(pp<c){
			ll loc=find(pp);
			if(loc!=-1){
				place[loc]-=pp;
			}else {
				idx++;
				ct++;
				place[idx]=c-pp;
			}
		}
	}
	for(ll i=1;i<=n;i++){
		cout<<name[i]<<' '<<ans[i]<<endl;
	}
	cout<<ct<<endl;
}
int main()
{
	ll t; 
	t=1;
	while(t--){
		solve();
	}
	return 0;
}

锦标赛

(不会)

寻宝图

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
const ll maxn=1e5+10;
ll n,m;
string vis[maxn],s[maxn]; 
ll xx[101]={0,0,1,0,-1};
ll yy[101]={0,1,0,-1,0};
ll ans=0,cnt=0;
ll flag=0;
void show(){
	for(ll i=0;i<n;i++){
		for(ll j=0;j<m;j++){
			cout<<vis[i][j];
		}
		cout<<endl;
	}
}
void init(){
	string t="";
	for(ll i=1;i<=m;i++){
		t+='0';
	}
	for(ll i=0;i<n;i++){
		vis[i]=t;
	}
}
void dfs(ll x,ll y){
	vis[x][y]='1';
	if(s[x][y]!='1'){
		flag=1;
	}
	for(ll i=1;i<=4;i++){
		ll tx=x+xx[i];
		ll ty=y+yy[i];
		if(tx<0||tx>=n||ty<0||ty>=m||vis[tx][ty]=='1'||s[tx][ty]=='0') continue;
		dfs(tx,ty);
	}
}
void solve(){
	cin>>n>>m;
	init();
	for(ll i=0;i<n;i++) cin>>s[i];
	for(ll i=0;i<n;i++){
		for(ll j=0;j<m;j++){
			if(s[i][j]!='0'&&vis[i][j]=='0'){
				flag=0;
				dfs(i,j);
				cnt++;
				ans+=flag;
			}
		}
	}
	cout<<cnt<<' '<<ans<<endl;
}

int main()
{
	ll t; 
	t=1;
	while(t--){
		solve();
	}
	return 0;
}

L3

超能力者大赛(5/30)部分正确

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
const ll maxn=1e5+10;
const ll inf=1e5+10;
ll die=1,nd=0;//当前死亡人数,当前天数 
ll game=0;
ll n,m,me,d;
ll npos,nabi;
ll cnt=0;
ll vis[maxn];
ll head[maxn];
struct people{
	ll abi,pos;
}man[maxn];
struct edge{
	ll v,nex,val;
}e[maxn<<1];
ll g[510][510];
ll path[510][510];
void add(ll u ,ll v,ll val){
	cnt++;
	e[cnt].v=v;
	e[cnt].val=val;
	e[cnt].nex=head[u];
	head[u]=cnt;	
}
void init(){
	for(ll i=0;i<n;i++){
		for(ll j=0;j<n;j++){
			if(i==j){
				g[i][j]=0;
				path[i][j]=0;
			} else{
				g[i][j]=inf;
				path[i][j]=inf;
			}
		}
	}
}
void floyd(){
	for(ll k=0;k<m;k++){
		for(ll i=0;i<m;i++){
			for(ll j=0;j<m;j++){
				if(g[i][j]>g[i][k]+g[k][j]){
					g[i][j]=g[i][k]+g[k][j];
					path[i][j]=path[i][k]+path[k][j];
				}else if(g[i][j]==g[i][k]+g[k][j]){
					path[i][j]=min(path[i][j],path[i][k]+path[k][j]);
				}
			}
		}
	}
}
ll find(){
	ll nex=-1;//下一个人的编号,途径城市,距离
	for(ll i=0;i<n;i++){
		if(vis[i]==1||nabi<man[i].abi) continue;
//		最近  途径城市最少 编号最小	
		if(nex==-1){
			nex=i;
			continue;
		}
		if(man[i].abi>man[nex].abi){
			nex=i;
		}else if(man[i].abi==man[nex].abi){
			if(g[npos][man[nex].pos]>g[npos][man[i].pos]){
				nex=i;
			}else if(g[npos][man[nex].pos]==g[npos][man[i].pos]){
				if(path[npos][man[nex].pos]>path[npos][man[i].pos]){
					nex=i;
				}else if(path[npos][man[nex].pos]==path[npos][man[i].pos]){
					if(man[nex].pos>man[i].pos){
						nex=i;
					}
				}
			}
		}
	}
	return nex;
}
void move(ll nex){
//	cout<<"num!!!!"<<nex<<endl;
	if(nd+g[npos][man[nex].pos]>d){
		game=1;
		return ;
	}
	cout<<"Move from "<<npos<<" to "<<man[nex].pos<<"."<<endl;
//	cout"Move from "<<city1 to city2."
	die++;
	vis[nex]=1;
	nd+=g[npos][man[nex].pos];
	if(nd+1>d){
		game=1;
		return ;
	}
	nd++;
	
//	cout<<"day"<<d<<endl;
	cout<<"Get "<<man[nex].abi<<" at "<<man[nex].pos<<" on day "<<nd<<"."<<endl;
	nabi+=man[nex].abi;
	npos=man[nex].pos;
}
void join(ll nex){//弱的合并  
	ll fir=-1;
	ll flag=0;
	for(ll i=0;i<n;i++){
		if(vis[i]==1||man[i].pos!=man[nex].pos) continue;
		if(man[i].abi<=nabi){
			if(fir==-1){
				fir=i;
			}else {
				man[fir].abi+=man[i].abi;
				vis[i]=1;
				die++;
			}
		}
	}	
	return ;//返回0表示没有比他强的,返回1表示有 
}
void kill(){
	ll flag=0;
	for(ll i=0;i<n;i++){
		if(vis[i]==1||man[i].pos!=npos) continue;
		if(man[i].abi>nabi){
//			cout<<"so big"<<man[i].abi<<endl;
			flag=1;
			break;
		}
	}
	if(flag==1) return ;
	for(ll i=0;i<n;i++){
		if(vis[i]==1||man[i].pos!=npos) continue;
		if(man[i].abi<=nabi){
			if(nd+1>d){
				game=1;
				return ;
			}
			nabi+=man[i].abi;
			die++;
			nd++;
			vis[i]=1;
			cout<<"Get "<<man[i].abi<<" at "<<man[i].pos<<" on day "<<nd<<"."<<endl;
			break;
		}
	}
	
}
void solve(){
	floyd();
	vis[0]=1;
	npos=man[0].pos;
	nabi=man[0].abi;
	while(1){
		if(die==n){//最终赢家 
			cout<<"WIN on day "<<nd<<" with "<<nabi<<"!"<<endl;
			break;
		}
//		cout<<"NOW ABILITY"<<nabi<<endl;
		ll nex=find();
//		cout<<"NEX"<<nex<<endl;
		if(nex==-1){//ability都你大或者时间不够赶过去 
			cout<<"Lose on day "<<nd<<" with "<<nabi<<"."<<endl;
			break;
		}
		move(nex);//移动到下一个城市 
		if(game==1) break;
		join(nex);//同一个城市的弱者合并
		kill();//逐一击败 返回-1表示时间到了跳出循环
		
	}
//	cout<<"Lose on day "<<nd<<" with "<<nabi<<"."<<endl;
//	cout<<"Game over with "<<nabi<<"."<<endl;
	if(game==1){
		cout<<"Game over with "<<nabi<<"."<<endl;
	}
}
void show(){
	for(ll i=0;i<m;i++){
		for(ll j=0;j<m;j++){
			cout<<g[i][j]<<' ';
		}
		cout<<endl;
	}
}
int main()
{
	cin>>n>>m>>me>>d;
	nd=0;
	init();
	for(ll i=0;i<n;i++){
		ll pos,abi;
		cin>>man[i].pos>>man[i].abi;
	}
	for(ll i=1;i<=me;i++){
		ll u,v,val;
		cin>>u>>v>>val;
		path[u][v]=path[v][u]=1;
		g[u][v]=g[v][u]=val;
	}
	solve();
	return 0;
}

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值