HDU 4972 Bisharp and Charizard 想法题

Bisharp and Charizard

Time Limit: 1 Sec  Memory Limit: 256 MB

 

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. The only way to gain scores is to throw the basketball into the basket. Each time after throwing into the basket, the score gained by the team is 1, 2 or 3. However due to the uncertain factors in the game, it’s hard to predict which team will get the next goal". 

Dragon is a crazy fan of Miami Heat so that after each throw, he will write down the difference between two team's score regardless of which team keeping ahead. For example, if Heat's score is 15 and the opposite team's score is 20, Dragon will write down 5. On the contrary, if Heat has 20 points and the opposite team has 15 points, Dragon will still write down 5. 

Several days after the game, Dragon finds out the paper with his record, but he forgets the result of the game. It's also fun to look though the differences without knowing who lead the game, for there are so many uncertain! Dragon loves uncertain, and he wants to know how many results could the game has gone? 

input

The first line of input contains only one integer T, the number of test cases. Following T blocks, each block describe one test case. 

For each test case, the first line contains only one integer N(N<=100000), which means the number of records on the paper. Then there comes a line with N integers (a 1, a 2, a 3, ... , a n). a i means the number of i-th record.
 

ouput

Each output should occupy one line. Each line should start with "Case #i: ", with i implying the case number. Then for each case just puts an integer, implying the number of result could the game has gone.
 
 

Sample Input

2 2 2 3 4 1 3 5 7

Sample Output

Case #1: 2 Case #2: 2

题意  

:篮球比赛有1、2、3分球  现给出两队的分差序列(5:3 分差2  3:5分差也是2)  问有多少种可能的比分

题解:

比较简单的想法题  可以类一张表“从分差x到分差y一共有几种情况”  很容易发现只有1->2和2->1的时候会多一种情况  其他均是一种  所以只需要统计这种特殊分差即可  注意一下最后结果要不要乘2  如果最后分差是0就不用因为x:x只有一种  但是最后分差不是0就要乘  因为x:y和y:x算两种  还有本题有坑!! 那个SB记分员会把分数记错  所以一旦记错种类数就为0了

代码:

 1 #include <cstdio>
 2 #include <cmath>
 3 #include <cstring>
 4 #include <ctime>
 5 #include <iostream>
 6 #include <algorithm>
 7 #include <set>
 8 #include <vector>
 9 #include <queue>
10 #include <typeinfo>
11 #include <map>
12 #include <stack>
13 typedef long long ll;
14 #define inf 0x7fffffff
15 using namespace std;
16 inline ll read()
17 {
18     ll x=0,f=1;
19     char ch=getchar();
20     while(ch<'0'||ch>'9')
21     {
22         if(ch=='-')f=-1;
23         ch=getchar();
24     }
25     while(ch>='0'&&ch<='9')
26     {
27         x=x*10+ch-'0';
28         ch=getchar();
29     }
30     return x*f;
31 }
32 //**************************************************************************************
33 
34 
35 int main()
36 {
37 
38     int T=read();
39     int oo=1;
40     while(T--)
41     {
42 
43         int n,a[100005];
44         scanf("%d",&n);
45         for(int i=1; i<=n; i++)
46         {
47             scanf("%d",&a[i]);
48         }
49         a[0]=0;
50         int flag=0;
51         int ans=1;
52         for(int i=1;i<=n;i++)
53             {
54                 if(abs(a[i]-a[i-1])>3||(a[i]!=1&&a[i]==a[i-1]))
55                 {
56                     flag=1;
57                     break;
58                 }
59                 if((a[i]==2&&a[i-1]==1)||(a[i]==1&&a[i-1]==2))ans++;
60             }
61             printf("Case #%d: ",oo++);
62             if(flag){
63                 printf("0
");
64             }
65             else {
66                 if(a[n]==0){
67                     printf("%d
",ans);
68                 }
69                 else printf("%d
",ans*2);
70             }
71     }
72     return 0;
73 }
原文地址:https://www.cnblogs.com/zxhl/p/4690233.html