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的边,从源点除法连接每个 ...
随机推荐
- css修改li前面的小圆点的颜色
直接改 li 的style 的 color 就好:就是这样:over
- javascript创建对象(一)
对象定义:无序属性的集合,属性包含基本值.对象.函数,相当于一组没有特定顺序的值. 创建自定义对象最简单的方式就是: var movie=new Object(); movie.name=&qu ...
- oracle学习笔记3:基本的SQL语句
oracle基本的SQL语句和SQLSERVER基本一样,在这里只简单列出与SQLSERVER不一样的地方 1.select * from orderinfo where address = 'abc ...
- CSS 导航栏
实例: 导航栏 Home News Articles Forum Contact About 导航栏 熟练使用导航栏,对于任何网站都非常重要. 使用CSS你可以转换成好看的导航栏而不是枯燥的HTML菜 ...
- JS异步阻塞的迷思
还是百度前端技术学院的“任务十九”可视化排序算法的题,在写出快速排序算法之后,要求用动画的形式把这个排序过程呈现出来.排序过程在CPU里不过是瞬间的事,但要转换成“缓慢的”动画效果给人类看,就不得不把 ...
- 系统后台图表生成文档说明-javascript
1.引入jquery插件文件datas.js 2.各图表分类 表格 $('#'+tableId).mTable({ url:'', //数据来源,[必填] pageNum:1, //分页,默认为1,[ ...
- python【第十三篇】可以写一个堡垒机了
前景介绍 到目前为止,很多公司对堡垒机依然不太感冒,其实是没有充分认识到堡垒机在IT管理中的重要作用的,很多人觉得,堡垒机就是跳板机,其实这个认识是不全面的,跳板功能只是堡垒机所具备的功能属性中的其中 ...
- HIVE:用外连接替代子查询
由于hive也支持sql,很多人会把hql跟标准sql进行比较,甚至有的时候会直接套用.hive不支持事务也不支持索引,更不支持追加写,但是对于一般的sql都是能够支持的.但是对于一些子查询确实无法支 ...
- JS面向对象思想(OOP)
直接看js好了,模拟创建一个奥运会 function 奥运会Class(主题) { // 删除主题 // delete this.主题; this.主题 = 主题; this.开幕时间; this.闭 ...
- getInputStream与getReader方法
getInputStream 方法用于返回的一个代表实体内容的输入流对象,其类型为javax.servlet.ServletInputStream. getReader方法用于返回的一个代表实体内容的 ...