• AHU 6th 校赛总结帖


    A.随便搞,我偷懒用了一个map。手贱给again加一个感叹号还WA了一发,o(╯□╰)o

    #include <cstdio>
    #include <map>
     
    using namespace std;
     
    map<int,int> mp;
     
    int main() {
        int n;  scanf("%d",&n);
        int mm,ss,v;
        scanf("%d:%d",&mm,&ss);
        v = mm * 60 + ss;
        for(int i = 1;i <= n;i++) {
            scanf("%d:%d",&mm,&ss);
            int tmp = mm * 60 + ss;
            if(mp[tmp] == 0) mp[tmp] = i;
        }
        if(mp[v] == 0) puts("Try Again");
        else printf("%d
    ",mp[v]);
        return 0;
    }

    B.n的范围只有200,模拟即可

    #include <cstdio>
    #include <map>
    #include <cstring>
    #include <algorithm>
    #include <cstdlib>
     
    using namespace std;
     
    int a[205],maxv,maxi;
     
    void findmax(int n) {
        maxv = -1;
        for(int i = 2;i <= n;i++) {
            if(a[i] > maxv) {
                maxv = a[i];
                maxi = i;
            }
        }
    }
     
    int main() {
        int n; scanf("%d",&n);
        int ans = 0;
        for(int i = 1;i <= n;i++) scanf("%d",&a[i]);
        findmax(n);
        while(maxv >= a[1]) {
            a[maxi]--; a[1]++;
            findmax(n);
            ans++;
        }
        if(ans == 0) printf("Oldbear, The best!
    ");
        else printf("%d
    ",ans);
        //system("pause");
        return 0;
    }

    C.Wzy说有规律可找,窝没发现(╯□╰)老老实实写了一个暴力

    首先,只要确定a[1]和b[1]遍可以确定矩阵c了,确定a[1]就可以确定b[1] 了,所以只要枚举a[1]就好了

    但是这里的数据范围有10^9,但是仔细观察可以发现,因为全是xor运算,a[1]可以一位一位的来确定,每一位只要枚举0和1就行了。

    所以我们只要从高位到低位枚举a[1]的每一位,然后算出b,a中所有元素的对应位的值,就可以直接推出c

    比赛的时候写的匆忙比较挫=。=

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
     
    using namespace std;
     
    const int maxn = 1030;
    int a[maxn],b[maxn],c[maxn][maxn];
        int t,n,m;
     
    inline int getbit(int v,int b) {
        if(v & (1 << b)) return 1;
        else return 0;
    }
     
    inline void setbit(int &s,int v,int b) {
        if(v) s |= (1 << b);
        else s &= ~(1 << b);
    }
     
    bool ok(int ss,int v1,int v2) {
        //printf("%d
    ",ss);
        setbit(a[1],v1,ss);
        setbit(b[1],v2,ss);
        for(int i = 2;i <= n;i++) {
            int bitc = getbit(c[i][1],ss);
            setbit(a[i],(bitc ^ v2),ss);
        }
     
        for(int i = 2;i <= m;i++) {
            int bitc = getbit(c[1][i],ss);
            setbit(b[i],bitc ^ v1,ss);
        }
     
        for(int i = 1;i <= n;i++) {
            for(int j = 1;j <= m;j++) {
                int bitc = getbit(c[i][j],ss);
                int bita = getbit(a[i],ss);
                int bitb = getbit(b[j],ss);
                if(bitc != (bita ^ bitb)) return false;
            }
        }
        return true;
    }
     
    bool allok() {
        for(int i = 1;i <= n;i++) {
            for(int j = 1;j <= m;j++) {
                //printf("%d %d %d %d
    ",c[i][j],a[i],b[j],a[i] ^ b[j]);
                if(c[i][j] != (a[i] ^ b[j])) return false;
            }
        }
        return true;
    }
     
    int main() {
        scanf("%d",&t);
        while(t--) {
            scanf("%d%d",&n,&m);
            for(int i = 1;i <= n;i++) {
                for(int j = 1;j <= m;j++) {
                    scanf("%d",&c[i][j]);
                }
            }
            int ss;
            for(int ss = 30;ss >= 0;ss--) {
                if(getbit(c[1][1],ss) == 0) {
                    if(ok(ss,0,0) || ok(ss,1,1)) continue;
                } else {
                    if(ok(ss,0,1) || ok(ss,1,0)) continue;
                }
            }
            if(allok()) {
                for(int i = 1;i <= n;i++) {
                    printf("%d",a[i]);
                    if(i == n) putchar('
    ');
                    else putchar(' ');
                }
                for(int i = 1;i <= m;i++) {
                    printf("%d",b[i]);
                    if(i == m) putchar('
    ');
                    else putchar(' ');
                }
            } else {
                puts("I bet Tyrion made a mistake.");
            }
        }
        return 0;
    }

    D.动态规划,f[i]表示以i结尾的时候最大的价值。

    f[i] =  f[j] + 1 >>> str[i] !=str[j]

        f[j - 1] + sq(cc) >> str[i] == str[j] cc表示i到j之间str[j]的数量,相当于把这些相同的str[j]直接的元素全部去掉

        j from i - 1 to 1

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
     
     
    using namespace std;
     
    const int maxn = 600;
    char str[maxn];
    int f[maxn];
     
    inline int sq(int x) {
        return x * x;
    }
     
    int main() {
        int T; scanf("%d",&T);
        while(T--) {
            int ans = 1;
            scanf("%s",str + 1);
            int len = strlen(str + 1);
            memset(f,0,sizeof(f));
            f[1] = 1;
            for(int i = 2;i <= len;i++) {
                int maxv = 1;
                int cc = 1;
                for(int j = i - 1;j >= 1;j--) {
                    if(str[i] != str[j]) {
                        maxv = max(maxv,f[j] + 1);
                    } else {
                        cc++;
                        maxv = max(maxv,f[j - 1] + sq(cc));
                    }
                }
                f[i] = maxv;
                ans = max(ans,f[i]);
            }
            printf("%d
    ",ans);
        }
        return 0;
    }

    E. 其实不是很难,就是利用前缀和和模运算有分配率来搞,比赛的时候没想到,最后安大的节操没有保住也有我的一部分责任o(╯□╰)o

    设Si为序列前i项的和有sum(i,j) = Sj - Si-1

    sum(i,j) % n = 0 >>> (Sj-Si-1)%n = 0 >> Sj % n == Si-1 %n

    就是先扫一遍求S数组,然后扫一遍取摸,然后找L最小的两个相等值的位置啦=。=

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
     
    using namespace std;
     
    const int maxn = 100005;
    int pos[maxn],a[maxn],sum[maxn];
     
    int main() {
        int n; scanf("%d",&n);
        memset(pos,-1,sizeof(pos));
        int ansl = 2100000000,ansr,minlen = 2100000000;
        for(int i = 1;i <= n;i++) {
            scanf("%d",&a[i]);
            sum[i] = sum[i - 1] + a[i];
        }
        for(int i = 0;i <= n;i++) {
            sum[i] %= n;
            if(pos[sum[i]] == -1) {
                pos[sum[i]] = i;
            } else {
                if(pos[sum[i]] + 1 < ansl) {
                    ansl = pos[sum[i]] + 1;
                    ansr = i;
                }
            }
        }
        printf("%d %d
    ",ansl,ansr);
        return 0;
    }

    F.其实我不会做,目测Bo哥时限手一抖多打了一个0让我7s水过

    完全暴力乱搞o(╯□╰)o

    #include <cstdio>
    #include <cstring>
    #include <map>
    #include <string>
    #include <iostream>
    #include <vector>
    #include <algorithm>
     
    using namespace std;
    
    vector<string> dict;
    vector<string> od;
    int cc[100005];
     
    int main() {
        ios::sync_with_stdio(false);
        int n; cin >> n;
        for(int i = 1;i <= n;i++) {
            string tmp;
            cin >> tmp;
            dict.push_back(tmp);
            od.push_back(tmp);
        }
        sort(dict.begin(),dict.end());
        for(int i = 0;i < od.size();i++) {
            int k = lower_bound(dict.begin(),dict.end(),od[i]) - dict.begin();
            int pos = k,maxv = cc[k],len = od[i].size(),maxi = k;
            while(pos < dict.size() && strncmp(od[i].c_str(),dict[pos].c_str(),len) == 0) {
                if(cc[pos] > maxv) {
                    maxv = cc[pos]; maxi = pos;
                }
                pos++;
            }
            if(maxv == 0) {
                cout << od[i] << endl;
            } else cout << dict[maxi] << endl;
            cc[k]++;
        }
        //system("pause");
        return 0;
    }

    G.状态压缩动态规划,状态为当前的序列a,因为相同的数字没有意义,所以只要保留一个,因为有性质MAX{a1, a2, a3, ..., an}(表示取a1~an中值最大的一个)与LCM{a1, a2, a3, ..., an}(表示能被a1~an整除的最小正整数)相等,所以项数不会太多,我粗略的算了一下最多只有18。然后直接爆搜加记忆化就好。(这题赛后最后能搞定要多谢爱酱的指导╮(╯▽╰)╭,我一开始状态想错,后来又各种细节处理不好,编码能力和DP还是弱啊=。=)

    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <algorithm>
     
    #define WIN 1
    #define LOSE 0
     
    using namespace std;
     
    const int maxn = 205;
    int a[maxn];
     
    //生成因数表
    int factor[maxn],fcount;
    void factor_maker(int n) {
        fcount = 0;
        for(int i = 2;i <= n;i++) {
            if(n % i == 0) factor[fcount++] = i;
        }
    }
     
    inline void setbit(int &n,int v,int b) {
        if(v) n |= (1 << b);
        else n &= ~(1 << b);
    }
     
    inline int getbit(int n,int b) {
        if(n & (1 << b)) return 1;
        else return 0;
    }
     
    inline int query(int n) {
        for(int i = 0;i < fcount;i++) if(factor[i] == n) return i;
    }
     
    int note[1 << 21];
     
    int dfs(int state) {    //当前取的情况是state的时候先手是否可以赢
        int ret = WIN;
        if(~note[state]) return note[state];
        if(state == 0) return LOSE;
        for(int i = 0;i < fcount;i++) {
            int nstate = state;
            for(int j = 0;j < fcount;j++) {
                if(getbit(state,j) && factor[j] % factor[i] == 0) {
                    setbit(nstate,0,j);
                    if(factor[j] != factor[i]) {
                        setbit(nstate,1,query(factor[j] / factor[i]));
                    } 
                }
            }
            if(nstate != state) {
                ret = dfs(nstate);
                if(ret == LOSE) break;
            }
        }
        return (note[state] = (!ret));
    }
     
    int main() {
        memset(note,-1,sizeof(note));
        int maxv = 0,n;
        scanf("%d",&n);
        for(int i = 1;i <= n;i++) {
            scanf("%d",&a[i]);
            maxv = max(maxv,a[i]);
        }
        factor_maker(maxv);
        int ori = 0;
        for(int i = 1;i <= n;i++) {
            setbit(ori,1,query(a[i]));
        }
        int ret = dfs(ori);
        if(ret == WIN) puts("Poor Tyrion.");
        else puts("The Lannister always pays his debts.");
        return 0;
    }

    H.水题,直接来或者打表随便搞

    #include <cstdio>
    #include <map>
    #include <cstring>
    #include <algorithm>
    #include <cstdlib>
     
    using namespace std;
     
    int val[300] = {
        1,3,7,13,19,27,39,49,63,79,87,91,103,109,123,133,139,147,169,181,183,187,207,219
    ,223,229,241,253,259,279,289,301,303,307,313,331,349,361,363,373,387,391,399,403
    ,423,439,447,459,463,469,481,499,507,511,523,529,543,553,567,571,583,589,601,613
    ,627,639,643,649,667,673,679,687,709,723,727,733,739,751,759,763,783,799,807,811
    ,819,841,843,853,859,867,889,901,903,907,927,931,943,949,963,973,979,
    };
     
    int main() {
        int n,t;
        scanf("%d",&t);
        while(t--) {
            scanf("%d",&n); printf("%d
    ",val[n - 1]);
        }
        //system("pause");
        return 0;
    }
  • 相关阅读:
    PHP NG (PHP 5.7) 性能比 PHP 5.6 提升近 1 倍
    PHP移动互联网开发笔记(3)——运算符
    利用PHP生成二维码
    几款常用的PHP模板引擎
    PHP多线程的使用
    关于程序员失眠的解决方案
    PHP移动互联网开发笔记(5)——文件的上传下载
    PHP生成二维码【谷歌API+qrcode+圆角Logo】
    7种流行PHP集成开发工具(IDE)的比较
    封装
  • 原文地址:https://www.cnblogs.com/rolight/p/3619901.html
Copyright © 2020-2023  润新知