• [Offer收割]编程练习赛40


    不到一个小时AK,虽然是VP的,舒服,第一次。都简单的一比,没什么可说的。

    查找三阶幻方

    #pragma comment(linker, "/STACK:102400000,102400000")
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include<vector>
    #include<algorithm>
    #include<iostream>
    #include<map>
    #include<queue>
    #include<stack>
    #include<string>
    #include<functional>
    #include<math.h>
    //#include<bits/stdc++.h>
    using namespace std;
    typedef long long lint;
    typedef vector<int> VI;
    typedef pair<int, int> PII;
    void makedata() {
        freopen("input.txt", "w", stdout);
        cout << 200000 << endl;
    
        for(int i = 0; i < 200000; i++) cout << 1000000000 << ' ';
    
        fclose(stdout);
    }
    
    int a[200][200];
    bool check(int x, int y) {
        int sum = a[x][y] + a[x][y + 1] + a[x][y + 2];
    
        for(int i = 0; i < 3; i++) {
            if(a[x + i][y] + a[x + i][y + 1] + a[x + i][y + 2] != sum) return false;
    
            if(a[x][y + i] + a[x + 1][y + i] + a[x + 2][y + i] != sum) return false;
    
            if(a[x][y] + a[x + 1][y + 1] + a[x + 2][y + 2] != sum) return false;
    
            if(a[x + 2][y] + a[x + 1][y + 1] + a[x][y + 2] != sum) return false;
        }
    
        return true;
    }
    int main() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
    #endif
        //makedata();
        std::ios::sync_with_stdio(0), cin.tie(0);
        int n, m;
        cin >> n >> m;
    
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                cin >> a[i][j];
            }
        }
    
        int ans = 0;
    
        for(int i = 0; i + 2 < n; i++) {
            for(int j = 0; j + 2 < m; j++) {
                if(check(i, j)) ans++;
            }
        }
    
        cout << ans << endl;
        return 0;
    }
    View Code

    双阶乘的末尾数字

    #pragma comment(linker, "/STACK:102400000,102400000")
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include<vector>
    #include<algorithm>
    #include<iostream>
    #include<map>
    #include<queue>
    #include<stack>
    #include<string>
    #include<functional>
    #include<math.h>
    //#include<bits/stdc++.h>
    using namespace std;
    typedef long long lint;
    typedef vector<int> VI;
    typedef pair<int, int> PII;
    void makedata() {
        freopen("input.txt", "w", stdout);
        cout << 200000 << endl;
    
        for(int i = 0; i < 200000; i++) cout << 1000000000 << ' ';
    
        fclose(stdout);
    }
    bool f[10];
    int main() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
    #endif
        //makedata();
        std::ios::sync_with_stdio(0), cin.tie(0);
        lint x;
        int t, k;
        cin >> t;
    
        while(t--) {
            cin >> x >> k;
            int st = 1, cnt = 0;
    
            while(st != k) {
                cnt++;
    
                if(st == 0 || cnt > 1000) {
                    x = -1;
                    break;
                }
    
                st = st * (x % 10) % 10;
                x -= 2;
    
                if(x <= 0) {
                    x = -1;
                    break;
                }
            }
    
            cout << x << endl;
        }
    
        return 0;
    }
    View Code

    01间隔方阵

    #pragma comment(linker, "/STACK:102400000,102400000")
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include<vector>
    #include<algorithm>
    #include<iostream>
    #include<map>
    #include<queue>
    #include<stack>
    #include<string>
    #include<functional>
    #include<math.h>
    //#include<bits/stdc++.h>
    using namespace std;
    typedef long long lint;
    typedef vector<int> VI;
    typedef pair<int, int> PII;
    void makedata() {
        freopen("input.txt", "w", stdout);
        cout << 200000 << endl;
    
        for(int i = 0; i < 200000; i++) cout << 1000000000 << ' ';
    
        fclose(stdout);
    }
    
    int f[1005][1005], fl[1005][1005], fu[1005][1005];
    char a[1005][1005];
    int main() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
    #endif
        //makedata();
        std::ios::sync_with_stdio(0), cin.tie(0);
        int n, m;
        cin >> n >> m;
    
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                cin >> a[i][j];
            }
        }
    
        memset(f, 0, sizeof(f));
        memset(fl, 0, sizeof(fl));
        memset(fu, 0, sizeof(fu));
    
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                if(j == 0) {
                    f[i][j] = 1;
                    fl[i][j] = 1;
                } else {
                    if(a[i][j] == a[i][j - 1]) fl[i][j] = 1;
                    else fl[i][j] = fl[i][j - 1] + 1;
                }
    
                if(i == 0) {
                    f[i][j] = 1;
                    fu[i][j] = 1;
                } else {
                    if(a[i][j] == a[i - 1][j]) fu[i][j] = 1;
                    else fu[i][j] = fu[i - 1][j] + 1;
                }
            }
        }
    
        int ans = 1;
    
        for(int i = 1; i < n; i++) {
            for(int j = 1; j < m; j++) {
                if(a[i][j] != a[i - 1][j - 1]) {
                    f[i][j] = 1;
                } else {
                    int tmp = 0x3FFFFFFF;
                    tmp = min(tmp, fl[i][j]);
                    tmp = min(tmp, fu[i][j]);
                    tmp = min(tmp, f[i - 1][j - 1] + 1);
                    f[i][j] = tmp;
    
                    if(ans < tmp) ans = tmp;
                }
            }
        }
    
        cout << ans << endl;
        return 0;
    }
    View Code

    方块游戏

    #pragma comment(linker, "/STACK:102400000,102400000")
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include<vector>
    #include<algorithm>
    #include<iostream>
    #include<map>
    #include<queue>
    #include<stack>
    #include<string>
    #include<functional>
    #include<math.h>
    //#include<bits/stdc++.h>
    using namespace std;
    typedef long long lint;
    typedef vector<int> VI;
    typedef pair<int, int> PII;
    void makedata() {
        freopen("input.txt", "w", stdout);
        cout << 200000 << endl;
    
        for(int i = 0; i < 200000; i++) cout << 1000000000 << ' ';
    
        fclose(stdout);
    }
    
    class SegmentTree {
    private:
        int *data, *lazy;
        void pushup(int rt) {
            data[rt] = max(data[rt << 1], data[rt << 1 | 1]);
        }
        void pushdown(int rt, int m) {
            if(lazy[rt] == 0) return;
    
            lazy[rt << 1] = lazy[rt];
            lazy[rt << 1 | 1] = lazy[rt];
            data[rt << 1] = lazy[rt];
            data[rt << 1 | 1] = lazy[rt];
            lazy[rt] = 0;
        }
    public:
        SegmentTree(int n) : data((int *)malloc((n << 3) * sizeof(int))), lazy((int *)malloc((n << 3) * sizeof(int))) {}
        void Build(int * base, int l, int r, int rt) {
            lazy[rt] = 0;
    
            if(l == r) data[rt] = base[l];
            else {
                int mid = (l + r) >> 1;
                Build(base, l, mid, rt << 1);
                Build(base, mid + 1, r, rt << 1 | 1);
                pushup(rt);
            }
        }
        void Modify(int l, int r, int rt, int L, int R, int v) {
            if(L <= l && R >= r) {
                lazy[rt] = v;
                data[rt] = v;
                return;
            }
    
            pushdown(rt, r - l + 1);
            int mid = (l + r) >> 1;
    
            if(L <= mid)
                Modify(l, mid, rt << 1, L, R, v);
    
            if(R > mid)
                Modify(mid + 1, r, rt << 1 | 1, L, R, v);
    
            pushup(rt);
        }
        int QueryPoint(int l, int r, int rt, int val) {
            if(l == r) return data[rt];
    
            pushdown(rt, r - l + 1);
            int mid = (l + r) >> 1;
            int ret = 0;
    
            if(val <= mid) ret = QueryPoint(l, mid, rt << 1, val);
            else ret = QueryPoint(mid + 1, r, rt << 1 | 1, val);
    
            pushup(rt);
            return ret;
        }
        int QuerySegment(int l, int r, int rt, int L, int R) {
            pushdown(rt, r - l + 1);
    
            if(L == l && R == r) return data[rt];
    
            int mid = (l + r) >> 1;
    
            if(R <= mid) return QuerySegment(l, mid, rt << 1, L, R);
    
            if(mid < L) return QuerySegment(mid + 1, r, rt << 1 | 1, L, R);
    
            return max(QuerySegment(l, mid, rt << 1, L, mid), QuerySegment(mid + 1, r, rt << 1 | 1, mid + 1, R));
        }
    };
    SegmentTree st(100005);
    int h[100005];
    
    int main() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
    #endif
        //makedata();
        std::ios::sync_with_stdio(0), cin.tie(0);
        memset(h, 0, sizeof(h));
        st.Build(h, 1, 100000, 1);
        int n, l, r;
        cin >> n;
    
        for(int i = 0; i < n; i++) {
            cin >> l >> r;
            int tmp = st.QuerySegment(1, 100000, 1, l, r);
            cout << (tmp + 1) << endl;
            st.Modify(1, 100000, 1, l, r, tmp + 1);
        }
    
        return 0;
    }
    View Code
  • 相关阅读:
    (转)上海驾照到期换证流程及注意事项
    sql 获取批处理信息的脚本(优化器在处理批处理时所发生的优化器事件)
    C# xml通过xslt转换为html输出
    C#基础 继承和实例化
    sqlserver 获取数据库、表和字段相关信息
    Json反序列化为动态类型(dynamic)
    Aspose.cells常用用法1
    C# 生成缩略图 去除图片旋转角度
    C# 压缩图片到指定宽度,假如图片小于指定宽度 判断图片大小是否大于指定大小(KB) 如果大于则压缩图片质量 宽高不变
    C# 2个List<T>比较内部项是否相等
  • 原文地址:https://www.cnblogs.com/dramstadt/p/8053355.html
Copyright © 2020-2023  润新知