zoukankan      html  css  js  c++  java
  • HDU-4972-A simple dynamic programming problem

    坑坑的题目,我只想说:题意不清楚也就算了。。包含不合法数据也就算了。。篮球还有平局也算是很diao了。。。

    吐槽结束。

    题解:不难发现当之前比分为2,当前比分为1,有两种情况,得分低的一组得3分反超,或者得1分。因为只关心最后的结果,每轮都是独立的,所以答案是加一。。。之前比分是1,当前比分是2类似。

    然后注意判一下非法情况,如果最后平局的话是没有输赢之分的,否则乘2。

     

    #include<cstdio>
    #include<algorithm>
    using namespace std;
    
    int main()
    {
        int T;
        scanf("%d",&T);
        for(int cas = 1; cas <= T; cas++){
            int N;
            scanf("%d",&N);
            int ans = 1;
            int pre;
            scanf("%d",&pre);
            bool impossible = false;
            if(pre>3||pre<=0) impossible = true;
            int j = 1;
            if(!impossible){
                 for(; j < N; j++){
                    int cur;
                    scanf("%d",&cur);
                    int del = abs(cur - pre);
                    if(del > 3) { impossible = true; j++ ;break; }
                    else if(del == 0 && cur != 1) { impossible = true; j++ ;break; }
                    if((cur == 1&& pre == 2)||(pre == 1&&cur == 2)) ans++;
                    pre = cur;
                }
            }
            for(; j < N; j++) { int dummy; scanf("%d",&dummy); }
            if(pre) ans <<= 1;
            printf("Case #%d: %d
    ",cas,impossible?0:ans);
        }
        return 0;
    }
  • 相关阅读:
    kubectl 命令详解
    codeforce344 C report
    poj3041 建图+最小顶点覆盖(最大匹配数)
    poj1637 混合欧拉回路的判定
    poj1149 最大流好题 难在建图 好题
    targan 算法模板
    poj2186 强连通分量 targan算法的应用
    poj2723 2分 + 2-sat
    poj3061 尺取法
    poj3207 2-sat基础题
  • 原文地址:https://www.cnblogs.com/jerryRey/p/4690717.html
Copyright © 2011-2022 走看看