zoukankan      html  css  js  c++  java
  • 蓝桥杯历届试题集合

    回文数字

    题目链接

      思路:DFS尝试每一位

    #include <bits/stdc++.h>
    using namespace std;
    const int maxn =  2e5 + 10;
    #define ll long long
    #define ios std::ios::sync_with_stdio(false)
    #define int long long
    typedef unsigned long long ULL;
    vector<int>ans;
    int a[10];
    void dfs(int step , int s)
    {
        if(step == 6 || step == 7)
        {
            if(s == 0){
                bool ok = true;
                if(a[1] == 0)ok = false;
                for(int i = 1 ; i <= step / 2 ; i ++){
                    if(a[i] != a[step - i]){
                        ok = false;
                        break;
                    }
                }
                if(ok){
                    int aa = 0;
                    for(int i = 1 ; i <= step - 1 ; i ++){
                        aa = aa * 10 + a[i];
                    }
                    ans.push_back(aa);
                }
            }
            if(step == 7)return ;
        }
        for(int i = 0 ; i <= 9 ; i ++){
            if(i > s)break;
            a[step] = i;
            dfs(step + 1 , s - i);
        }
    }
    
    
    
    signed main()
    {
        ios;
        cin.tie(0);///
        int n;
        cin >> n;
        dfs(1 , n);
        if(ans.size() == 0){
            cout << -1 << '
    ';
        }
        else{
            sort(ans.begin() , ans.end());
            for(int i = 0 ; i < ans.size() ; i ++){
                cout << ans[i] << '
    ';
            }
        }
        return 0;
    }
    View Code

    翻硬币

    题目链接

    #include <bits/stdc++.h>
    using namespace std;
    const int maxn =  2e5 + 10;
    #define ll long long
    #define ios std::ios::sync_with_stdio(false)
    #define int long long
    typedef unsigned long long ULL;
    #define debug(x) cout << #x << " : " << x << '
    ';
    
    vector<int>vec;
    char a[maxn] , b[maxn];
    signed main()
    {
        ios;
        cin.tie(0);///
        cin >> a + 1 >> b + 1;
        int n = strlen(a + 1);
        for(int i = 1 ; i <= n ; i ++){
            if(a[i] != b[i])vec.push_back(i);
        }
        int ans = 0;
        for(int i = 0 ; i < vec.size() ; i += 2){
            ans += vec[i + 1] - vec[i];
        }
        cout << ans << '
    ';
        return 0;
    }
    View Code

    连号区间数

    题目链接

    思路:

      看了一下觉得是个很难的题,没想到o(n2)可以过,大吃一斤...

      在一个区间内如果这个区间的最大值减去最小值等于区间长度,即满足条件。

    #include <bits/stdc++.h>
    using namespace std;
    const int maxn =  2e5 + 10;
    #define ll long long
    #define ios std::ios::sync_with_stdio(false)
    #define int long long
    typedef unsigned long long ULL;
    
    int a[maxn];
    signed main()
    {
        ios;
        cin.tie(0);///
        int n;
        cin >> n;
        for(int i = 1 ; i <= n ; i ++){
            cin >> a[i];
        }
        int ans = n;
        for(int i = 1 ; i <= n ; i ++){
            int maxx = a[i] , minn = a[i];
            for(int j = i + 1 ; j  <= n ; j ++){
                maxx = max(a[j] , maxx) , minn = min(minn , a[j]);
                if(maxx - minn == j - i) ans ++;
            }
        }
        cout << ans << '
    ';
        return 0;
    }
    View Code

     

    买不到的数目

    题目链接

    思路: 

      找规律找出来的

    #include <bits/stdc++.h>
    using namespace std;
    const int maxn =  2e5 + 10;
    #define ll long long
    #define ios std::ios::sync_with_stdio(false)
    #define int long long
    typedef unsigned long long ULL;
    signed main()
    {
        ios;
        cin.tie(0);///
        int a , b;
        cin >> a >> b;
        cout << a * b - a - b << '
    ';
        return 0;
    }
    View Code
  • 相关阅读:
    IOS-多线程技术
    设计模式-抽象工厂设计模式
    IOS-内存管理
    IOS-MVC的使用
    POJ2411 Mondriaan's Dream (广场铺砖问题 状压dp)
    NOIp2006T2 金明的预算方案
    POJ1179 Polygon(区间DP)
    NOIp2006T1能量项链
    美梦1(JSOI2014SC)
    TJOI2013(BZOJ3173)最长上升子序列
  • 原文地址:https://www.cnblogs.com/GoodVv/p/12623210.html
Copyright © 2011-2022 走看看