ÉèΪÊ×Ò³ ¼ÓÈëÊÕ²Ø

TOP

´ÓÒ»¶Ñ¶þάµãÖÐÕÒµ½×î¸ß·Ö
2013-11-20 14:24:05 À´Ô´: ×÷Õß: ¡¾´ó ÖРС¡¿ ä¯ÀÀ:118´Î
Tags£º´ÓÒ»¶Ñ ¶þάµãÖÐ ÕÒµ½ ×î¸ß·Ö
    ÌâÒ⣺¸øÄãÒ»¶Ñ¶þάµã£¬Ã¿¸öµãÓÐһЩ·ÖÊý¡£ÏÖÔÚÒª´Óµã£¨0 , 0 £©³ö·¢£¬Ö»ÄÜ´Ó±êºÅСµÄµã×ßµ½´óµÄµã£¬Ã¿¸öÈËÓÐÒ»¸ö×ߵľàÀëµÄÏÞÖÆ£¬ÎÊ×îºóÄÜÄõ½µÄ×î¸ßµÄ·ÖÊý£¬µ±È»Õâ¸öÈË´Ó£¨0 , 0£©³ö·¢»¹µÃ»Øµ½£¨ 0 , 0 £©¡£
    ˼·£ºÓÃdp[i][j]±íʾÔÚµãi·ÖÊýΪjµÄ×î¶Ì¾àÀë£¬×ªÒÆ·½³Ì¾ÍÊÇdp[i][j] = min£¨dp[i][j] , dp[k][j - w[k]] + Map[i][k]£© .
    CODE:
    #include <set>
    #include <map>
    #include <stack>
    #include <cmath>
    #include <queue>
    #include <cstdio>
    #include <string>
    #include <vector>
    #include <iomanip>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    #define Max 2505
    #define FI first
    #define SE second
    #define ll __int64
    #define PI acos£¨-1.0£©
    #define inf 0x3fffffff
    #define LL£¨x£© £¨ x ¡¶ 1 £©
    #define bug puts£¨"here"£©
    #define PII pair<int,int>
    #define RR£¨x£© £¨ x ¡¶ 1 | 1 £©
    #define mp£¨a,b£© make_pair£¨a,b£©
    #define mem£¨a,b£© memset£¨a,b,sizeof£¨a£©£©
    #define REP£¨i,s,t£© for£¨ int i = £¨ s £© ; i <= £¨ t £© ; ++ i £©
    using namespace std;
    #define N 333
    ll x[N] , y[N] , w[N] ;
    int n ;
    double Map[N][N] ;
    double dp[N][11111] ;
    double getD£¨int i , int j£© {
    return sqrt£¨1.0 * £¨x[i] - x[j]£© * £¨x[i] - x[j]£© + 1.0 * £¨y[i] - y[j]£© * £¨y[i] - y[j]£©£© ;
    }
    int Asum = 0 ;
    int main£¨£© {
    int ca = 0 ;
    while£¨cin ¡· n , n £© {
    Asum = 0 ;
    for £¨int i = 1 ; i <= n ; i ++ £© {
    scanf£¨"%I64d%I64d%I64d",&x[i] ,&y[i],&w[i]£© ;
    Asum += w[i] ;
    }
    n ++ ;
    x[0] = y[0] = x[n] = y[n] = w[0] = w[n] = 0 ;
    for £¨int i = 0 ; i <= n ; i ++ £© {
    for £¨int j = 0 ; j <= n ; j ++ £© {
    Map[i][j] = getD£¨i , j£© ;
    }
    }
    string name ;
    int lim ;
    printf£¨"Race %d\n",++ca£© ;
    while£¨cin ¡· name ¡· lim£© {
    if£¨name == "#"£©break ;
    for £¨int i = 0 ; i <= n ; i ++ £© {
    for £¨int j = 0 ; j <= Asum ; j ++ £©dp[i][j] = inf ;
    dp[0][0] = 0 ;
    }
    for £¨int i = 1 ; i <= n ; i ++ £© {
    for £¨int j = 0 ; j <= Asum ; j ++ £© {
    for £¨int k = 0 ; k < i ; k ++ £© {
    if£¨w[k] > j£©continue ;
    dp[i][j] = min£¨dp[i][j] , dp[k][j - w[k]] + Map[k][i]£© ;
    }
    }
    }
    int ans = 0 ;
    for £¨int i = 0 ; i <= Asum ; i ++ £© {
    if£¨dp[n][i] <= lim£©ans = max£¨ans , i£© ;
    }
    printf£¨"%s: %d\n",name.c_str£¨£© ,ans£© ;
    }
    }
    return 0 ;
    }
    /*
    5
    750 -800 30
    1500 0 50
    750 750 60
    -1250 750 70
    -1000 -500 50
    Chris 7000
    Karl 6500
    Tania 5000
    # 0
    4
    500 0 10
    0 500 10
    -500 0 10
    0 -500 10
    Hanny 2100
    Lizzie 1800
    # 0
    0
    */

¡¾´ó ÖРС¡¿¡¾´òÓ¡¡¿ ¡¾·±Ìå¡¿¡¾Í¶¸å¡¿¡¾Êղء¿ ¡¾ÍƼö¡¿¡¾¾Ù±¨¡¿¡¾ÆÀÂÛ¡¿ ¡¾¹Ø±Õ¡¿ ¡¾·µ»Ø¶¥²¿¡¿
·ÖÏíµ½: 
ÉÏһƪ£ºÉ¡±ø½µÂäµÄ¾«×¼±à³ÌʵÀý ÏÂһƪ£º×î´óÖµ¼õÈ¥×îСֵµÄƽ·½ÊµÀý

ÆÀÂÛ

ÕÊ¡¡¡¡ºÅ: ÃÜÂë: (ÐÂÓû§×¢²á)
Ñé Ö¤ Âë:
±í¡¡¡¡Çé:
ÄÚ¡¡¡¡ÈÝ:

¡¤Linuxϵͳ¼ò½é (2025-12-25 21:55:25)
¡¤Linux°²×°MySQL¹ý³Ì (2025-12-25 21:55:22)
¡¤Linuxϵͳ°²×°½Ì³Ì£¨ (2025-12-25 21:55:20)
¡¤HTTP Åc HTTPS µÄ²î„ (2025-12-25 21:19:45)
¡¤ÍøÕ¾°²È«±ØÐ޿ΣºÍ¼ (2025-12-25 21:19:42)