2019天梯赛总决赛L1-L2

L1-1 PTA使我精神焕发

没什么好讲的

print("PTA shi3 wo3 jing1 shen2 huan4 fa1 !")

L1-2 6翻了 (15 分)

这个题当时有点错误理解了题意

应该是小于等于9个6的时候输出9而不是小于

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#define ll long long
#define re return

using namespace std;

int main(){
	string s;
	// cin >> s;
	getline(cin, s);
	int l = s.size();
	for(int i = 0; i < l; i++){
		if(s[i] == '6'){
			int cnt = 1;
			int j = i + 1;
			for(; j < l; j++){
				if(s[j] == '6') cnt ++;
				else break;
			}
			i = j - 1;
			if(cnt <= 3){
				for(int j = 1; j <= cnt; j++){
					printf("6");
				}
			}
			else if(cnt <= 9)
				printf("9");
			else printf("27");
		}
		else{
			printf("%c",s[i]);
		}
	}
	re 0;
}

L1-3 敲笨钟 (20 分)

这题当时用python不知道为什么最后一个点没过,

附上python的代码:

n = int(input())
# s = input()

for i in range(n):
    s = input().split(',')
    t = 0
    flag = 0
    for j in s:
        for k in range(len(j) - 1, -1, -1):
            if j[k] == 'g':
                if j[k - 1] == 'n':
                    if j[k - 2] == 'o':
                        t += 1
                        flag = 1
            if flag == 1:
                flag = 0
                break
        if t == 2:
            break
    if t < 2:
        print("Skipped")
        continue
    else:
        print(s[0] + ', ', end='')
        x = s[1].split()
        for k in range(len(x) - 3):
            print(x[k],end=' ')
        print("qiao ben zhong.")


在这里插入图片描述

之后受到师哥启发,只需要看看’ong,'和’ong.'有没有出现过就行了,然后找到后面出现三个空格的地方

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <sstream>
#define ll long long
#define re return

using namespace std;

int T;

int main(){
   cin >> T;
   char c = getchar();
   while(T--){
   		string s;
   		// cin >> s;
   		getline(cin, s);
        // cout << s << endl;
        int f1 = s.find("ong,");
   		if(f1 == -1){
   			cout << "Skipped" << endl;
   			continue;
   		}
   		int f2 = s.find("ong.");
   		if(f2 == -1){
   			cout << "Skipped" << endl;
   			continue;
   		}
   		
   		int blank = 0;
   		int j;
        int l = s.size();
        for(j = l - 1; j >= 0 && blank < 3; j--){
			if(s[j] == ' ') blank++;
   		}
   		for(int i = 0; i <= j; i++){
   			printf("%c",s[i]);
   		}
   		cout << " qiao ben zhong." << endl;
   }
   return 0;
}

L1-4 心理阴影面积 (5 分)

就是一个高中解析几何的公式题(我学的不好早忘了

坐标系中点到直线距离公式:
∣ A x 0 + B y 0 + C ∣ A 2 + B 2 \dfrac{|Ax_0+By_0+C|}{\sqrt{A^2+B^2}} A2+B2 Ax0+By0+C
然后这个直线是y=x带入就能算出来

import  math

s = input().split()
x = int(s[0])
y = int(s[1])

# 点到直线距离

print(abs(x - y) * 50)

L1-5 新胖子公式

算bmi就行

s = input().split()
w = eval(s[0])
h = eval(s[1])

bmi = w / (h * h)
print("{:.1f}".format(bmi))
if bmi > 25:
    print("PANG")
else:
    print("Hai Xing")

L1-6 幸运彩票

直接模拟

n = int(input())
for _ in range(n):
    s = int(input())
    x = 0
    y = 0
    for i in range(3):
        x += s % 10
        s //= 10
    for i in range(3):
        y += s % 10
        s //= 10
    # print(x)
    # print(y)
    if x == y:
        print("You are lucky!")
    else:
        print("Wish you good luck.")

L1-7 吃鱼还是吃肉 (10 分)

直接模拟判断

n = int(input())
for _ in range(n):
    s = input().split()
    sex = int(s[0])
    h = int(s[1])
    w = int(s[2])
    if sex == 1:
        if h < 130:
            print("duo chi yu!" ,end=' ')
        elif h > 130:
            print("ni li hai!", end= ' ')
        else:
            print("wan mei!", end=' ')
        if w < 27:
            print("duo chi rou!", end='')
        elif w > 27:
            print("shao chi rou!", end='')
        else:
            print("wan mei!", end='')
    else:
        if h < 129:
            print("duo chi yu!", end=' ')
        elif h > 129:
            print("ni li hai!", end=' ')
        else:
            print("wan mei!", end=' ')
        if w < 25:
            print("duo chi rou!", end='')
        elif w > 25:
            print("shao chi rou!", end='')
        else:
            print("wan mei!", end='')
    print()

L1-8 估值一亿的AI核心代码 (20 分)

字符串大模拟(暂时未做

L2-1 特立独行的幸福 (25 分)

学习blog:https://blog.csdn.net/qq_40946921/article/details/88932652

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#define ll long long
#define re return

using namespace std;

int isPrime(int n){
    if(n == 1 || n == 0)
        return 1;
    if(n == 2)
        return 2;
    for (int i = 2; i <= sqrt(n); i++){
        if(n % i == 0)
            return 1;
    }
    return 2;
}

int apper[10000 + 10];

int main(){
    int a, b;
    cin >> a >> b;
    map<int, int> m;
    for (int i = a; i <= b; i++){
        int t = i;
        vector<int> v;
        while(t != 1){
            int summ = 0;
            while(t){
                summ += (t % 10) * (t % 10);
                t /= 10;
            }
            if(find(v.begin(), v.end(), summ) != v.end()){ //说明陷入了死循环
                break;
            }
            t = summ;
            v.push_back(summ);
            apper[t] = 1;
        }
        if(t == 1)
            m[i] = v.size();
    }
    int flag = 0;
    for (auto &it : m)
        if(!apper[it.first]){ //表示他没出现过,这个数不是其他数”走“过的和,即是独立的
            flag = 1;
            cout << it.first << " " << it.second * isPrime(it.first) << endl;
        }
    if(!flag)
        cout << "SAD" << endl;
    return 0;
}

L2-2 冰岛人 (25 分)

暂时未做

L2-3 深入虎穴 (25 分)

bfs遍历即可,然后存最后进去的是谁就是最远的

注意这题没给起点,然后根据题意,如果这个某个点没有出现过那他就是起点

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <queue>
#define ll long long

using namespace std;

int chu[100000 + 10];
// int d[100000 + 5][100000 + 5];
vector<vector<int>> d (100000 + 1);
queue<int> q;

int main(){
	
	int n;
	cin >> n;
	int start = 0;

	for(int i = 1; i <= n; i++){
		int k;
		cin >> k;
		for(int j = 1; j <= k; j++){
			int x;
			cin >> x;
			d[i].push_back(x);
			chu[x]++;
		}
	}
	
	for(int i = 1; i<= n; i++){
		if(!chu[i]){
			start = i;
			break;
		}
	}
	
	q.push(start);
	int zhong = 1;
	while(!q.empty()){
		int now = q.front();
		q.pop();
		int j = 1;
        int l = d[now].size();
		for (int i = 0; i < l; i++)
		{
			q.push(d[now][i]);
			zhong = d[now][i];
		}
		j++;
	}
	cout << zhong;
}

L2-4 彩虹瓶 (25 分)

模拟入站出站

#include <iostream>
#include <stack>

using namespace std;

int main(){
    int n, m, k;
    cin >> n >> m >> k;
    while(k--){
        stack<int> s;
        int now = 1;
        int t = 1;
        int a[1000 + 10] = {0};
        for (int i = 1; i <= n; i++){
            cin >> a[i];
        }
        for (int i = 1; i <= n; i++)
        {
            if (a[i] == now)
            {
                now++;
                while(!s.empty() && s.top() == now){
                    now++;
                    s.pop();
                }
            }
            else{
                s.push(a[i]);
                if(s.size() > m){
                    t = 0;
                    break;
                }
            }
            
        }
        if(t && s.empty()){ 
        //如果不判断是不是为空的话,就想给的的样例中3、1、5、4、2、6、7 
        //3、1、5、4、2、6、7,放上1 2就拿不到3号箱了,因为这个样例能正好放满货架而不会break
            cout << "YES" << endl;
        }
        else
            cout << "NO" << endl;
    }
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值