HDU4972 A simple dynamic programming problem(规律)
来源:互联网 发布:手机定时开机软件 编辑:程序博客网 时间:2024/05/30 02:53
A simple dynamic programming problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1794 Accepted Submission(s): 506
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?
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.
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
222 341 3 5 7
Sample Output
Case #1: 2Case #2: 2
Author
BJTU
Source
2014 Multi-University Training Contest 10
这个题有几个坑点一直没跳出来,一个是没想到需要判断非法情况,另一个是题目说每一次投篮之后记录比分,而没说是每一次投进之后记录...所以一开始题意理解有问题
#include <iostream>#include <cstdio>#include <cmath>#include <cstring>#include <algorithm>#include <queue>using namespace std;typedef long long int ll;const int MAXN=100005;int a[MAXN];int n;int main(){ int t; scanf("%d",&t); for(int cas=1;cas<=t;cas++){ scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d",a+i); } int res=0; int cnt=0; int ok=1; for(int i=0;i<n-1;i++){ if((a[i]==1&&a[i+1]==2)||(a[i]==2&&a[i+1]==1)) res++; /*else if(a[i]==1&&a[i+1]==1) cnt++; */ if(a[i+1]-a[i]>3||a[i]-a[i+1]>3||(a[i]==a[i+1]&&a[i]!=1)){ ok=0; break; } } if(!ok){ printf("Case #%d: %d\n",cas,0); continue; } if(n==0){ printf("Case #%d: %d\n",cas,1); continue; } if(a[n-1]==0){ printf("Case #%d: %d\n",cas,res+1); } else{ printf("Case #%d: %d\n",cas,(res+1)*2); } } return 0;}
阅读全文
0 0
- HDU4972 A simple dynamic programming problem(规律)
- HDU4972 A simple dynamic programming problem(找规律)
- HDU4972:A simple dynamic programming problem
- hdu4972 A simple dynamic programming problem(多校第十场1002)
- HDU 4972 A simple dynamic programming problem(找规律)
- HDU 4972 A simple dynamic programming problem
- HDU 4972 A simple dynamic programming problem
- HDOJ 4972 A simple dynamic programming problem
- HDU-4972-A simple dynamic programming problem
- 【HDU】A simple dynamic programming problem
- hdu 4972 A simple dynamic programming problem 2014多校十
- 【杂题】 HDOJ 4972 A simple dynamic programming problem
- HDU 4972 A simple dynamic programming problem(推理)
- hdu 4972 A simple dynamic programming problem(高效)
- hdu - 4972 - A simple dynamic programming problem(数学 + dp)
- 14多校 B-A simple dynamic programming problem
- hdu 4947 A simple dynamic programming problem(2014 Multi-University Training Contest 10)
- HDU 4972 A simple dynamic programming problem(数学思维题)
- (1)linux环境变量初始化与对应文件的生效顺序
- Phonon MinGW 编译指南
- oracle-12514 or 12520 监听程序无法为请求的服务器类型找到可用的处理程序
- 学习笔记:SQL增删改查; SQL转储和导入;myeclipce导入文件;MyEclipse项目发布
- Volley 请求数据之数据不缓存
- HDU4972 A simple dynamic programming problem(规律)
- Qt4.7.4和tslib移植到开发板
- 再谈互斥锁与条件变量
- LNMP 一键按环境
- [置顶] Android 混淆代码总结
- UVA
- java笔记--springMessage处理自定义注解
- PS去除图片白色背景
- 数据库中varchar和char的区别