• UVALive 7512 November 11th 题解


    思路:心态大崩,最多不讲了,最少应该是三个一组,比如......应该是.S..S.,这样占的最多

    代码:

    #include<set>
    #include<map>
    #include<cmath>
    #include<queue>
    #include<string>
    #include<cstdio>
    #include<cstring>
    #include<sstream>
    #include<algorithm>
    typedef long long ll;
    using namespace std;
    const int maxn = 1000 + 10;
    const int MOD = 1e9 + 7;
    const int INF = 0x3f3f3f3f;
    int row[maxn][maxn], cnt[maxn];
    int getMax(int s){
        return (s + 1) / 2;
    }
    int getMin(int s){
        if(s % 3 == 0){
            return s / 3;
        }
        else if(s % 3 == 1){
            return (s + 2) / 3;
        }
        else return (s + 1) / 3;
    }
    int main(){
        int t, ca = 1;
        scanf("%d", &t);
        while(t--){
            int b, r, s;
            scanf("%d%d", &r, &s);
            scanf("%d", &b);
            memset(cnt, 0 ,sizeof(cnt));
            for(int i = 1; i <= b; i++){
                int x, y;
                scanf("%d%d", &x, &y);
                row[x][cnt[x]++] = y;
            }
            int Max = 0, Min = 0;
            for(int i = 0; i < r; i++){
                if(cnt[i] == 0){
                    Max += getMax(s);
                    Min += getMin(s);
                }
                else{
                    sort(row[i], row[i] + cnt[i]);
                    for(int j = 0; j < cnt[i]; j++){
                        if(j == 0){
                            int tmp = row[i][j] - 0;
                            Max += getMax(tmp);
                            Min += getMin(tmp);
                        }
                        else{
                            int tmp = row[i][j] - row[i][j - 1] - 1;
                            Max += getMax(tmp);
                            Min += getMin(tmp);
                        }
                    }
                    int tmp = s - 1 - row[i][cnt[i] - 1];
                    Max += getMax(tmp);
                    Min += getMin(tmp);
                }
            }
            printf("Case #%d: %d %d
    ", ca++, Max, Min);
        }
        return 0;
    }
    /*
    3
    2 3
    1
    0 1
    2 3
    0
    1 1
    1
    0 0
    */
  • 相关阅读:
    C#中的Dictionary的使用
    关于加密和解密的方法
    单链表逆置
    稀疏矩阵存储
    数组内存地址
    堆和栈的区别
    vc++6.0快捷键
    springMvc-02
    SpringMvc-01
    数据库字段设置问题,具体问题具体分析
  • 原文地址:https://www.cnblogs.com/KirinSB/p/10325201.html
Copyright © 2020-2023  润新知