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
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?
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.
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.
#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的更多相关文章
- hdu 4972 A simple dynamic programming problem(高效)
pid=4972" target="_blank" style="">题目链接:hdu 4972 A simple dynamic progra ...
- 2014多校第十场1002 || HDU 4972 A simple dynamic programming problem
题目链接 题意 : 每次无论哪个队投进一个篮球,就记下现在两队比分的差值,问你最后的结果有多少种情况. 思路 : 该题实在是不好理解,最后的结果有多少种情况就是说不管中间过程怎么来的,只要最后结果不一 ...
- hdu 4972 A simple dynamic programming problem (转化 乱搞 思维题) 2014多校10
题目链接 题意:给定一个数组记录两队之间分差,只记分差,不记谁高谁低,问最终有多少种比分的可能性 分析: 类似cf的题目,比赛的时候都没想出来,简直笨到极点..... 最后的差确定,只需要计算和的种类 ...
- 【HDOJ】4972 A simple dynamic programming problem
水题. #include <cstdio> #include <cstring> #include <cstdlib> int abs(int x) { ? -x: ...
- HDU 4975 A simple Gaussian elimination problem.
A simple Gaussian elimination problem. Time Limit: 1000ms Memory Limit: 65536KB This problem will be ...
- HDU 4971 A simple brute force problem.
A simple brute force problem. Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged o ...
- hdu 4975 A simple Gaussian elimination problem.(网络流,推断矩阵是否存在)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4975 Problem Description Dragon is studying math. One ...
- hdu - 4975 - A simple Gaussian elimination problem.(最大流量)
意甲冠军:要在N好M行和列以及列的数字矩阵和,每个元件的尺寸不超过9,询问是否有这样的矩阵,是独一无二的N(1 ≤ N ≤ 500) , M(1 ≤ M ≤ 500). 主题链接:http://acm ...
- hdu 4975 A simple Gaussian elimination problem 最大流+找环
原题链接 http://acm.hdu.edu.cn/showproblem.php?pid=4975 这是一道很裸的最大流,将每个点(i,j)看作是从Ri向Cj的一条容量为9的边,从源点除法连接每个 ...
随机推荐
- java 子类重写父类的方法应注意的问题
若想实现一个合格重写方法,而不是重载,那么必须同时满足下面的要求! A.重写规则之一: 重写方法不能比被重写方法限制有更严格的访问级别.(但是可以更广泛,比如父类方法是包访问权限,子类的重写方法 ...
- window.event对象详细介绍
1.event代表事件的状态,例如触发event对象的元素.鼠标的位置及状态.按下的键等等.event对象只在事件发生的过程中才有效.event的某些属性只对特定的事件有意义.比如,fromEleme ...
- HTTP状态吗汇录
页面Http状态查询工具说明 建议直接Ctrl+F来查找状态码 如果向您的服务器发出了某项请求要求显示您网站上的某个网页,那么,您的服务器会返回 HTTP 状态代码以响应该请求. 如果向您的服务器发出 ...
- UITabBar的隐藏
方式一: // 重写导航控制器的push方法 - (void)pushViewController:(UIViewController *)viewController animated:(BOOL) ...
- 2014-11-9------- 设有一数据库,包括四个表:学生表(Student)、课程表(Course)、成绩表(Score)以及教师信息表(Teacher)。
一. 设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表(一)~表( ...
- C++primer(第五版)读书笔记&习题解答---CHAPTER 3
C++标准库类型包括:string,vector和迭代器,其中string是可变长的字符序列,vector存放的是某种给定类型对象的可变长序列,迭代器是string和vector的配套类型,常被用于访 ...
- 不错的轮播插件flexslider
http://flexslider.woothemes.com/ $('.flexslider').flexslider({ animation:'slide', //滑动效果:翻页效果,默认为fad ...
- phpcms安装完成后总是跳转到install/install.php
很多人在本地安装phpcms后总是跳转到install/install.php.由于很多人是第一次使用phpcms,不知道为何会出现这个错误.出现这个大都是phpcms的缓存所致. 如何解决ph ...
- 【算法】快速排序-Java版
说在前面的话 平常码砖的时候,对于一个数组进行排序更多的是起泡排序,起泡排序对于一般不是很长的数组进行操作没什么问题,一旦数组过大,很明显效率低. 而快排是对起泡排序的一种改进,效率明显优高. 快排思 ...
- ART模式和Dalvik模式的异同
Dalvik模式 如果要解释清楚什么是ART模式,我们就需要从Android系统的应用编译模式说起,我们都知道Android系统是以Linux系统为底层构建的,Android系统是开源(源代码公开)的 ...