概述:本道作业题是邰抡痰同学的课后练习,分享的知识点是c国共有n个城市,指导老师为宰老师,涉及到的知识点涵盖:noip模拟题收费站(cost)CC++代码在某个遥远的国家里,有n个城市。...-c国共有n个城市,下面是邰抡痰作业题的详细。
题目:noip模拟题收费站(cost)CC++代码在某个遥远的国家里,有n个城市。...-c国共有n个城市
// StationCost.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include
#include
#include
#include
#include
//记录每一步的选择。
struct SearchStep
{
int city;
int road;
int s;
SearchStep* next;
SearchStep* pre;
};
struct Road
{
int startc;
int endc;
int ci;
};
int FindNextCity(SearchStep* as,Road* ar,int n)
{
//查找线路是否有一端符合当前城市
int icity;
SearchStep* ps;
if (ar->startc == n)
icity = ar->endc ;
else if (ar->endc == n)
icity = ar->startc ;
else
return 0;
//查找线路是否已经过另一端城市
ps = as;
while (ps != NULL)
{
if (ps->city == icity)
return 0;
ps = ps->next ;
}
return icity;
}
int DoSearch(SearchStep* as,int aa,Road* ar,int* ac,int* ap,int ad)
{
//as 搜寻的路径;
//aa 公路数,ar 公路信息
//ac 最低的最高线路途经城市费用
//ap 城市收费信息
//ad 目标城市
int m,nextcity,nexts,ipay,imax;
SearchStep *ps,*pp;
ps = as;
if (ps->city == ad)
{
//查找所经过的路径,设置最大缴费值,比较缴费值和起讫城市的收费值,如果和其中之一相等,则直接返回
pp = ps;
while (pp != NULL)
{
ipay = *(ap + pp->city -1);
if (imax< ipay)
imax = ipay;
pp = pp->pre ;
}
*ac = imax;
if ((imax == *(ap + as->city -1)) || (imax == *(ap + ps->city -1)))
return 1;
else
{
if (ps->pre != NULL)
{
ps = ps->pre ;
ps ->next = NULL;
}
return 0;
}
}
m = ps->road;
while (m< aa)
{
nextcity = FindNextCity(as,ar + m,ps->city);
if (nextcity >0)
{
//执行到下一步
if (*ac >0)
if (*(ap + nextcity -1) >*ac)
{
//如果所到城市的费用大于已有线路最大费用,跳过
m++;
continue;
}
if (ps->s - (ar + m)->ci >0)
{
ps->next = new SearchStep;
ps->road = m;
ps = ps->next;
ps->next =NULL;
ps->pre =as;
ps->city = nextcity;
ps->road = 0;
ps->s = as->s - (ar + m)->ci;
nexts = DoSearch(ps,aa,ar,ac,ap,ad);
if (nexts == 1) return nexts;
}
}
m++;
}
if (ps->pre != NULL)
{
ps = ps->pre ;
ps ->next = NULL;
}
return 0;
}
int main(int argc, char* argv[])
{
//第一步,录入城市数量,线路数量,出发城市,目标城市,汽车油箱容量
int ccount,rcount,startc,endc,vehs,imaxcost;
int inputright;
inputright = 0;
while (inputright == 0)
{
cout<< "请输入城市数量,线路数量,出发城市,目标城市,汽车油箱容量\n";
cin >>ccount >>rcount >>startc >>endc >>vehs;
if (startc >ccount || endc >ccount)
cout<< "出发城市或目标城市不能大于城市数,请重新输入!";
else if (ccount >10000)
cout<< "城市数量不能大于10000,请重新输入!";
else if (rcount >50000)
cout<< "线路数量不能大于50000,请重新输入!";
else
inputright ++;
}
//初始化城市收费,线路信息
int *Pcity = new int [ccount];
Road *Proad = new Road [rcount];
int i,num1,num2,num3;
srand((unsigned)time(NULL));
for (i = 0;i { num1 = rand()%10000 + 1; *(Pcity + i) = num1; } for (i = 0; i { num1 = rand()%ccount + 1; num2 = rand()%ccount + 1; if (num1 == num2) { num2 = (num1 + 1) % ccount + 1; } (Proad + i)->startc = num1; (Proad + i)->endc = num2; num3 = rand()%10000 + 1; (Proad + i)->ci = num3; } //输出题目的数据 cout<< "城市数量\t线路数量\t出发城市\t目标城市\t汽车油箱容量\n"; cout<< ccount<< "\t"<< rcount<< "\t" ; cout<< startc<< "\t"<< endc<< "\t" ; cout<< vehs<< "\n"; for (i = 0;i cout<< *(Pcity + i)<< "\n"; for (i = 0;i cout<< (Proad + i)->startc<< "\t"<< (Proad + i)->endc<< "\t"<<(Proad + i)->ci<< endl; // getchar(); //开始寻找线路 SearchStep sFirst; sFirst.next = NULL; sFirst.city = startc; sFirst.pre = NULL; sFirst.road = 0; sFirst.s = vehs; imaxcost = -1; DoSearch(sFirst,rcount,Proad,imaxcost,Pcity,endc); //输出结果 cout<< "搜索结果为:"<< imaxcost<< endl; getchar(); return 0; } 提示:又是你…具体可看萌娘百科战舰少女词条E国、英国(英国皇家海军——TheRoyalNavy)J国、日本(旧日本帝国海军——TheImperialJapaneseNavy)U国、美国(美国海军——TheUnitedStatesNavy)G国、德国(德国战争海军——Kriegsmarine)C国、中国(中华民国... 提示:急!!C语言或C++都可以,谢谢!!描述 A、B两国间发生战争了,B国要在最短时间内对A国发动攻击。已知A国共有n个城市(城市编号1, 2, …, n),城市间有一些... 提示:C 国有 n 个大城市和 m 条道路,每条道路连接这 n 个城市中的某两个城市。任意两个城市之间最多只有一条道路直接相连。这 m 条道路中有一部分为单向通行的... 提示:国产奔驰C级共包括7款车型。分别是C 180 K经典型、C 200 CGI优雅型、C 200 CGI时尚型、C 260 CGI时尚型、C 260 CGI运动型、C 300时尚型、C 300运动型。排量分别为:C 180 K为1.6L,C 200 CGI为1.8L,C 260 CGI为1.8L,C 300为3.0L。其中C 180 K... 提示:N normal 普通客户 C Elite Club理财金账户C也就是贵宾
思考:
思考1:J国F国C国M国E国都是那几个国家
思考2:急!!C语言或C++都可以,谢谢!!
思考3:最优贸易用Dijkstra写,要求语言是c++
思考4:国产奔驰C级轿车共有几个型号?都是多大排量的?
思考5:中国银行卡n开头和c开头有什么区别