| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
一个变量写错,竟会wa4次!啊啊啊啊!noip 可怎么办啊(附代码,做贡献)#include <stdio.h>
#include <stdlib.h>
#define inf 66666666
#define pri 2999
struct da{
int x, y , v ;}da[1001] ;
int ha[3000], n, ans , dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1 };
char vi[1001] ;
void init ()
{
memset (ha, -1, sizeof (ha) ) ;
ans = 0 ;
}
int find (int x, int y)
{
int t = ((x % pri) * (y % pri)) % pri ;
while (ha[t] != -1 && (da[ha[t]].x != x || da[ha[t]].y != y)){
t ++ ;
if (t == 3000) t = 0 ;}
return t ;
}
int dp (int nu)
{
int i , t , v = da[nu].v ;
vi[nu] = 1 ;
for (i = 0 ; i <= 3 ; i ++ ){
t = find (da[nu].x + dx[i], da[nu].y + dy[i]) ;
if (ha[t] == -1) continue ;
t = ha[t] ;
if ( ! vi[t]){
t = dp (t) ;
if (t > 0) v += t ;}}
if (ans < v) ans = v ;
return v ;
}
main ()
{
int i, j, t;
scanf ("%d", &n) ;
init () ;
for (i = 1; i <= n; i ++ ){
scanf ("%d%d%d", &da[i].x, &da[i].y, &da[i].v) ;
t = find (da[i].x , da[i].y ) ;
ha[t]= i ;}
dp (1) ;
printf ("%d\n", ans) ;
system ("pause") ;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator