一道ACM题,为什么WA了,求解释啊
时间:2011-07-25
来源:互联网
http://acm.hdu.edu.cn/showproblem.php?pid=1087
Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now.
The game can be played by two or more than two players. It consists of a chessboard(棋盘)and some chessmen(棋子), and all chessmen are marked by a positive integer or “start” or “end”. The player starts from start-point and must jumps into end-point finally. In the course of jumping, the player will visit the chessmen in the path, but everyone must jumps from one chessman to another absolutely bigger (you can assume start-point is a minimum and end-point is a maximum.). And all players cannot go backwards. One jumping can go from a chessman to next, also can go across many chessmen, and even you can straightly get to end-point from start-point. Of course you get zero point in this situation. A player is a winner if and only if he can get a bigger score according to his jumping solution. Note that your score comes from the sum of value on the chessmen in you jumping path.
Your task is to output the maximum value according to the given chessmen list.
Input
Input contains multiple test cases. Each test case is described in a line as follow:
N value_1 value_2 …value_N
It is guarantied that N is not more than 1000 and all value_i are in the range of 32-int.
A test case starting with 0 terminates the input and this test case is not to be processed.
Output
For each case, print the maximum according to rules, and one line one case.
Sample Input
3 1 3 2
4 1 2 3 4
4 3 3 2 1
0
Sample Output
4
10
3
#include <iostream>
using namespace std;
typedef struct
{
long int max;
long int t;
}node;
int main()
{
long int n,i;
while(cin >> n&&n)
{
node a[1010];
a[0].max =0;
a[0].t=0;
for(i=1;i<=n;i++)
{
cin >> a[i].t;
if(a[i].t > a[i-1].t)
{
a[i].max = a[i].t+a[i-1].max;
}
else if(a[i].t < a[i-1].t)
{
a[i].max = a[i].t;
}
else if(a[i].t = a[i-1].t)
{
a[i].max = a[i].t;
}
}
long int max=0;
for(i=1;i<=n;i++)
if(a[i].max > max)
max =a[i].max;
cout<<max<<endl;
}
return 0;
}
Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now.
The game can be played by two or more than two players. It consists of a chessboard(棋盘)and some chessmen(棋子), and all chessmen are marked by a positive integer or “start” or “end”. The player starts from start-point and must jumps into end-point finally. In the course of jumping, the player will visit the chessmen in the path, but everyone must jumps from one chessman to another absolutely bigger (you can assume start-point is a minimum and end-point is a maximum.). And all players cannot go backwards. One jumping can go from a chessman to next, also can go across many chessmen, and even you can straightly get to end-point from start-point. Of course you get zero point in this situation. A player is a winner if and only if he can get a bigger score according to his jumping solution. Note that your score comes from the sum of value on the chessmen in you jumping path.
Your task is to output the maximum value according to the given chessmen list.
Input
Input contains multiple test cases. Each test case is described in a line as follow:
N value_1 value_2 …value_N
It is guarantied that N is not more than 1000 and all value_i are in the range of 32-int.
A test case starting with 0 terminates the input and this test case is not to be processed.
Output
For each case, print the maximum according to rules, and one line one case.
Sample Input
3 1 3 2
4 1 2 3 4
4 3 3 2 1
0
Sample Output
4
10
3
#include <iostream>
using namespace std;
typedef struct
{
long int max;
long int t;
}node;
int main()
{
long int n,i;
while(cin >> n&&n)
{
node a[1010];
a[0].max =0;
a[0].t=0;
for(i=1;i<=n;i++)
{
cin >> a[i].t;
if(a[i].t > a[i-1].t)
{
a[i].max = a[i].t+a[i-1].max;
}
else if(a[i].t < a[i-1].t)
{
a[i].max = a[i].t;
}
else if(a[i].t = a[i-1].t)
{
a[i].max = a[i].t;
}
}
long int max=0;
for(i=1;i<=n;i++)
if(a[i].max > max)
max =a[i].max;
cout<<max<<endl;
}
return 0;
}
作者: querdaizhi 发布时间: 2011-07-25
http://tieba.baidu.com/p/1136190421
作者: za083z 发布时间: 2011-07-25
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28