hdu 4972 A simple dynamic programming problem (转化 乱搞 思维题) 2014多校10

题目链接

题意:给定一个数组记录两队之间分差,只记分差,不记谁高谁低,问最终有多少种比分的可能性

分析:

类似cf的题目,比赛的时候都没想出来,简直笨到极点。。。。。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cstdlib>
 5 #include <cmath>
 6 #include <vector>
 7 #include <algorithm>
 8 #define LL __int64
 9 const int maxn = 100000+10;
10 using namespace std;
11 int a[maxn];
12
13 int main()
14 {
15     int i, t, n, ca = 1, ans, f;
16     scanf("%d", &t);
17     while(t--)
18     {
19         ans = 0; f = 0;
20         scanf("%d", &n);
21         for(i = 1; i <= n; i++)
22         {
23             scanf("%d", &a[i]);
24             if(i>=2)
25             {
26                if(a[i-1]==1 && a[i]==2)
27                ans ++;
28                if(a[i-1]==2 && a[i]==1)
29                ans ++;
30                if(a[i-1]==a[i] && a[i]!=1) //这两种都是不符合规则的
31                f = 1;
32                if(abs(a[i]-a[i-1])>3)
33                f = 1;
34             }
35         }
36         if(f)
37         printf("Case #%d: 0\n", ca++);  //不存在的情况
38         else if(a[n]==0)
39         printf("Case #%d: %d\n", ca++, ans+1);  //最后分差为0,结果少了一半
40         else
41         printf("Case #%d: %d\n", ca++, 2*ans+2);
42     }
43     return 0;
44 }

hdu 4972 A simple dynamic programming problem (转化 乱搞 思维题) 2014多校10,布布扣,bubuko.com

时间: 2024-08-02 02:48:42

hdu 4972 A simple dynamic programming problem (转化 乱搞 思维题) 2014多校10的相关文章

HDU 4972 A simple dynamic programming problem(推理)

HDU 4972 A simple dynamic programming problem 题目链接 推理,会发现只有前一个和当前一个分数为(1, 2)或(2, 1)的时候,会有两种加分方法,其他情况最多就一种情况,所以只要统计(1, 2),(2, 1)的个数,最后判断分差是否为0,如果不为0,那么可能是正或负,那就是两倍 代码: #include <cstdio> #include <cstring> const int N = 100005; int t, n, a[N]; i

hdu 4972 A simple dynamic programming problem(高效)

题目链接:hdu 4972 A simple dynamic programming problem 题目大意:两支球队进行篮球比赛,每进一次球后更新比分牌,比分牌的计数方法是记录两队比分差的绝对值,每次进球的分可能是1,2,3分.给定比赛中的计分情况,问说最后比分有多少种情况. 解题思路:分类讨论: 相邻计分为1-2或者2-1的时候,会对应有两种的的分情况 相邻计分之差大于3或者说相等并且不等于1的话,为非法输入 其他情况下,不会造成新的比分情况产生 对于最后一次比分差为0的情况,就没有谁赢谁

HDU 4972 A simple dynamic programming problem(数学思维题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4972 Problem Description Dragon is watching NBA. He loves James and Miami Heat. Here's an introduction of basketball game:http://en.wikipedia.org/wiki/Basketball. However the game in Dragon's version is

hdu - 4972 - A simple dynamic programming problem(数学 + dp)

题意:NBA比赛,双方共N次进球(N<=100000),无论哪方,进一个球(得分只可能为1,2,3),就记录一次(记两队分数差的绝对值),问最后两队的比分有多少种. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4972 -->>知道最后的比分差k,怎么求得比分呢?设分数较低的一方的最后分数为x,则另一方的最后分数为x + k,设双方最后总分和为S,则x  = (S - k) / 2,可得双方的比分..所以,只要知道最后双方的总分和,就可以

hdu 4972 A simple dynamic programming problem (每次记录两队得分差值求结果数)

因为是每次投篮后记录两队得分的差值,所以两个队伍的总分是不断增加的,可以发现只有差值由1-->2或者2-->1的情况才可能产生产生两种总分和的结果如 0:2可以变成2:3和1:2  其他的情况都只能是一种 郜大可的代码: 1 #include<stdio.h> 2 #include<string.h> 3 #include<iostream> 4 #include<algorithm> 5 using namespace std; 6 #defi

HDOJ 4972 A simple dynamic programming problem

找规律...数据可能不合法...输出0 A simple dynamic programming problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 85    Accepted Submission(s): 31 Problem Description Dragon is watching NBA. He loves Ja

【HDOJ】4972 A simple dynamic programming problem

水题. 1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 5 int abs(int x) { 6 return x<0 ? -x:x; 7 } 8 9 int main() { 10 int t, n; 11 int cur, past; 12 __int64 ans; 13 bool flag; 14 15 #ifndef ONLINE_JUDGE 16 freopen("

HDU-4972 A simple dynamic programming problem

http://acm.hdu.edu.cn/showproblem.php?pid=4972 ++和+1还是有区别的,不可大意. A simple dynamic programming problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 307    Accepted Submission(s): 117 Problem D

HDU4972:A simple dynamic programming problem

Problem Description Dragon is watching NBA. He loves James and Miami Heat. Here's an introduction of basketball game:http://en.wikipedia.org/wiki/Basketball. However the game in Dragon's version is much easier: "There's two teams fight for the winner