zoukankan      html  css  js  c++  java
  • Codeforces Round #351(Div 2)

    熬到半夜打结果前一个小时提交代码的页面根本加载不进去,D题写完还因为小点没判被hack掉了。。。
    rating什么的都是身外之物了,于是乎喜闻乐见地又掉回绿名了。

    A题:

    *题目描述:
    Bear看一场90分钟的比赛,有n个有趣的事件的时间点,Bear如果连续15分钟没有看到有趣的事件,那么它就会关掉电视,问Bear最多可以看多长时间的电视?
    *题解:
    模拟,记得判最后一个点到90分钟的距离。
    *代码:

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    
    #ifdef WIN32
        #define LL "%I64d"
    #else
        #define LL "%lld"
    #endif
    
    #ifdef CT
        #define debug(...) printf(__VA_ARGS__)
        #define setfile() 
    #else
        #define debug(...)
        #define filename ""
        #define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout);
    #endif
    
    #define R register
    #define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 15, stdin), S == T) ? EOF : *S++)
    #define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
    #define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
    #define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
    #define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
    char B[1 << 15], *S = B, *T = B;
    inline int FastIn()
    {
        R char ch; R int cnt = 0; R bool minus = 0;
        while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
        ch == '-' ? minus = 1 : cnt = ch - '0';
        while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
        return minus ? -cnt : cnt;
    }
    
    int main()
    {
    //  setfile();
        R int n = FastIn(), last = 0;
        for (R int i = 1; i <= n; ++i)
        {
            R int t = FastIn();
            if (t - last > 15) return !printf("%d
    ",last + 15 );
            last = t;
        }
        if (90 - last > 15) return !printf("%d
    ",last + 15 );
        puts("90");
        return 0;
    }

    B题:

    *题目描述:
    有n个题目和m种关系,每种关系表示两个题目是相似的。求所有的二分图的数量,同时要保证其中一个集合的点的编号都大于另一个集合的点的编号。
    *题解:
    我的第一反应是图论的题,但是想得非常复杂,然而zzx一眼秒题,把问题转化成区间上的问题。
    *代码:

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    
    #ifdef WIN32
        #define LL "%I64d"
    #else
        #define LL "%lld"
    #endif
    
    #ifdef CT
        #define debug(...) printf(__VA_ARGS__)
        #define setfile() 
    #else
        #define debug(...)
        #define filename ""
        #define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout);
    #endif
    
    #define R register
    #define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 15, stdin), S == T) ? EOF : *S++)
    #define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
    #define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
    #define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
    #define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
    char B[1 << 15], *S = B, *T = B;
    inline int FastIn()
    {
        R char ch; R int cnt = 0; R bool minus = 0;
        while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
        ch == '-' ? minus = 1 : cnt = ch - '0';
        while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
        return minus ? -cnt : cnt;
    }
    
    int main()
    {
    //  setfile();
        R int n = FastIn(), m = FastIn();
        R int left = 1, right = n;
        for (R int i = 1; i <= m; ++i)
        {
            R int l = FastIn(), r = FastIn();
            cmax(left, dmin(l, r));
            cmin(right, dmax(l, r));
        }
        printf("%d
    ",dmax(right - left, 0) );
        return 0;
    }

    C题:

    *题目描述:
    有n个数,每个数代表一种颜色,颜色的范围在1~n之间。问每种颜色在多少个区间内是众数(如果有多个众数则取较小的那个)。
    *题解:
    直接暴力搞,枚举左端点,每次把出现的数计到一个数组里面,然后用一个变量维护出现次数的最大值。
    *代码:

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    
    #ifdef WIN32
        #define LL "%I64d"
    #else
        #define LL "%lld"
    #endif
    
    #ifdef CT
        #define debug(...) printf(__VA_ARGS__)
        #define setfile() 
    #else
        #define debug(...)
        #define filename ""
        #define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout);
    #endif
    
    #define R register
    #define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 15, stdin), S == T) ? EOF : *S++)
    #define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
    #define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
    #define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
    #define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
    char B[1 << 15], *S = B, *T = B;
    inline int FastIn()
    {
        R char ch; R int cnt = 0; R bool minus = 0;
        while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
        ch == '-' ? minus = 1 : cnt = ch - '0';
        while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
        return minus ? -cnt : cnt;
    }
    
    int main()
    {
    //  setfile();
        R int n = FastIn();
        for (R int i = 1; i <= n; ++i)
            t[i] = FastIn();
        for (R int i = 1; i <= n; ++i)
        {
            R int maxx = 0, node;
            for (R int j = 1; j <= n; ++j) cnt[j] = 0;
            for (R int j = i; j <= n; ++j)
            {
                ++cnt[t[j]];
                maxx < cnt[t[j]] || (maxx == cnt[t[j]] && t[j] < node) ? maxx = cnt[t[j]], node = t[j] : 0;
                ans[node]++;
            }
        }
        for (R int i = 1; i <= n; ++i) printf("%d ",ans[i] );
        return 0;
    }

    D题:

    *题目描述:
    请你构造一幅图,这幅图满足:节点数为n,边数小于等于m,同时,存在一条路径,可以从a经过所有的节点仅一次到达b,也可以从c经过所有的节点仅一次然后到达d。
    *题解:
    数学构造题。除了a,b,c,d的点先构一条链,然后链的一头连a,c,另一头连b,d,然后再把a和c,b和d连起来(这里建议画一副图来理解)。于是边就变成了n+1条,否则就不成立。(我sb了没有判n=4的情况,即都是无解,结果过了pretest完立马被人x掉,直至比赛结束一直没有调出来)
    *代码:

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    
    #ifdef WIN32
        #define LL "%I64d"
    #else
        #define LL "%lld"
    #endif
    
    #ifdef CT
        #define debug(...) printf(__VA_ARGS__)
        #define setfile() 
    #else
        #define debug(...)
        #define filename ""
        #define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout);
    #endif
    
    #define R register
    #define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 15, stdin), S == T) ? EOF : *S++)
    #define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
    #define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
    #define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
    #define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
    char B[1 << 15], *S = B, *T = B;
    inline int FastIn()
    {
        R char ch; R int cnt = 0; R bool minus = 0;
        while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
        ch == '-' ? minus = 1 : cnt = ch - '0';
        while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
        return minus ? -cnt : cnt;
    }
    
    int main()
    {
    //  setfile();
        R int n = FastIn(), m = FastIn();
        R int a = FastIn(), b = FastIn(), c = FastIn(), d = FastIn();
        if (m < n + 1 || n == 4)
        {
            puts("-1");
            return 0;
        }
        printf("%d ",a );
        printf("%d ",c );
        for (R int i = 1; i <= n; ++i) if (i != a && i != b && i != c && i != d) printf("%d ",i );
        printf("%d ",d );
        printf("%d
    ",b );
    
        printf("%d ",c );
        printf("%d ",a );
        for (R int i = 1; i <= n; ++i) if (i != a && i != b && i != c && i != d) printf("%d ",i );
        printf("%d ",b );
        printf("%d
    ",d );
        return 0;
    }
  • 相关阅读:
    Vue+element UI实现“回到顶部”按钮组件
    JS判断字符串长度的5个方法(区分中文和英文)
    从vue源码看Vue.set()和this.$set()
    mac下git安装与使用
    JS数组reduce()方法详解及高级技巧
    vue中router.go、router.push和router.replace的区别
    上传及更新代码到github(以及如何在vscode上提交自己的代码)
    VSCode打开多个项目文件夹的解决方法
    get请求和post请求的区别
    android 进程的优先级
  • 原文地址:https://www.cnblogs.com/cocottt/p/5550963.html
Copyright © 2011-2022 走看看