2022/4/22 天梯赛刷题记录&2018天梯赛

L1-8 语法+模拟
L2-1 图论
L2-2 bfs
L2-3 stl排序

L1-1 天梯赛座位分配

#include <bits/stdc++.h>
using namespace std;
#define endl '\n';
typedef long long ll;
typedef pair<int,double> PII;
const int N=1e5+10,mod=1e9+7;
int vis[105][105],a[105][105],n,m,maxn;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>m;
		maxn=max(maxn,m);
		for(int j=0;j<10*m;j++){
			vis[i][j]=1;
		}
	}
	int num=1,flag=-1;  
	for(int i=0;i<10*maxn;i++){
		for(int j=0;j<n;j++){
			if(vis[j][i]){  
				if(flag!=j){
					a[j][i]=num++;
					flag=j;
				}
				else{
					num+=1;
					a[j][i]=num++;
					flag=j;
				}
			}
		}
	}
	for(int i=0;i<n;i++){
		printf("#%d\n",i+1);
		for(int j=0;j<10*maxn;j++){
			if(a[i][j])printf("%d%c",a[i][j],(j+1)%10==0?'\n':' ');
		}
	}
	return 0;
}

L1-2 倒数第N个字符串

#include <bits/stdc++.h>
using namespace std;
#define endl '\n';
typedef long long ll;
typedef pair<int,double> PII;
const int N=1e5+10;
int l,n;
char a[10];
int main(){
    cin>>l>>n;
	ll ans=pow(26,l)-n;
	for(int i=l;i>=1;i--) a[i]=ans%26+'a',ans/=26;
	for(int i=1;i<=l;++i) cout<<a[i];
	return 0;
}

L1-3 打折

#include <bits/stdc++.h>
using namespace std;
#define endl '\n';
typedef long long ll;
typedef pair<int,double> PII;
const int N=1e5+10;
int n,k;
int main(){
    cin>>n>>k;
	printf("%.2lf",n*k*0.1);
	return 0;
}

L1-4 2018我们要赢

#include <bits/stdc++.h>
using namespace std;
#define endl '\n';
typedef long long ll;
typedef pair<int,double> PII;
const int N=1e5+10;

int main(){
	cout<<"2018"<<endl;
    cout<<"wo3 men2 yao4 ying2 !";
	return 0;
}

L1-5 电子汪

#include <bits/stdc++.h>
using namespace std;
#define endl '\n';
typedef long long ll;
typedef pair<int,double> PII;
const int N=1e5+10;
int n,m;
int main(){
	cin>>n>>m;
	for(int i=1;i<=n+m;++i) cout<<"Wang!";
	return 0;
}

L1-6 福到了

#include <bits/stdc++.h>
using namespace std;
#define endl '\n';
typedef long long ll;
typedef pair<int,double> PII;
const int N=1e5+10;
int n;
char a[101][101],b[101][101];
char c;
bool check(){
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(a[i][j]!=b[i][j]) return false;
		}
	}
	return true;
}
int main(){
	cin>>c>>n;
	getchar();
	for(int i=0;i<n;i++){
		string s;
		getline(cin,s);
		for(int j=0;j<n;j++){
			a[i][j]=s[j];
			b[n-i-1][n-j-1]=a[i][j];
		}
	}
	if(check()) cout<<"bu yong dao le"<<endl;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(b[i][j]=='@') cout<<c;
			else cout<<" ";
		}
		cout<<endl;
	}
	return 0;
}

L1-7 谁是赢家

#include <bits/stdc++.h>
using namespace std;
#define endl '\n';
typedef long long ll;
typedef pair<int,double> PII;
const int N=1e5+10;
int x,y,a1,a2,a3;
int main(){
	cin>>x>>y>>a1>>a2>>a3;
	int cnt1=0,cnt2=0;
	if(a1==0) cnt1+=1;
	else cnt2+=1;
	if(a2==0) cnt1+=1;
	else cnt2+=1;
	if(a3==0) cnt1+=1;
	else cnt2+=1;
	if((x>y&&cnt1)||cnt1==3) cout<<"The winner is a: "<<x<<" + "<<cnt1;
	else cout<<"The winner is b: "<<y<<" + "<<cnt2;
	return 0;
}

L1-8 猜数字

#include <bits/stdc++.h>
using namespace std;
#define endl '\n';
typedef long long ll;
typedef pair<int,double> PII;
const int N=1e5+10,mod=1e9+7;
int n,x;
map<string,int>mp;
string s;
int main(){
    cin>>n;
	int sum=0;
	for(int i=1;i<=n;i++){
		cin>>s>>x;
		sum+=x;
		mp[s]=x;
	}
	double ave=sum*1.0/n/2;
	string ans;
	double kk=1000;
	for(auto i:mp){
		if(abs(i.second-ave)<kk) kk=abs(i.second-ave),ans=i.first;
	}
	cout<<(int)ave<<" "<<ans<<endl;
	return 0;
}

L2-1 分而治之

#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define endl '\n';
typedef long long ll;
typedef pair<vector<int>,int> PII;
const int N=1e5+10,mod=1e9+7;
int n,a[N],m,q,k;
vector<int>e[N];
int main(){
	IOS;
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int u,v;cin>>u>>v;
		e[u].push_back(v);
		e[v].push_back(u);
	}
	cin>>q;
	while(q--){
		cin>>k;
		for(int i=1;i<=k;i++){
			int id;cin>>id;
			a[id]=1;
		}
		int f=1;
		for(int i=1;i<=n;i++){
			for(auto j:e[i]){
				if(!a[i]&&!a[j]){
					f=0;
					break;
				}
			}
			if(!f) {
				cout<<"NO"<<endl;
				break;
			}
		}
		if(f) cout<<"YES"<<endl;
		fill(a+1,a+1+n,0);
	}
	return 0;
}

L2-2 小字辈

#include <bits/stdc++.h>
using namespace std;
#define endl '\n';
typedef long long ll;
typedef pair<int,double> PII;
const int N=1e5+10;
int n,x,vis[N];
vector<int>e[N];
queue<int>q;
int main(){
	cin>>n;
	int pos=0,k=1;
	for(int i=1;i<=n;i++) {
		cin>>x;
		if(x==-1) pos=i;
		else e[x].push_back(i);
	}
	q.push(pos);
	vis[pos]=1;
	while(!q.empty()){
		x=q.front();
		q.pop();
		for(auto i:e[x]){
			vis[i]=vis[x]+1;
			k=max(k,vis[i]);
			q.push(i);
		}
	}
	cout<<k<<endl;
	int f=1;
	for(int i=1;i<=n;i++){
		if(vis[i]==k){
			if(f) cout<<i,f=0;
			else cout<<" "<<i;
		}
	}
	return 0;
}

L2-3 名人堂与代金券

#include <bits/stdc++.h>
using namespace std;
#define endl '\n';
typedef long long ll;
typedef pair<string,int> PII;
const int N=1e5+10;
string s;
int n,g,k,x;
vector<PII>ans;
bool cmp(PII i,PII j){
	if(i.second==j.second) return i.first<j.first;
	return i.second>j.second;
}
int main(){
	cin>>n>>g>>k;
	int sum=0;
	for(int i=1;i<=n;i++){
		cin>>s>>x;
		if(x>=60&&x<g) sum+=20;
		if(x>=g) sum+=50;
 		ans.push_back({s,x});
	}
	sort(ans.begin(),ans.end(),cmp);
	int tt=0;
	cout<<sum<<endl;
	while(tt<k){
		int cnt=0;
		for(int i=tt;i<=ans.size();i++){
			cnt++;
			cout<<tt+1<<" "<<ans[i].first<<" "<<ans[i].second<<endl;
			if(ans[i+1].second!=ans[i].second) break;
		}
		tt+=cnt;
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

懂又不懂啊

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值