2022/4/21 天梯赛刷题记录&2019天梯赛

L1 语法+模拟
L2-1 stl
L2-2 stl
L2-3 bfs

L1-8 模拟太恶心没写
比赛和期末考撞个满怀太累了,计组要寄了(悲…
在这里插入图片描述

L1-1 PTA使我精神焕发

#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 main() {
    cout<<"PTA shi3 wo3 jing1 shen2 huan4 fa1 !";
	return 0;
}

L1-2 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,mod=1e9+7;
string s;
int main() {
    getline(cin,s);
    int k=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='6') k++;
        else {
            if(k<=3) {
                for(int j=1;j<=k;j++) cout<<"6";
            }else if(k>3&&k<=9){
                cout<<"9";
            }else {
                cout<<"27";
            }
            k=0;
            cout<<s[i];
        }
    }
    if(k){
        if(k<=3) {
            for(int j=1;j<=k;j++) cout<<"6";
        }else if(k>3&&k<=9){
            cout<<"9";
        }else {
            cout<<"27";
        }
    }
	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,mod=1e9+7;
int n;
string s;
int main() {
    cin>>n;
    getchar();
    for(int i=1;i<=n;i++){
        getline(cin,s);
        int f1=0,f2=0,k=0;
        for(int j=0;j<s.size();j++){
            if(s[j]==' '&&f2!=1) k++;
            if(s[j]=='o'&&s[j+1]=='n'&&s[j+2]=='g'&&s[j+3]==',') f1=1;
            if(s[j]=='o'&&s[j+1]=='n'&&s[j+2]=='g'&&s[j+3]=='.') f2=1;
        }
        if(f1==1&&f2==1){
            k-=2;
            int cnt=0;
            while(k){
                cout<<s[cnt];
                if(s[cnt]==' ') k--;
                cnt++;
            }
            cout<<"qiao ben zhong.";
        }  else{
            cout<<"Skipped";
        }
        cout<<endl;
    }
	return 0;
}

L1-4 心理阴影面积

#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 x,y;
int main() {
    cin>>x>>y;
    cout<<100*100/2-x*y/2-(y+100)*(100-x)/2;
	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,mod=1e9+7;
double w,h;
int main() {
    cin>>w>>h;
    double ans=w/(h*h);
    printf("%.1lf\n",ans);
    if(ans>25) {
        printf("PANG");
    }else{
        printf("Hai Xing\n");
    }
	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,mod=1e9+7;
int n;
string x;
int main() {
    cin>>n;
    while(n--){
        cin>>x;
        int ans1=x[0]-'0'+x[1]-'0'+x[2]-'0';
        int ans2=x[3]-'0'+x[4]-'0'+x[5]-'0';
        if(ans1==ans2) {
            cout<<"You are lucky!"<<endl;
        }else{
            cout<<"Wish you good luck."<<endl;
        }
    } 
	return 0;
}

L1-7 吃鱼还是吃肉

#include <bits/stdc++.h>
using namespace std;
#define endl '\n';
typedef long long ll;
typedef pair<int,int> PII;
const int N=1e5+10,mod=1e9+7;
void solve(){
    int id,h,w;
    cin>>id>>h>>w;
    if(id==1){
        if(h<130) cout<<"duo chi yu! ";
        if(h==130) cout<<"wan mei! ";
        if(h>130)cout<<"ni li hai! ";
        if(w<27) cout<<"duo chi rou!";
        if(w==27) cout<<"wan mei!";
        if(w>27) cout<<"shao chi rou!";
    }else{
        if(h<129) cout<<"duo chi yu! ";
        if(h==129 ) cout<<"wan mei! ";
        if(h>129) cout<<"ni li hai! ";
        if(w<25) cout<<"duo chi rou!";
        if(w==25) cout<<"wan mei!";
        if(w>25) cout<<"shao chi rou!";
    }
    cout<<endl;
}
int main(){
    int t;cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

L2-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 a,b,vis[N]; 
vector<int>q;
map<int,int>mp;    
int is_prime(int x){
    if(x==1) return 1;
    if(x==2||x==3) return 2;
    for(int i=2;i<=x/i;i++){
        if(x%i==0) return 1;
    }
    return 2;
}                                         
int main() {
    cin>>a>>b;
    for(int i=a;i<=b;i++){
        int k=i;
        while(k!=1){
            int sum=0;
            while(k){
                sum+=(k%10)*(k%10);
                k/=10;
            }
            k=sum;
            if(find(q.begin(),q.end(),sum)!=q.end()) break;
            q.push_back(sum);
            vis[sum]=1;
        }
        if(k==1) mp[i]=q.size();
        q.clear();
    }
    if(!mp.size()){
        cout<<"SAD"<<endl;
        return 0;
    }
    for(auto i:mp){
        if(!vis[i.first]){
            cout<<i.first<<" "<<is_prime(i.first)*i.second<<endl;
        }
    }
	return 0;
}

L2-2 冰岛人

#include <bits/stdc++.h>
using namespace std;
#define endl '\n';
typedef long long ll;
typedef pair<int,string> PII;
int N, M;
string fName, sName, temp;
map<string, PII> mp;
string check(string a, string b) {
	int cnt1 = 0, cnt2;
	while (a != "") {
		cnt2 = 0;
		string b2 = b;
		while (b2 != "") {
			if (a == b2 && (cnt1 < 4 || cnt2 < 4)) return "No\n";
			if (cnt1 >= 4 && cnt2 >= 4) return "Yes\n";
			b2 = mp[b2].second;
			cnt2++;
		}
		a = mp[a].second;
		cnt1++;
	}
	return "Yes\n";
}
int main() {
	cin >> N;
	while(N--){
		cin >> fName >> sName;
		if (sName.back() == 'n') mp[fName] = {1, sName.substr(0, sName.length() - 4)};
		else if (sName.back() == 'r') mp[fName] = {0, sName.substr(0, sName.length() - 7)};
		else if (sName.back() == 'm') mp[fName].first = 1;
		else mp[fName].first = 0;
	}
	cin >> M;
	while(M--){
		cin >> fName >> temp >> sName >> temp;
		if (!mp.count(fName) || !mp.count(sName)) cout << "NA\n";
		else if(mp[fName].first == mp[sName].first) cout << "Whatever\n";
		else cout << check(fName, sName);
	}
	return 0;
}

L2-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,mod=1e9+7;
int n,k,x,vis[N];
vector<int>e[N];                                       
int main() {
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>k;
        for(int j=1;j<=k;j++){
            cin>>x;
            e[i].push_back(x);
            e[x].push_back(i);
        }
    }
    queue<int>q;
    q.push(1);
    vis[1]=1;
    while(!q.empty()){
        x=q.front();
        q.pop();
        for(auto i:e[x]){
            if(vis[i]) continue;
            vis[i]=1;
            q.push(i);
        }
    }
    cout<<x<<endl;
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

学不会数据库

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

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

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

打赏作者

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

抵扣说明:

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

余额充值