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 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 (a1, a2, a3, ... ,
an). ai means the number of i-th record.

 
Output
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
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
int abs(int x)
{
if(x>)
return x;
else
return -x;
}
int main()
{
int i,t,n,a[],ans,k=;
scanf("%d",&t);
while(t--)
{
memset(a,,sizeof(a));
ans=;
scanf("%d",&n);
for(i=;i<n;i++)
scanf("%d",&a[i]);
int cnt=;
int flag=;
for(i=;i<n&&(i+)<n;i++)
{
if(((a[i+]==a[i])&&a[i]!=)||abs(a[i+]-a[i])>)
{
flag=;
break;
}
if((a[i]==&&a[i+]==)||(a[i]==&&a[i+]==))
cnt++;
} if(flag==)
{
printf("Case #%d: %d\n",k++,ans);
continue;
}
if(a[n-]==)
ans=cnt+;
else
ans=*cnt+;
printf("Case #%d: %d\n",k++,ans);
}
return ;
}

HDU-4972 A simple dynamic programming problem的更多相关文章

  1. hdu 4972 A simple dynamic programming problem(高效)

    pid=4972" target="_blank" style="">题目链接:hdu 4972 A simple dynamic progra ...

  2. 2014多校第十场1002 || HDU 4972 A simple dynamic programming problem

    题目链接 题意 : 每次无论哪个队投进一个篮球,就记下现在两队比分的差值,问你最后的结果有多少种情况. 思路 : 该题实在是不好理解,最后的结果有多少种情况就是说不管中间过程怎么来的,只要最后结果不一 ...

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

    题目链接 题意:给定一个数组记录两队之间分差,只记分差,不记谁高谁低,问最终有多少种比分的可能性 分析: 类似cf的题目,比赛的时候都没想出来,简直笨到极点..... 最后的差确定,只需要计算和的种类 ...

  4. 【HDOJ】4972 A simple dynamic programming problem

    水题. #include <cstdio> #include <cstring> #include <cstdlib> int abs(int x) { ? -x: ...

  5. HDU 4975 A simple Gaussian elimination problem.

    A simple Gaussian elimination problem. Time Limit: 1000ms Memory Limit: 65536KB This problem will be ...

  6. HDU 4971 A simple brute force problem.

    A simple brute force problem. Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged o ...

  7. hdu 4975 A simple Gaussian elimination problem.(网络流,推断矩阵是否存在)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4975 Problem Description Dragon is studying math. One ...

  8. hdu - 4975 - A simple Gaussian elimination problem.(最大流量)

    意甲冠军:要在N好M行和列以及列的数字矩阵和,每个元件的尺寸不超过9,询问是否有这样的矩阵,是独一无二的N(1 ≤ N ≤ 500) , M(1 ≤ M ≤ 500). 主题链接:http://acm ...

  9. hdu 4975 A simple Gaussian elimination problem 最大流+找环

    原题链接 http://acm.hdu.edu.cn/showproblem.php?pid=4975 这是一道很裸的最大流,将每个点(i,j)看作是从Ri向Cj的一条容量为9的边,从源点除法连接每个 ...

随机推荐

  1. PHP制作简单的日历

    在这里分享一个PHP制作的日历 <?php //万年历if($_GET['year']){$year = $_GET['year'];}else{$year = date("Y&quo ...

  2. 文件夹IsShow字段为空

    IsShow为YesNo字段,默认值为Yes:在Library中新建一个文件的时候会给出默认值yes,但是新建一个文件夹的时候,默认为空,所以f.Item["IsShow"]为空, ...

  3. 概述ASP.NET缓存机制

    PetShop之ASP.NET缓存机制 如果对微型计算机硬件系统有足够的了解,那么我们对于Cache这个名词一定是耳熟能详的.在CPU以及主板的芯片中,都引入了这种名为高速缓冲存储器(Cache)的技 ...

  4. 评论一下现有几个开源IM框架(Msn/QQ/Fetion/Gtalk...)

    转载:http://www.cnblogs.com/zc22/archive/2010/05/30/1747300.html 前言 ---------------- 这阵子,在集成通讯框架, 由于不想 ...

  5. .NET下的加密解密大全(2):对称加密

    本博文列出了.NET下常用的对称加密算法,并将它们制作成小DEMO,希望能对大家有所帮助. 公共代码[csharp]static byte[] CreateKey(int num) {     byt ...

  6. xp和win 2003远程桌面强制进入命令

    xp和win 2003远程桌面强制进入命令 注意:端口号也可以不写 如果是在win 2003里面进行踢人的话可以用命令: mstsc /console /v:172.25.100.27:3389 如果 ...

  7. CocoaPods详解之----进阶篇

    作者:wangzz原文地址:http://blog.csdn.net/wzzvictory/article/details/19178709转载请注明出处如果觉得文章对你有所帮助,请通过留言或关注微信 ...

  8. HDU 1074 Doing Homework (dp+状态压缩)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1074 题目大意:学生要完成各科作业, 给出各科老师给出交作业的期限和学生完成该科所需时间, 如果逾期一 ...

  9. 读书笔记之 - javascript 设计模式 - 责任链模式

    责任链模式可以用来消除请求的发送者和接收者之间的耦合.这是通过实现一个由隐式地对请求进行处理的对象组成的链而做到的.链中的每个对象可以处理请求,也可以将其传给下一个对象. 责任链的结构: 责任链由多个 ...

  10. v880 debug

    zte v880手机,ubuntu中配置真机调试, 1.开启手机调试模式2.增加/etc/udev/rules.d/51-android.rules. 内容如下:SUBSYSTEM=="us ...