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;
    }
  • 相关阅读:
    LeetCode
    LeetCode
    Django ORM 查询
    The Usage of Pymongo
    MongoDB基操
    Django内置auth模块中login_required装饰器用于类视图的优雅方式
    Django Session配置
    Python虚拟环境
    遇见Flask-Script
    Git使用手册
  • 原文地址:https://www.cnblogs.com/jerryRey/p/4690717.html
Copyright © 2011-2022 走看看