bnu10791DOTA选人

来源:互联网 发布:鞋子淘宝试用报告范文 编辑:程序博客网 时间:2024/05/01 02:36

DOTA选人

Time Limit: 1000ms
Memory Limit: 65536KB
64-bit integer IO format: %lld      Java class name: Main
Prev 
Submit Status Statistics Discuss
 Next
Type: 
None
     

    DOTA(Defense of the Ancients)是一款很受欢迎的游戏。DOTA将10个游戏玩家分为两组,分别为天灾和近卫,推倒对方主基地的一方获得胜利。每个玩家可以选择一个英雄作为游戏中的角色。每个角色有三个属性:力量,敏捷,智力。选人的策略对比赛的胜负非常关键,现在需要你找出最平衡的一套阵容(5个英雄)。这里对平衡性F做个很简单的定义:设E1是一套阵容力量的平均数,E2是敏捷的平均数,E3是智力的平均数,F是E1,E2,E3的方差, F越小越平衡。

    Input

    第一行一个正整数 C  表示一共有多少组数据
    对于每一组数据:
    第一行一个正整数N,表示这组英雄的个数(5<=N<=20)
    接下来的N行每行有4个整数 B,L,M,Z 表示该英雄编号为B,力量为L,敏捷为M,智力为Z。(1<=B<=N  0<L,M,Z<1000)

    Output

    对于每组数据,输出一行为最平衡的一套阵容(5个英雄的编号),英雄的编号需要从小到大排列,如果存在多组解输出英雄编号字典序最小的。

    Sample Input

    163 1 1 12 1 1 11 7 8 94 1 1 15 1 1 16 1 1 1

    Sample Output

    2 3 4 5 6


    Source


    //我们的目的是计算出每所有人的方差,然后排序输出,过程直接暴搜O(20^5)
    #include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;struct node{    int id;    double l,m,z;}hero[25];int cmp(node a,node b){    return a.id<b.id;}int main(){    int t,n;    double l,m,z,aver,fc,minm;    int r1,r2,r3,r4,r5;    int id1,id2,id3,id4,id5;    scanf("%d",&t);    while(t--)    {        minm=1000000;        scanf("%d",&n);        for(int i=0;i<n;i++)        {            scanf("%d%lf%lf%lf",&hero[i].id,&hero[i].l,&hero[i].m,&hero[i].z);        }        sort(hero,hero+n,cmp);        for(r1=0;r1<n-4;r1++)          for(r2=r1+1;r2<n-3;r2++)            for(r3=r2+1;r3<n-2;r3++)              for(r4=r3+1;r4<n-1;r4++)                for(r5=r4+1;r5<n;r5++)                {                    l=(hero[r1].l+hero[r2].l+hero[r3].l+hero[r4].l+hero[r5].l)/5;                    m=(hero[r1].m+hero[r2].m+hero[r3].m+hero[r4].m+hero[r5].m)/5;                    z=(hero[r1].z+hero[r2].z+hero[r3].z+hero[r4].z+hero[r5].z)/5;                    aver=(l+m+z)/3;                    fc=(l-aver)*(l-aver)+(m-aver)*(m-aver)+(z-aver)*(z-aver);                    if(fc<minm)                    {                        id1=hero[r1].id;                        id2=hero[r2].id;                        id3=hero[r3].id;                        id4=hero[r4].id;                        id5=hero[r5].id;                        minm=fc;                    }                }        printf("%d %d %d %d %d\n",id1,id2,id3,id4,id5);    }    return 0;}


    0 0
    原创粉丝点击