一道ACM题,为什么WA了,求解释啊

querdaizhi 2011-07-25 05:33:38
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;
}
...全文
162 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
rikiss 2011-07-26
  • 打赏
  • 举报
回复
逻辑有错,计算当前节点的max应该是当前节点之前的所有t小于当前节点t的所有节点中,最大的max加上当前节点的t的和
简单写了一下,提交accept了,LZ看下
for(i=1;i<=n;i++)
{
cin >> a[i].t;
int tempMax = 0;
for(int j =0 ; j< i; j++)
{
if(a[j].t < a[i].t)
{
if(a[j].max > tempMax)
{
tempMax = a[j].max;
}
}
}
a[i].max = tempMax + a[i].t;
}
BNUEP Offline Judge 北京师范大学珠海分校离线评测系统是在具备目测试数据的情况下,能无联网自动评测ACM/ICPC模式的源代码评测系统(即本地测试工具、评测机)。它主要有以下功能(所有的功能都无需联网,在本机即可实现): *评测核心功能: 基本具备Online Judge的判核心功能,如编译代码、内存限定,时间限定,获取代码长度等; *支持多种语言: 1.0 Beta2版本支持C/C++、Pascal、C#、JAVA; *出模式 可以在有标准输入数据和标准程序的情况下,由系统产生标准输出数据,并可批量保存,同时自动命名标准输出数据的后缀; *文本高亮对比 在判后,可以直接在本系统中将自己的程序输出和标准输出进行高亮的文本差异对比,操作类似于一些文本对比软件,在一定程度上可以较方便地发现WA代码的出错细节; *支持不限时执行代码 这个功能可以在一定程度上检测TLE代码的算法是否正确的,当然,不能是跑一天都没跑出来的程序; *打包与加密测试数据 使用加密后的数据可以正常判,但不显示标准输出。这个功能是为了弥补放出去给别人评测的测试数据是明文的缺陷。加密之后评测方就看不到测试数据。这样就既可以实现离线评测,又可以实现Online Judge上的对测试数据屏蔽; ACM-ICPC简介: ACM国际大学生程序设计竞赛(简称ACM-ICPC)是由国际计算机界具有悠久历史的权威性组织ACM学会(Association for Computing Machinery)主办,是世界上公认的规模最大、水平最高、参与人数最多的大学生程序设计竞赛,其宗旨是使大学生能通过计算机充分展示自己分析问和解决问的能力。 ACM-ICPC的每一道,都具备目、需描述、输入格式描述、输出格式描述、样例输入和样例输出共六大信息,有些目还有一定的提示。此外,裁判还额外存储了关于该的一组或多组对选手屏蔽的标准输入和标准输出数据,这些测试数据已经经过验证符合意要。当用户提交一道目的源码之后,裁判会将该源码放入评测系统中编译运行,并使用标准输入作为用户程序的输入,然后获取用户程序的输出,接着,将用户程序输出和标准输出比较,最后返回给用户一个评判结果。评判结果包括:Accepted(测试通过)、Compile Error(编译失败)、Memory Limit Exceed(内存超出限制)、Presentation Error(格式错误)、Runtime Error(运行时错误,可能是数组越界,改写只读的内存,除零,栈或堆溢出等错误)、Time Limit Exceed(时间超出限制)、Wrong Answer(答案错误)等。

33,006

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧