zoj 3263 Immaterial and Missing Power (二分)

Immaterial and Missing Power

Time Limit: 8 Seconds       Memory Limit: 32768 KB       Special Judge

Spring has passed by the land of Gensokyo, a reclusive realm in the far east, and the cherry trees have since shred their blossoms. However, the hanami(flower viewing) kept on going, with feasts being hosted day after day with no end in sight. Adding onto that, every time the feast is held, an unknown restless spiritual aura in Gensokyo also increases; however, nothing happens even while the spiritual aura rises, but when the spiritual aura rises, not a single person attempts to stop the feasts. As such, everyone who goes to the feast, be it human or youkai(phantoms), appears to be very suspicious. The truth is that Ibuki Suika, an oni(ogre) who loves drinks, feasts, and competition, uses her ability to control density to gather people to form a banquet. And she scatters herself to become mist to attend it.

Immaterial&MissingPower(pic)

There are N places and M roads in Gensokyo. Suika wants to made Q residents of Gensokyo have a feast at Hakurei Shrine as soon as possible. Each resident will start off from her residence, choose the fastest route and move at speed Vi. What's more, residents in Gensokyo prefer to "yukkuri shiteitte ne!"("take it easy!"), resident Ri will spend time Tij playing at place Pj once she gets there, excluding the starting and terminal. However, Suika can use her ability to increase one's Vi by Ai * sqrt(ci). As the limit of her ability, the total sum of ci cannot exceed a given number C.

What's the minimum time that Suika needs to wait for before all residents get to Hakurei Shrine to begin the feast.

Input

There are about 16 cases. Process to the end of file.

Each case begins with 3 integers 1 <= N <= 100, 1 <= M <= 1000, 1 <= Q <= 16. Then N places. Each place is identified by its name whose length is less than 30. Then M roads. Each road is represent by two string PaPb, its two ends, and a real number Dab, the distance. Then Q residents. Each resident contains two strings Xi and Pi, her name and her residence, and 2 + N real numbers, ViAiTi1Ti2, ..., TiN. The case ends with a real number C. All real numbers are in range [0.1, 1000000].

Output

The minimum time on separate lines.

Answer having an absolute or relative error less than 1e-6 will be accepted. You can assume that the answer always exists.

Sample Input

2 2 1
Eientei
Hakurei_Shrine
Hakurei_Shrine Eientei 2.72
Eientei Hakurei_Shrine 3.14
Reisen_Udongein_Inaba Eientei 0.1 0.2 0.3 0.4
1
8 11 9
Hakurei_Shrine
Forest_of_Magic(Marisa's_house)
Forest_of_Magic(Alice's_house)
Misty_Lake
Scarlet_Devil_Mansion
Mayohiga
Poltergeist_Mansion
Hakugyokurou
Hakurei_Shrine      Misty_Lake                      218
Hakurei_Shrine	    Forest_of_Magic(Marisa's_house) 192
Hakurei_Shrine      Forest_of_Magic(Alice's_house)  255
Misty_Lake          Forest_of_Magic(Marisa's_house) 51
Misty_Lake          Forest_of_Magic(Alice's_house)  49
Misty_Lake          Mayohiga                        66
Mayohiga            Forest_of_Magic(Alice's_house)  77
Misty_Lake          Scarlet_Devil_Mansion           221
Poltergeist_Mansion Forest_of_Magic(Alice's_house)  71
Poltergeist_Mansion Hakugyokurou                    73
Hakugyokurou        Scarlet_Devil_Mansion           90
Hakurei_Reimu       Hakurei_Shrine                  0.4 0.1 99 99 99 99 99 99 99 99
Kirisame_Marisa     Forest_of_Magic(Marisa's_house) 0.6 0.2 88 77 66 55 44 33 22 11
Izayoi_Sakuya       Scarlet_Devil_Mansion           0.4 0.3 77 10 10 10 10 10 10 10
Alice_Margatroid    Forest_of_Magic(Alice's_house)  0.4 0.2 66 11 22 33 44 55 66 77
Patchouli_Knowledge Scarlet_Devil_Mansion           0.5 0.3 55 15 15 15 15 15 15 15
Konpaku_Youmu       Hakugyokurou                    0.6 0.1 44 11 13 17 19 23 29 31
Remilia_Scarlet     Scarlet_Devil_Mansion           0.6 0.3 33 99 99 88 88 88 11 11
Saigyouji_Yuyuko    Hakugyokurou                    0.4 0.1 22 31 29 23 19 17 13 11
Hong_Meiling        Scarlet_Devil_Mansion           0.5 0.2 11 22 33 44 55 66 77 88
49

Sample Output

9.06666768697071727374757677787980
484.202020202020202020202020202020

External Links

TeamShanghaiAlice(banner) 
Wikipedia
Touhou Wiki


Author:  WU, Zejun

Source: ZOJ Monthly, November 2009


二分套二分。精度问题,样例都没过交一发竟然AC了?!!

#include<cstdio>
#include<map>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<list>
#include<set>
#include<cmath>
using namespace std;
const int maxn = 1e2 + 5;
const int INF = 1e9;
const double eps = 1e-7;
typedef unsigned long long ULL;
typedef long long LL;
typedef pair<int, double> P;
#define fi first
#define se second

map<string, int> M;
vector<P> G[maxn];
int pos[20];
double V[20], A[20], T[maxn][20];
int sink, q, n;
double C;
double dist[maxn];

struct Node{
    int pos;
    double dis;
    bool operator < (const Node& e) const{
        return dis > e.dis;
    }
};

double get(int source, double ci, int from){
    double v = A[source]*sqrt(ci) + V[source];
    priority_queue<Node> q;
    while(!q.empty())
        q.pop();
    for(int i = 0;i < n;i++)
        dist[i] = 1e12;
    dist[from] = 0;
    q.push((Node){from, 0});

    while(!q.empty()){
        Node tem = q.top();
        q.pop();
        int pos = tem.pos;
        double dis = tem.dis;

        if(dis > dist[pos])
            continue;
        if(pos == sink){
            return dis;
        }
        for(int i = 0;i < G[pos].size();i++){
            P& edge = G[pos][i];
            int to = edge.fi;
            double der = edge.se;
            if(dist[to] > dis+der/v+T[to][source]){
                dist[to] =  dis+der/v+T[to][source];
                q.push((Node){to, dist[to]});
            }
        }
    }
}

bool can(double limit){
    double left = C;
    for(int i = 0;i < q;i++){
        double l = 0, r = 1e7, ans = 1e6;
        for(int c = 0;c < 100;c++){
            double mid = (l+r)/2;
            if(limit-get(i, mid, pos[i])>eps){
                ans = mid;
                r = mid;
            }
            else
                l = mid;
        }
        left -= ans;
    }
    if(left < eps)
        return false;
    return true;
}

int main(){
    int m;
    while(scanf("%d%d%d", &n, &m, &q) != EOF){
        M.clear();
        for(int i = 0;i < n;i++)
            G[i].clear();
        for(int i = 0;i < n;i++){
            string s;
            cin >> s;
            M[s] = i;
            if(s == "Hakurei_Shrine")
                sink = i;
        }
        while(m--){
            string s;
            cin >> s;
            int x = M[s];
            cin >> s;
            int y = M[s];
            double dis;
            cin >> dis;
            G[x].push_back(P(y, dis));
            G[y].push_back(P(x, dis));
        }
        for(int i = 0;i < q;i++){
            string s;
            cin >> s >> s >> V[i] >> A[i];
            pos[i] = M[s];
            for(int j = 0;j < n;j++)
                cin >> T[j][i];
            T[sink][i] = 0;
        }
        cin >> C;

        double l = 0, r = 1e12;
        double ans;
        for(int c = 0;c < 100;c++){
            double mid = (l+r)/2;
            if(can(mid)){
                r = mid;
                ans = mid;
            }
            else
                l = mid;
        }
        printf("%.7lf\n", ans);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值