123

 

#include<iostream>

#include<string.h>

#include<stdio.h>

#include<iomanip>

usingnamespace std;

structdate

{

    intmonth, day;

};

structmeeting

{

    datestartdate, enddate;

    charplace[10];

    int cost,hotel, influence;

}M[14];

void datainit(int *p[14])

{

    int i, j;

    intstartday[14] = { 0,20,21,26,26,29,22,2,1,3,6,7,8,7 };

    intstartmonth[14] = { 0,7,7,7,7,7,7,8,8,8,8,8,8,8 };           //开始日期

    intendday[14] = { 0,25,26,28,28,31,26,4,3,6,8,9,10,10 };

    intendmonth[14] = { 0,7,7,7,7,7,7,8,8,8,8,8,8,8 };         //结束日期

    intregtrans[14] = { 0,1200,980,500,500,500,650,550,550,600,500,500,650,400 };

    inthotel[14] = { 0,650,0,400,460,480,550,500,490,500,450,480,490,320 };

    intinf[14] = { 0,5,5,3,4,3,4,4,3,3,4,3,4,3 };

    charposition[14][10] = { ","北京","上海","兰州","成都","昆明","广州","厦门","南京","杭州","济南","天津","大连","咸阳" };

    intlongtravel[14][14] =

    {

        {0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 },

        {0 ,0 ,441 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 },

        {0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 },

        {0 ,0 ,946 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 },

        {0 ,0 ,989 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 },

        {0 ,1494 ,961 ,829 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 },

        {0 ,0 ,542 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 },

        {0 ,871 ,364 ,389 ,1387 ,960 ,1169 ,0 ,0 ,0 ,0 ,0 ,0 ,0 },

        {0 ,581 ,151 ,1004 ,947 ,986 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 },

        {0 ,817 ,101 ,713 ,1186 ,961 ,1126 ,0 ,0 ,0 ,0 ,0 ,0 ,0 },

        {0 ,248 ,484 ,999 ,928 ,914 ,1357 ,419 ,790 ,0 ,0 ,0 ,0 ,0 },

        {0 ,69 ,453 ,1141 ,907 ,945 ,1510 ,459 ,1085 ,0 ,0 ,0 ,0 ,0 },

        {0 ,463 ,841 ,1628 ,1275 ,1421 ,1166 ,728 ,965 ,586 ,0 ,0 ,0 ,0 },

        {0 ,491 ,755 ,1058 ,338 ,269 ,960 ,561 ,1044 ,0 ,0 ,0 ,0 ,0 }

    };

    for (i =0; i <= 13; i++)

    {

        M[i].startdate.month= startmonth[i];

        M[i].startdate.day= startday[i];

        M[i].enddate.month= endmonth[i];

        M[i].enddate.day= endday[i];

        M[i].cost= regtrans[i];

        M[i].hotel= hotel[i];

        M[i].influence= inf[i];

        strcpy_s(M[i].place,position[i]);

        for (j =0; j <= 13; j++)

        {

            *(p[i] +j) = longtravel[i][j];

        }

    }

}

void displaydata()

{

    int i;

    for (i =1; i <= 13; i++)

    {

        cout<<"Meetingin "<<M[i].place <<"starts at "<<M[i].startdate.month <<"/"<<M[i].startdate.day <<"\tends at "<<M[i].enddate.month <<"/"<<M[i].enddate.day <<"\t"<<M[i].cost <<"\t"<<M[i].hotel << endl;

    }

    cout<<'\n';

}

int gap(datestart, dateend)

{

    if (start.month== end.month)

        return (abs(end.day -start.day) - 1);

    elseif (start.month< end.month)

        return (end.day +30 - start.day);

    elsereturn  (start.day +30 - end.day);

}

int compare(datea, dateb)

{

    if (a.month== b.month)

    {

        if (a.day< b.day) return 1;

        elsereturn 0;

    }

    elsereturn (-(a.month- b.month));

}

int find(intnow)

{

    int i;

    for (i = now + 1;i <= 13; i++)

    {

        if((compare(M[now].enddate,M[i].startdate)) && (gap(M[now].enddate,M[i].startdate) >= 1))

            return i;

    }return 0;

}

int min(inta, intb)

{

    if (a <=b)returna;

    elsereturnb;

}

int cheaper(intnow, intnext)

{

    if (M[now].hotel<= M[next].hotel) returnnow;

    elsereturnnext;

}

int whether(intnow, intnext, intcostarray[14][14])

{

    int back,noback;

    back= costarray[now][2] +costarray[next][2];

    noback= costarray[next][now] +(gap(M[now].enddate, M[next].startdate)- 1)*M[cheaper(now, next)].hotel;

    if (back> noback) return(-noback);

    elsereturn back;

};

int calcu(intnow, intnext, intcostarray[14][14])

{

    inttotal(0);

    total= (gap(M[now].startdate, M[now].enddate)+ 3)*M[now].hotel + M[now].cost+ abs(whether(now, next, costarray))

        +(gap(M[next].startdate, M[next].enddate)+ 3)*M[next].hotel + M[next].cost;

    returntotal;

}

void main()

{

    int fir,sec, thi, fort, i;

    inttravel[14][14], *p[14];

    for (i =0; i <= 13; i++)

    {

        p[i]= travel[i];

    }

    datainit(p);

    displaydata();

    for (fir= 1; fir <= 9; fir++)

    {

        for (sec= find(fir); sec <= 13; sec++)

        {

            for (thi= find(sec); thi <= 13; thi++)

            {

                if (thi== 0)

                {

                    cout<< M[fir].influence +M[sec].influence <<'\t';

                    cout<< travel[fir][2] +calcu(fir, sec, travel) + travel[sec][2] <<'\t';

                    cout<< M[fir].place <<setw(4) <<gap(M[fir].enddate, M[sec].startdate) <<";

                    cout<<"("<<whether(fir, sec, travel) / abs(whether(fir, sec, travel)) <<")\t";

                    cout<< M[sec].place << endl;

                    break;

                }

                for (fort= find(thi); fort <= 13; fort++)

                    if (fort== 0)

                    {

                        cout<< M[fir].influence +M[sec].influence + M[thi].influence <<'\t';

                        cout<< travel[fir][2] +calcu(fir, sec, travel) - M[sec].cost - (gap(M[sec].startdate, M[sec].enddate)+ 3)*M[sec].hotel + calcu(sec, thi, travel) + travel[thi][2] <<'\t';

                        cout<< M[fir].place <<setw(4) <<gap(M[fir].enddate, M[sec].startdate) <<";

                        cout<<"("<<whether(fir, sec, travel) / abs(whether(fir, sec, travel)) <<")\t";

                        cout<< M[sec].place <<setw(4) <<gap(M[sec].enddate, M[thi].startdate) <<";

                        cout<<"("<<whether(sec, thi, travel) / abs(whether(sec, thi, travel)) <<")\t";

                        cout<< M[thi].place << endl;

                        break;

                    }

                    else

                    {

                        cout<< M[fir].influence +M[sec].influence + M[thi].influence + M[fort].influence <<'\t';

                        cout<< travel[fir][2] +calcu(fir, sec, travel) - M[sec].cost - (gap(M[sec].startdate, M[sec].enddate)+ 3)*M[sec].hotel + calcu(sec, thi, travel) - M[thi].cost -(gap(M[thi].startdate, M[thi].enddate) + 3)*M[sec].hotel + calcu(thi, fort,travel) + travel[fort][2] <<'\t';

                        cout<< M[fir].place <<setw(4) <<gap(M[fir].enddate, M[sec].startdate) <<";

                        cout<<"("<<whether(fir, sec, travel) / abs(whether(fir, sec, travel)) <<")\t";

                        cout<< M[sec].place <<setw(4) <<gap(M[sec].enddate, M[thi].startdate) <<";

                        cout<<"("<<whether(sec, thi, travel) / abs(whether(sec, thi, travel)) <<")\t";

                        cout<< M[thi].place <<setw(4) <<gap(M[thi].enddate, M[fort].startdate) <<";

                        cout<<"("<<whether(thi, fort, travel) / abs(whether(thi, fort, travel)) <<")\t";

                        cout<< M[fort].place << endl;

                    }

            }

        }

        //system("pause");

    }

    system("pause");

}

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

张懿娈

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值