hdu 4947 A simple dynamic programming problem(2014 Multi-University Training Contest 10)
来源:互联网 发布:php面试让现场写代码 编辑:程序博客网 时间:2024/05/17 04:56
A simple dynamic programming problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 316 Accepted Submission(s): 120
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 ofresult could the game has gone.
Sample Input
222 341 3 5 7
Sample Output
Case #1: 2Case #2: 2
解题思路:
相邻差值大于3,或者相邻的相同且不为1,只有2->1或者1->2能使比分发生变化。
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn=100000+100;int a[maxn];int main(){ long long ans=0; int t; scanf("%d",&t); for(int i=1;i<=t;i++) { int n; ans=0; scanf("%d",&n); for(int j=1;j<=n;j++) scanf("%d",&a[j]); int sign=0; for(int j=2;j<=n;j++) { if(a[j]==1&&a[j-1]==2) { ans++; } else if(a[j]==2&&a[j-1]==1) { ans++; } else if((a[j]-a[j-1]>3||a[j-1]-a[j]>3)||(a[j]==a[j-1]&&a[j]!=1)) { ans=0; sign=1; break; } } if(sign) { printf("Case #%d: ",i); printf("%I64d\n",ans); continue; } if(a[n]) { printf("Case #%d: ",i); printf("%I64d\n",ans*2+2); } else { printf("Case #%d: ",i); printf("%I64d\n",ans+1); } } return 0;}
0 0
- hdu 4947 A simple dynamic programming problem(2014 Multi-University Training Contest 10)
- hdu 4973 A simple simulation problem.(2014 Multi-University Training Contest 10)
- hdu 4973 A simple simulation problem 线段树 2014 Multi-University Training Contest 10-1003
- hdu 4973 A simple simulation problem 2014 Multi-University Training Contest 10
- 2015 Multi-University Training Contest 5 - MZL's simple problem
- HDU 5349 MZL's simple problem (2015 Multi-University Training Contest 5 2015多校联合)
- HDU--5349--2015 Multi-University Training Contest 5--MZL's simple problem
- hdu 5349 MZL's simple problem 2015 Multi-University Training Contest 5
- hdu 5858 Hard problem(2016 Multi-University Training Contest 10——数学题)
- hdu 5867 Water problem(2016 Multi-University Training Contest 10——水题)
- 2016 多校 Multi-University Training Contest 6 A Simple Chess
- 【2016 Multi-University Training Contest 6】【1002】【A Simple Chess】
- HDU 5795 A Simple Nim(SG打表找规律)——2016 Multi-University Training Contest 6
- (HDU 5795)2016 Multi-University Training Contest 6 A Simple Nim (SG函数、博弈)
- (HDU 5794)2016 Multi-University Training Contest 6 A Simple Chess (Lucas、容斥)
- hdu 5795 A Simple Nim(2016 Multi-University Training Contest 6——博弈)
- hdu 4911 Inversion ( 2014 Multi-University Training Contest 5)
- hdu 5328 Problem Killer 2015 Multi-University Training Contest 4
- 51Talk-Level 7 Unit 4 L4
- 酷狗音乐API
- EaselJs 测试小结
- 成都青羊考场科目二考试分享
- android 发送短信和接受短信模块
- hdu 4947 A simple dynamic programming problem(2014 Multi-University Training Contest 10)
- hdu 4970 Killing Monster
- UIView、Layer、Animation
- 二分图的最大匹配————匈牙利算法(hungary)基础详解。
- 国际化与本地化(i18n)支持函数库(多语言)
- net spy memcached 使用demo
- 机房收费系统(1)之结账
- Redis客户端之Jedis
- 网络报文转发逻辑