天梯集训笔记整理

1.着色问题

        直接标注哪些行和列是被标注过的,安全格子的数量就是未标注的行*列

#include <bits/stdc++.h>
using namespace std;

const int N = 1e5+10;
int hang[N],lie[N];

int main(){
    int n,m;
    cin>>n>>m;
    int q;
    cin>>q;
    while(q--){
        int x,y;
        cin>>x>>y;
        if(x==0){
            if(hang[y]==0){
                hang[y] = 1;
                n--;
            }
        }else{
            if(lie[y]==0){
                lie[y] = 1;
                m--;
            }
        }
    }
    cout<<m*n<<endl;
    return 0;
}

2.插松枝

        当涉及队列的相关操作的时候需要判断队列是否为空,否则会导致段错误。

deque<int>dq;    # 双端队列
dq.push_back(t); # 尾插
dq.pop_back();   # 尾元素出队
dp.pop_front();  # 头元素出队
dq.empty();      # 判断队列是否为空

3.老板的作息表

vector<pair<string, string>>vec # 存储题目的两个字符串
vec.push_back({a,b});           # 在容器尾部插入元素
sort(vec.begin(), vec.end());   # 升序排序,第一个元素相同时,按照第二个元素升序排序
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin>>n;
    vector<pair<string,string>>s;
    for(int i=1;i<=n;i++){
        string a,b,c;
        cin>>a>>b>>c;
        s.push_back({a,c});
    }
    sort(s.begin(), s.end());
    string re = "-1";
    for(auto t:s){
        if(re=="-1"){
            re = t.second;
            if(t.first!="00:00:00"){
                cout<<"00:00:00 - "<<t.first<<endl;
            }
        }else{
            if(re!=t.first){
                cout<<re<<" - "<<t.first<<endl;
            }
            re = t.second;
        }
    }
    if(re!="23:59:59"){
        cout<<re<<" - "<<"23:59:59";
    }
    return 0;
}

4.在主串s中查找字串t

string t = "123";
string s = "123321";
s.find(t, 0)!=string::npos; # !=说明找到字串了

5.从字符串数据流中读取整数

string s = "12 7";
istringstream iss(s);    # 将字符串转化为数据流
int L,T;
iss>>L>>T;               # 从数据流中读出整数 L=12 T=7

6.字符大小写转化

#include <bits/stdc++.h>
using namespace std;

int main(){
    char a = 'A';
    char c = a+32; // 'a'
    cout<<c<<endl;
    char b = 'z';
    char d = b-32;
    cout<<d<<endl; // 'Z'
}

7.记忆数字

#include <bits/stdc++.h>
using namespace std;

int main(){
    string s;
    getline(cin, s);
    int len = 0;
    for(char c:s){
        if(isalpha(c)){    # 是否是字符
            len++;
        }else if(len){
            cout<<len%10;
            len = 0;
        }
    }
    if(len){
        cout<<len%10;
    }
    return 0;
}

8.猜单词

#include <bits/stdc++.h>
using namespace std;

struct Node {
    string s;
    int a, b;
};

int main() {
    vector<Node> vec(5);
    for (auto &[s, a, b] : vec) {
        cin >> s >> a >> b;
    }

    auto check = [&](const string &t) {
        bool res = true;
        set<char> ss(t.begin(), t.end());    # 对t的每个字符插入到set中
        for (auto &[s, a, b] : vec) {
            int x = 0, y = 0;
            for (int i = 0; i < 3; i++) {
                x += ss.count(s[i]);
                y += s[i] == t[i];
            }
            res &= x == a && y == b;
        }
        return res;
    };

    vector<string> ans;
    for (char i = 'A'; i <= 'Z'; i++) {
        for (char j = 'A'; j <= 'Z'; j++) {
            for (char k = 'A'; k <= 'Z'; k++) {
                string t = {i, j, k};
                if (check(t)) {
                    ans.push_back(t);
                }
            }
        }
    }

    cout << ans.size() << '\n';
    for (auto &x : ans) {
        cout << x << '\n';
    }

    return 0;
}

9.寻宝图

               从每个位置进行搜索,找到以这个位置扩散出去的岛屿,则岛屿数量加1,并将遍历过的地方都置为已经遍历过,遍历过程中判断是否有宝藏

#include <bits/stdc++.h>
using namespace std;

const int N = 1e5+7;
vector<int>a[N];
vector<int>whe[N];
bool flag;
int n,m;
int dx[] = {-1,0,1,0};
int dy[] = {0,-1,0,1};

void dfs(int i,int j){
    whe[i][j] = 1;
    if(a[i][j]>1){
        flag = true;
    }
    for(int t=0;t<=3;t++){
        int xx = i+dx[t];
        int yy = j+dy[t];
        if(xx>=0&xx<n&&yy>=0&&yy<m){
            if(whe[xx][yy]==1||a[xx][yy]==0){
                continue;
            }else{
                dfs(xx,yy);
            }
        }
    }
}

int main(){
    cin>>n>>m;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            char c;
            cin>>c;
            a[i].push_back(c-'0');
            whe[i].push_back(0);
        }
    }
    int sum=0, count = 0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(whe[i][j]==0&&a[i][j]>0){
                sum++;
                flag = false;
                dfs(i,j);
                if(flag){
                    count++;
                }
            }
        }
    }
    cout<<sum<<" "<<count<<endl;
    return 0;
}

10.吉老师的回归

#include <bits/stdc++.h>
using namespace std;

int main(){
    int n,m;
    cin>>n>>m;
    cin.ignore();
    int flag = 0;
    m++;                    # m++是因为当做到最后一道题的时候是能AK的,若不+1会误判
    for(int i=1;i<=n;i++){
        string s;
        getline(cin, s);
        if(s.find("qiandao")!=string::npos||s.find("easy")!=string::npos){
            continue;
        }
        m--;
        if(m==0){
            flag = 1;
            cout<<s<<endl;
        }
    }
    if(flag==0){
        cout<<"Wo AK le"<<endl;
    }
    return 0;
}

11.乘法口诀表

        直接枚举从1到n,当项数多于n的时候break即可

#include <bits/stdc++.h>
using namespace std;

const int N = 1e4+7;
int a[N];

int main(){
    int a1,a2,n;
    cin>>a1>>a2>>n;
    a[1] = a1;
    a[2] = a2;
    int count = 2;
    for(int i=1;i<=n;i++){
        int re = a[i]*a[i+1];
        if(re<=9){
            count++;
            a[count] = re;
        }else{
            count++;
            a[count] = re/10;
            count++;
            a[count] = re%10;
        }
        if(count>=n){
            break;
        }
    }
    for(int i=1;i<=n;i++){
        cout<<a[i]<<(i==n?"":" ");
    }
    return 0;
}

12.深入虎穴

                深度搜索,需要注意的是,入口是入度为0的门

#include <bits/stdc++.h>
using namespace std;

const int N = 1e5+7;
int whe[N];         # 记录某个门是否被遍历过
int dis[N];         # 记录到每个门的距离
int du[N];          # 记录每个门的入度
vector<int>a[N];    # 记录每个门的邻接门

void dfs(int i){
    whe[i] = 1;
    for(int t=0;t<a[i].size();t++){
        if(whe[a[i][t]]==0){
            dis[a[i][t]] = dis[i]+1;
            dfs(a[i][t]);
        }else{
            continue;
        }
    }
}

int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        int k;
        cin>>k;
        for(int j=1;j<=k;j++){
            int x;
            cin>>x;
            du[x]++;
            a[i].push_back(x);
        }
    }
    for(int i=1;i<=n;i++){
        if(du[i]==0){
            dfs(i);
        }
    }
    int distance = -1;
    int index = -1;
    for(int i=1;i<=n;i++){
        if(dis[i]>distance){
            distance = dis[i];
            index = i;
        }
    }
    cout<<index<<endl;
    return 0;
}

13.倒数第N个字符

            26进制,其中n刚开始要--,因为最后一个字符算倒一字符

#include <bits/stdc++.h>
using namespace std;

int main(){
    int l,n;
    cin>>l>>n;
    string re = "";
    n--;
    for(int i=1;i<=l;i++){
        re += 'z';
    }
    for(int i=l-1;i>=0;i--){
        re[i] -= n%26;
        n /= 26;
    }
    cout<<re<<endl;
    return 0;
}

14.福到了

        对每一行的数据当作字符串来处理,先将每行reverse,再将总体reverse即可得到reverse 的结果,vector容器当作数组使用的时候要初始化

#include <bits/stdc++.h>
using namespace std;

int main(){
    char c;
    int n;
    cin>>c>>n;
    cin.ignore();
    vector<string>be(n+1),af(n+1);
    for(int i=1;i<=n;i++){
        string t;
        getline(cin, t);
        af[i] = t;
        be[i] = t;
        reverse(af[i].begin(), af[i].end());
    }
    reverse(af.begin()+1, af.end());
    if(af==be){
        cout<<"bu yong dao le"<<endl;
    }
    for(int i=1;i<=n;i++){
        for(int j=0;j<n;j++){
            if(af[i][j]!=' '){
                cout<<c;
            }else{
                cout<<' ';
            }
        }
        cout<<endl;
    }
    return 0;
}

15.天梯赛座位分配

        需要存储每个学校的队伍数量,以及当前每个学校已经有多少人已经入座,用二维数组re[i][j]来表示第i个学校第j个同学的座位。如何判断只剩一个学校没入座呢?就是上一个入座的人的编号就等于sit值。

#include <bits/stdc++.h>
using namespace std;

const int N = 1e3+7;
int a[N];     // 记录每个学校的队伍数量
int cnt[N];   // 记录每个学校的已经入座的同学数量
int re[N][N]; // 记录每个学校的入座的同学的坐位号

int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    int sit = 0;        // 记录座位号
    bool issit = false; // 记录是否还有同学入座
    do{
        issit = false;
        for(int i=1;i<=n;i++){
            if(a[i]*10==cnt[i]){
                continue;
            }
            if(sit&&re[i][cnt[i]]==sit){
                sit++;
            }
            issit = true;
            cnt[i]++;
            re[i][cnt[i]] = ++sit;
        }
    }while(issit);
    for(int i=1;i<=n;i++){
        cout<<"#"<<i<<endl;
        for(int j=1;j<=a[i]*10;j++){
            if(j%10==0){
                cout<<re[i][j];
                cout<<endl;
            }else{
                cout<<re[i][j]<<" ";
            }
        }
    }
    return 0;
}

16.整除光根

        原理不是很懂直接上代码

#include <bits/stdc++.h>
using namespace std;

int main(){
    int x;
    cin>>x;
    int n = 1;
    int count = 1;
    while(n<x){
        n = n*10+1;
        count++;
    }
    while(1){
        cout<<n/x;
        n%=x;
        if(n==0){
            break;
        }else{
            n = n*10+1;
            count++;
        }
    }
    cout<<" "<<count;
    return 0;
}

17.点赞狂魔

#include <bits/stdc++.h>
using namespace std;

struct person{
    string name;
    double cnt = 0;
    double avg = 0;
    bool operator<(const person &other) const {
        if(cnt!=other.cnt){
            return cnt > other.cnt;
        }
        return avg < other.avg;
    }
};

int main(){
    vector<person>vec;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        string s;
        cin>>s;
        double t;
        cin>>t;
        map<double ,double>mp;
        for(int j=1;j<=t;j++){
            double x;
            cin>>x;
            mp[x]++;
        }
        person p;
        p.name = s;
        p.cnt = mp.size();
        p.avg = t/mp.size();
        vec.push_back(p);
    }
    sort(vec.begin(), vec.end());
    for(int i=0;i<3;i++){
        if(i<vec.size()){
            cout<<vec[i].name;
        }else{
            cout<<"-";
        }
        if(i!=2){
            cout<<" ";
        }
    }
    return 0;
}

### 笔记本 CPU 性能天梯笔记本 CPU 的性能排名对于消费者选择合适的设备至关重要。最新的笔记本 CPU 天梯图已经更新至2024年11月版本[^1],该图表主要基于Cinebench R23测试成绩来评估各款处理器的表现。 值得注意的是,此榜单专注于笔记本专用的中央处理器,并未包含桌面级产品;如果需要更全面的数据,则可以查阅综合性的CPU天梯图资源[^2]。此外,由于市场上的新旧型号众多以及不同品牌的优化差异,实际应用中的表现可能会有所区别,因此建议关注具体应用场景下的评测报告作为补充参考资料[^3]。 根据当前数据,在高端领域内,Intel Core i9-13900HK 和 AMD Ryzen 9 7940HS 展现出相近的强大运算能力,特别适用于高负载任务如视频剪辑或复杂三维模型创建等工作场景。另一方面,苹果公司的 M2 Max 芯片组凭借其卓越的图形渲染效率和高效的多线程管理机制成为创意产业用户的理想之选[^4]。 尽管上述信息反映了现阶段市场上较为突出的产品特点,但随着技术进步速度加快和技术革新不断涌现,未来还会有更多优秀的作品问世。为了获得最准确的选择指导,推荐定期查看官方发布的最新版次天梯图并结合个人需求做出判断。 ```python # Python代码用于展示如何获取在线天梯图链接(假设存在API接口) import requests def get_cpu_ladder_link(): url = "https://example.com/api/cpu-ladder" response = requests.get(url) data = response.json() return data['link'] print(get_cpu_ladder_link()) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值