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-struts2 配置hellow world
这里进行struts框架的配置问题,和简单的输出hellow world 配置的步骤 1. 配置TomCat 2. Jak 3. 拷贝struts.xml文件到src目录 ...
- Java23种设计模式之单例模式
一.单例模式简介 单例模式是Java设计模式中常见的一种模式.主要分为懒汉式单例.饿汉式单例.登记式单例: 单例模式的特点: 1.单例类只能有一个实例: 2.单例类必须自己创建自己的唯一的实例: ...
- CSS 尺寸 (Dimension)
CSS 尺寸 (Dimension) 属性允许你控制元素的高度和宽度.同样,它允许你增加行间距. 更多实例 设置元素的高度 这个例子演示了如何设置不同元素的高度. 使用百分比设置图像的高度 这个例子演 ...
- 100. Same Tree(C++)
100. Same Tree Given two binary trees, write a function to check if they are equal or not. Two binar ...
- Eclipse中文乱码解决汇总(应该比较全):
Eclipse中文乱码解决汇总(应该比较全,欢迎补充): 方法一: 把GBK改成utf-8. 方法二: Window->preference->general->content ty ...
- javascript图片预先加载
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- Django 基础
Django 的路由系统 在 django 的 URLconf 配置文件 urls.py 中根据一个 URL 对应 views 的一个函数来处理用户的请求. 1.基本的 urls 对应 urlpatt ...
- Centos7 修改运行级别
systemd使用比sysvinit的运行级别更为自由的target概念作为替代 第三运行级: multi-user.target 第五运行级: graphical.target #前者是符号链接 ...
- QML之TextEdit
TextEdit显示一个可编辑的,有格式的文本框.它也可以显示明文和富文本.例如:TextEdit { width: 240 text: "<b>Hello</ ...
- max os 安装python模块PIL
下载libjpeg和zlib: http://www.ijg.org/files/jpegsrc.v9.tar.gz http://zlib.net/zlib-1.2.8.tar.gz 安装libjp ...