[gym102012K]Rikka with Ants

time limit per test : 4.0 s
memory limit per test : 1024 MB

Every time when Rikka faces to a great nature sight, she will recall a line of ants moving in a hurry. Rikka loves ants and keeps two large colonies of ants in her drawer. Observing ants hurrying in moving has controlled her life.

That is why she prepares n n n different nests in her drawer, and n n n undirected channels between these nests form a circular orbit. All nests are numbered by 1 1 1 to n n n in order, and the lengths of channels are known. The first colony of ants is living in the s 1 s_1 s1-th nest, and the second colony is living in the s 2 s_2 s2-th nest.

Now, ants decide to move to new nests together. The new home for these two colonies of ants will be the e1-th nest and the e 2 e_2 e2-th nest respectively.

For each colony, all ants should queue up one by one to crawl from the origin to the destination along a path. They cannot be split into several groups crawling moving along different paths. Then, they can measure the complexity of their plan moving to new nest using the total length of channels in the path selected.

If these two colonies of ants select paths sharing some common channels, they will walk through these channels slowly for security. Specifically, for each common channel, we can consider equivalently that its measured length will be tripled.

Ants are highly intelligent and they all want to minimize the complexities of their plan. They will choose the best strategies for themselves respectively without negotiation. All they know are the lengths of channels, and the nests where their colony and the other one will start and end respectively.

Rikka wants you to calculate the expected complexities of plans for each colony of ants. For more details about the best strategy, please refer to note.

Input

The input contains several test cases, and the first line contains a single integer T ( 1 ≤ T ≤ 5000 ) T(1≤T≤5000) T(1T5000), the number of test cases.

For each test case, the first line contains a single integer n ( 2 ≤ n ≤ 50 ) n(2≤n≤50) n(2n50), the number of nests and also the number of channels between them.

The second line contains n n n integers a 1 , a 2 , ⋯ , a n ( 1 ≤ a i ≤ 50 ) a_1,a_2,⋯,a_n (1≤a_i≤50) a1,a2,,an(1ai50), where the i-th one, ai, represents the length of the undirected channel between the i-th nest and the ( ( i    m o d    n ) + 1 ) ((i \ \ mod \ \ n)+1) ((i  mod  n)+1)-th nest. It is guaranteed that the total length of the n n n channels is odd.The third line contains four integers s 1 , e 1 , s 2 s_1,e_1,s_2 s1,e1,s2 and e 2 ( 1 ≤ s 1 , s 2 , e 1 , e 2 ≤ n , s 1 e_2 (1≤s_1,s_2,e_1,e_2≤n, s_1 e2(1s1,s2,e1,e2n,s1 e 1 , s 2 e_1, s_2 e1,s2 e 2 ) e_2) e2), representing the original nests where these ants live and their new nests.
Output

For each test case, output a line with two space-separated numbers, representing the expected complexity for the first colony of ant and the expected complexity for the second colony respectively. Your answer is considered correct if the absolute or relative error between each number in your output and the corresponding one in Rikka’s answer does not exceed 1 0 − 9 10^{−9} 109
. Formally, let a number of your answer be a, and the corresponding number of Rikka’s answer be b b b. Your answer is considered correct if ∣ a − b ∣ m a x ( 1 , ∣ b ∣ ) ≤ 1 0 − 9 \frac {|a−b|} {max(1,|b|)}≤10^{−9} max(1,b)ab109.
Example
Input

2
5
1 5 2 4 3
1 2 3 4
5
1 5 2 4 3
1 3 2 4

Output

1.000000000000000 2.000000000000000
14.666666666666667 14.666666666666667

Note

What we are talking about including strategies, best strategies and expectations are actually what about Nash Equilibrium and mixed strategies.

In the theory of games, a player is said to use a mixed strategy whenever the player chooses to randomize over the set of available actions. Formally, a mixed strategy is a probability distribution that assigns to each available action a likelihood of being selected. If only one action has a positive probability of being selected, the player is said to use a pure strategy. In the first sample case, the best strategies for both colonies are pure strategies.

A mixed strategy profile is a list of strategies, one for each player in the game. A mixed strategy profile induces a probability distribution or lottery over the possible outcomes of the game. In this problem, the profiles are those plans that we discussed before.

A Nash equilibrium (mixed strategy) is a strategy profile with the property that no single player can, by deviating unilaterally to another strategy, induce a lottery that he or she finds strictly preferable. In 1950, the mathematician John Nash proved that every game with a finite set of players and actions has at least one equilibrium.In this problem, a Nash equilibrium is what you need to find. You may find out several different equilibriums. If some of them have the same unilateral strategy, their earnings must be constant.

We still need to discuss when several different equilibriums without fixed unilateral strategy exist. Notice that in this case, we have a unique equilibrium with mixed, impure strategies. Since ants like to show-off their intelligence, this equilibrium is exactly their final choices.

In the second test case, though we have three different equilibriums whose earnings are ( 8 , 10 ) , ( 13 , 11 ) (8,10) , (13,11) (8,10),(13,11) and ( 14.666 ⋯ , 14.666 ⋯ ) (14.666⋯,14.666⋯) (14.666,14.666), the last one is the earnings for the only equilibrium with mixed, impure strategies and thus is what we need.

题意:
有两窝蚂蚁要迁移巢穴,从 s 1 s_1 s1 e 1 e_1 e1,从 s 2 s_2 s2 e 2 e_2 e2,两个相邻的巢穴之间有一个通道,如果这个通道同时使用的话,使用时间就要乘三。所有巢穴是一个环形。
同一窝的蚂蚁要一起行动,不能分开。每一巢的蚂蚁都是按照自己最快的策略选择的。
问耗时的期望。

题解:
百度词条:纳什平衡
预处理出蚂蚁迁移的四种情况,特判四种显然的博弈情况之后,剩下的直接套纳什平衡模型即可。

#include<bits/stdc++.h>
#define ll long long
#define pa pair<int,int>
using namespace std;
int n,a[54];
int s[4],e[4];
pa ans[4][4];
int c[54];
pa  work(){
    memset(c,0,sizeof(c));
    for(int i=0;i<2;i++){
        //cout<<i<<" ----- "<<endl;
        for(int j=s[i];j!=e[i];j=(j+1)%n){
            //cout<<j<<" "<<i+1<<endl;
            c[j]+=i+1;
        }
    }
    //for(int i=0;i<n;i++)cout<<c[i]<<" " ;cout<<endl;
    pa ret={0,0};
    for(int i=0;i<n;i++){
        if(c[i]==1){
            ret.first+=a[i];
        }
        if(c[i]==2){
            ret.second+=a[i];
        }
        if(c[i]==3){
            ret.first+=a[i]*3;
            ret.second+=a[i]*3;
        }
    }
    return ret;
}
int w33ha(){
    scanf("%d",&n);
    for(int i=0;i<2;i++){
        for(int j=0;j<2;j++){
            ans[i][j]={-1,-1};
        }
    }
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    for(int i=0;i<2;i++){
        scanf("%d%d",&s[i],&e[i]);
        --s[i];--e[i];
    }
    //cout<<s[0]<<" "<<e[0]<<" "<<s[1]<<" "<<e[1]<<endl;
    for(int i=0;i<2;i++){
        for(int j=0;j<2;j++){
            ans[i][j]=work();
            swap(s[1],e[1]);
        }
        swap(s[0],e[0]);
    }
    if(ans[0][0].first<=ans[1][0].first&&ans[0][1].first<=ans[1][1].first){
        if(ans[0][0].second<=ans[0][1].second){
            printf("%.10f %.10f\n",ans[0][0].first*1.0,ans[0][0].second*1.0);
        }
        else{
            printf("%.10f %.10f\n",ans[0][1].first*1.0,ans[0][1].second*1.0);
        }
        return 0;
    }
    if(ans[0][0].first>=ans[1][0].first&&ans[0][1].first>=ans[1][1].first){
        if(ans[1][0].second<=ans[1][1].second){
            printf("%.10f %.10f\n",ans[1][0].first*1.0,ans[1][0].second*1.0);
        }
        else{
            printf("%.10f %.10f\n",ans[1][1].first*1.0,ans[1][1].second*1.0);
        }
        return 0;
    }
    if(ans[0][0].second<=ans[0][1].second&&ans[1][0].second<=ans[1][1].second){
        if(ans[0][0].first<=ans[1][0].first){
            printf("%.10f %.10f\n",ans[0][0].first*1.0,ans[0][0].second*1.0);
        }
        else{
            printf("%.10f %.10f\n",ans[1][0].first*1.0,ans[1][0].second*1.0);
        }
        return 0;
    }
    if(ans[0][0].second>=ans[0][1].second&&ans[1][0].second>=ans[1][1].second){
        if(ans[0][1].first<=ans[1][1].first){
            printf("%.10f %.10f\n",ans[0][1].first*1.0,ans[0][1].second*1.0);
        }
        else{
            printf("%.10f %.10f\n",ans[1][1].first*1.0,ans[1][1].second*1.0);
        }
        return 0;
    }
    double A,B,_A,_B;
    A=1.0*(ans[1][1].second-ans[1][0].second)/(ans[0][0].second+ans[1][1].second-ans[1][0].second-ans[0][1].second);
    _A=1.0-A;
    B=1.0*(ans[1][1].first-ans[0][1].first)/(ans[0][0].first+ans[1][1].first-ans[1][0].first-ans[0][1].first);
    _B=1.0-B;
    printf("%.10f %.10f\n",
           A*B*(ans[0][0].first)+A*_B*(ans[0][1].first)+_A*B*(ans[1][0].first)+_A*_B*(ans[1][1].first),
           A*B*(ans[0][0].second)+A*_B*(ans[0][1].second)+_A*B*(ans[1][0].second)+_A*_B*(ans[1][1].second));
    return 0;
}
int main(){
    int T;scanf("%d",&T);
    while(T--)w33ha();
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值