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. U3D 抛物线的方法

    本文转载:http://www.manew.com/thread-44642-1-1.html 无论是愤怒的小鸟,还是弓箭发射功能,亦或者模拟炮弹受重力影响等抛物线轨迹,都可以使用本文的方法,模拟绝对 ...

  2. 功能点分析法FPA笔记

    转载请注明出处:http://www.cnblogs.com/lidabnu/p/5700412.html 主要参考资料来自百度文库:http://wenku.baidu.com/link?url=y ...

  3. play app to war

    project/Build.scala import sbt._ import Keys._ import play.Play.autoImport._ import PlayKeys._ impor ...

  4. 视频处理简单实例 [OpenCV 笔记2]

    VideoCapture是OpenCV 2.X中新增的类,提供从摄像机或视频文件捕获视频的C++接口.利用它读入视频的方法一般有两种: // method 1 VideoCapture capture ...

  5. 开发错误日志之No matching bean of type [xxx] found for dependency

    No matching bean of type [org.springframework.data.mongodb.core.MongoTemplate] found for dependency ...

  6. preg_replace($pattern, $replacement, $content) 修饰符的奇葩作用

    $str = "<span>lin</span> == <span>3615</span>";$pattern = "/& ...

  7. sass学习--什么是sass

    1.预备知识--什么是 CSS 预处理器 CSS 预处理器定义了一种新的语言,其基本思想是,用一种专门的编程语言,为 CSS 增加了一些编程的特性,将 CSS 作为目标生成文件,然后开发者就只要使用这 ...

  8. mysql-积累管理sql语句

    //连接数据库 mysql -h xxx -u root -p; //查看数据库 show databases //查看数据表 show tables //查看某数据表结构 desc xxx表 //修 ...

  9. php中foreach()函数与Array数组经典案例讲解

    //php中foreach()函数与Array数组经典案例讲解 function getVal($v) { return $v; //可以加任意检查代码,列入要求$v必须是数字,或过滤非法字符串等.} ...

  10. LINQ小记

     //LINQ 根据长度查询出来            string[] strs = new string[] { "1", "22", "333& ...