美赛数模

Merge After Toll

Multi-lane divided limited-access toll highways use “ramp tolls” and “barrier tolls” to collect tolls from motorists. A ramp toll is a collection mechanism at an entrance or exit ramp to the highway and these do not concern us here. A barrier toll is a row of tollbooths placed across the highway, perpendicular to the direction of traffic flow. There are usually (always) more tollbooths than there are incoming lanes of traffic (see former 2005 MCM Problem B). So when exiting the tollbooths in a barrier toll, vehicles must “fan in” from the larger number of tollbooth egress lanes to the smaller number of regular travel lanes. A toll plaza is the area of the highway needed to facilitate the barrier toll, consisting of the fan-out area before the barrier toll, the toll barrier itself, and the fan-in area after the toll barrier. For example, a three-lane highway (one direction) may use 8 tollbooths in a barrier toll. After paying toll, the vehicles continue on their journey on a highway having the same number of lanes as had entered the toll plaza (three, in this example).
Consider a toll highway having L lanes of travel in each direction and a barrier toll containing B tollbooths (B > L) in each direction. Determine the shape, size, and merging pattern of the area following the toll barrier in which vehicles fan in from B tollbooth egress lanes down to L lanes of traffic. Important considerations to incorporate in your model include accident prevention, throughput (number of vehicles per hour passing the point where the end of the plaza joins the L outgoing traffic lanes), and cost (land and road construction are expensive). In particular, this problem does not ask for merely a performance analysis of any particular toll plaza design that may already be implemented. The point is to determine if there are better solutions (shape, size, and merging pattern) than any in common use.
Determine the performance of your solution in light and heavy traffic. How does your solution change as more autonomous (self-driving) vehicles are added to the traffic mix? How is your solution affected by the proportions of conventional (human-staffed) tollbooths, exact-change (automated) tollbooths, and electronic toll collection booths (such as electronic toll collection via a transponder in the vehicle)?
Your MCM submission should consist of a 1 page Summary Sheet, a 1-2 page letter to the New Jersey Turnpike Authority, and your solution (not to exceed 20 pages) for a maximum of 23 pages. Note: The appendix and references do not count toward the 23 page limit.

模拟方法

// simulate_car.cpp: 定义控制台应用程序的入口点。
//written by Ricard.Huo
//assume calculate the number of cars left every one second
//output the status of the road every one second

include “stdafx.h”

include “stdlib.h”

include “stdio.h”

include “iostream”

include “windows.h”

include “CSpreadSheet.h”

using namespace std;
int car_num = 200;//The number of cars waitting under line
int t = 1;//Time used when all cars through
int l = 0;//The length of the merged road
int fee_num;//The number of toll station
int car_dis = 5;//The shortest distance between cars

int road1[3][100][2];//describe the status of the road, each point 1*3, desribe the speed and acceration
int road2[3][100][2];
int road3[2][100][2];

bool flag = true;//judge whether the car has moved
bool chang_road = true;//juduge whether the car change road
bool forward_car = false;//前方有车,速度降为与前方车辆一致
bool start_car = true;

//on each road, I will assume three variables, representing
//能走到的地方:x
//前方有车退避到的地方:v

void traverse1()
{
for (int i = 0; i < 3; i++)
{
if (i == 0) {
for (int j = l - 1; j >= 0; j–)
{
flag = true;//车辆尚未移动
if (road1[i][j][0] != -1)
{
int x = road1[i][j][0] + 1;
x = x + j;//x为他能走到的点
if (x >= l - 1) continue;
else {
for (int w1 = 1; w1 <= car_dis; w1++)
{
if (road1[i][w1 + x][0] != -1) {
int v = x + w1 - car_dis;
road1[i][v][0] = road1[i][x+w1][0];
flag = false;//车辆已经移动
}
}
if (flag == true) {//如果车辆尚未移动
road1[i][x][0] = road1[i][j][0] + 2;
}
}//car’s move
road1[i][j][0] = -1;
}

            //查看是否可以发车
            if (j == 0 && road1[i][j][0] == -1)
            {
                start_car = true;
                for (int k = 1; k < 5; k++)
                {
                    if (road1[i][k][0] != -1) { start_car = false; break; }
                }
                if (start_car) {
                    car_num--;
                    road1[i][j][0] = 0;
                }
            }
        }
    }
    else if (i == 1) {//The second road, car driver wants ro merge soon
        int k = l * 2 / 3;
        for (int j = k - 1; j >= 0; j--)
        {
            flag = true;
            if (road1[i][j][0] != -1)//检查此处是否有车
            {
                forward_car = false;
                chang_road = true;
                int z = road1[i][j][0] + 1;
                z += j;//此车能向前移动到多少米
                int q1 = j - car_dis;
                int q2 = j + car_dis - 1;
                //判断他是否可以变道
                for (int p = j; p <= q2; p++) {
                    if (road1[i-1][p][0] != -1) { chang_road = false; break; }
                }
                if (chang_road == true) {
                    for (int p = j; p <= z; p++)
                    {
                        if (road1[i-1][p][0] != -1) {
                            z = p - 5;//z更新
                            forward_car = true;
                            break;
                        }
                    }
                    q1 = z - 5;
                    q2 = z - 1;
                    for (int p = q1; p <= q2; p++)
                    {
                        if (road1[i-1][p][0] != -1)
                        {
                            chang_road = false;
                            break;
                        }
                    }
                    if (chang_road == true) {
                        if (forward_car == true)road1[i-1][z][0] = road1[i-1][z + 5][0];
                        else {
                            road1[i-1][z][0] = road1[i][j][0];
                        }
                        road1[i][j][0] = -1;
                    }
                }
                if (chang_road == false)
                {
                    int x = road1[i][j][0] + 1;
                    x = x + j;//x为他能走到的点
                    if (x >= k-1) {
                        road1[i][j][0] = -1;
                    }
                    else {
                        for (int w1 = 1; w1 <= car_dis; w1++)
                        {
                            if (road1[i][w1 + x][0] != -1) {
                                int v = x + w1 - car_dis;
                                road1[i][v][0] = road1[i][x + w1][0];
                                flag = false;//车辆已经移动
                            }
                        }
                        if (flag == true) {//如果车辆尚未移动
                            road1[i][x][0] = road1[i][j][0] + 2;
                        }
                    }//car's move
                    road1[i][j][0] = -1;
                }
            }
            if (j == 0 && road1[i][j][0] == -1)
            {
                start_car = true;
                for (int k = 0; k < 5; k++)
                {
                    if (road1[i][k][0] != -1) { start_car = false; break; }
                }
                if (start_car == true) {
                    car_num--;
                    road1[i][j][0] = 0;
                }
            }
        }
    }
    else
    {
        int k = l / 3;
        for (int j = k - 1; j >= 0; j--)
        {
            flag = true;
            if (road1[i][j][0] != -1)//检查此处是否有车
            {
                forward_car = false;
                chang_road = true;
                int z = road1[i][j][0] + 1;
                z += j;//此车能向前移动到多少米
                int q1 = j - car_dis;
                int q2 = j + car_dis - 1;
                //判断他是否可以变道
                for (int p = j; p <= q2; p++) {
                    if (road1[i - 1][p][0] != -1) { chang_road = false; break; }
                }
                if (chang_road == true) {
                    for (int p = j; p <= z; p++)
                    {
                        if (road1[i - 1][p][0] != -1) {
                            z = p - 5;//z更新
                            forward_car = true;
                            break;
                        }
                    }
                    q1 = z - 5;
                    q2 = z - 1;
                    for (int p = q1; p <= q2; p++)
                    {
                        if (road1[i - 1][p][0] != -1)
                        {
                            chang_road = false;
                            break;
                        }
                    }
                    if (chang_road == true) {
                        if (forward_car == true)road1[i - 1][z][0] = road1[i - 1][z + 5][0];
                        else {
                            road1[i - 1][z][0] = road1[i][j][0];
                        }
                        road1[i][j][0] = -1;
                    }
                }
                if (chang_road == false)
                {
                    int x = road1[i][j][0] + 1;
                    x = x + j;//x为他能走到的点
                    if (x >= k - 1) {
                        road1[i][j][0] = -1;
                    }
                    else {
                        for (int w1 = 1; w1 <= car_dis; w1++)
                        {
                            if (road1[i][w1 + x][0] != -1) {
                                int v = x + w1 - car_dis;
                                road1[i][v][0] = road1[i][x + w1][0];
                                flag = false;//车辆已经移动
                            }
                        }
                        if (flag == true) {//如果车辆尚未移动
                            road1[i][x][0] = road1[i][j][0] + 2;
                        }
                    }//car's move
                    road1[i][j][0] = -1;
                }
            }
            if (j == 0 && road1[i][j][0] == -1)
            {
                start_car = true;
                for (int k = 0; k < 5; k++)
                {
                    if (road1[i][k][0] != -1) { start_car = false; break; }
                }
                if (start_car == true) {
                    car_num--;
                    road1[i][j][0] = 0;
                }
            }
        }
    }
}

}
void traverse2()
{
for (int i = 0; i < 3; i++)
{
if (i == 0) {
for (int j = l - 1; j >= 0; j–)
{
flag = true;//车辆尚未移动
if (road2[i][j][0] != -1)
{
int x = road2[i][j][0] + 1;
x = x + j;//x为他能走到的点
if (x >= l - 1) continue;
else {
for (int w1 = 1; w1 <= car_dis; w1++)
{
if (road2[i][w1 + x][0] != -1) {
int v = x + w1 - car_dis;
road2[i][v][0] = road2[i][x + w1][0];
flag = false;//车辆已经移动
}
}
if (flag == true) {//如果车辆尚未移动
road2[i][x][0] = road2[i][j][0] + 2;
}
}//car’s move
road2[i][j][0] = -1;
}

            //查看是否可以发车
            if (j == 0 && road2[i][j][0] == -1)
            {
                start_car = true;
                for (int k = 1; k < 5; k++)
                {
                    if (road2[i][k][0] != -1) { start_car = false; break; }
                }
                if (start_car) {
                    car_num--;
                    road2[i][j][0] = 0;
                }
            }
        }
    }
    else if (i == 1) {//The second road, car driver wants ro merge soon
        int k = l * 2 / 3;
        for (int j = k - 1; j >= 0; j--)
        {
            flag = true;
            if (road2[i][j][0] != -1)//检查此处是否有车
            {
                forward_car = false;
                chang_road = true;
                int z = road2[i][j][0] + 1;
                z += j;//此车能向前移动到多少米
                int q1 = j - car_dis;
                int q2 = j + car_dis - 1;
                //判断他是否可以变道
                for (int p = j; p <= q2; p++) {
                    if (road2[i - 1][p][0] != -1) { chang_road = false; break; }
                }
                if (chang_road == true) {
                    for (int p = j; p <= z; p++)
                    {
                        if (road2[i - 1][p][0] != -1) {
                            z = p - 5;//z更新
                            forward_car = true;
                            break;
                        }
                    }
                    q1 = z - 5;
                    q2 = z - 1;
                    for (int p = q1; p <= q2; p++)
                    {
                        if (road2[i - 1][p][0] != -1)
                        {
                            chang_road = false;
                            break;
                        }
                    }
                    if (chang_road == true) {
                        if (forward_car == true)road2[i - 1][z][0] = road2[i - 1][z + 5][0];
                        else {
                            road2[i - 1][z][0] = road2[i][j][0];
                        }
                        road2[i][j][0] = -1;
                    }
                }
                if (chang_road == false)
                {
                    int x = road2[i][j][0] + 1;
                    x = x + j;//x为他能走到的点
                    if (x >= k - 1) {
                        road2[i][j][0] = -1;
                    }
                    else {
                        for (int w1 = 1; w1 <= car_dis; w1++)
                        {
                            if (road2[i][w1 + x][0] != -1) {
                                int v = x + w1 - car_dis;
                                road2[i][v][0] = road2[i][x + w1][0];
                                flag = false;//车辆已经移动
                            }
                        }
                        if (flag == true) {//如果车辆尚未移动
                            road2[i][x][0] = road2[i][j][0] + 2;
                        }
                    }//car's move
                    road2[i][j][0] = -1;
                }
            }
            if (j == 0 && road2[i][j][0] == -1)
            {
                start_car = true;
                for (int k = 0; k < 5; k++)
                {
                    if (road2[i][k][0] != -1) { start_car = false; break; }
                }
                if (start_car == true) {
                    car_num--;
                    road2[i][j][0] = 0;
                }
            }
        }
    }
    else
    {
        int k = l / 3;
        for (int j = k - 1; j >= 0; j--)
        {
            flag = true;
            if (road2[i][j][0] != -1)//检查此处是否有车
            {
                forward_car = false;
                chang_road = true;
                int z = road2[i][j][0] + 1;
                z += j;//此车能向前移动到多少米
                int q1 = j - car_dis;
                int q2 = j + car_dis - 1;
                //判断他是否可以变道
                for (int p = j; p <= q2; p++) {
                    if (road2[i - 1][p][0] != -1) { chang_road = false; break; }
                }
                if (chang_road == true) {
                    for (int p = j; p <= z; p++)
                    {
                        if (road2[i - 1][p][0] != -1) {
                            z = p - 5;//z更新
                            forward_car = true;
                            break;
                        }
                    }
                    q1 = z - 5;
                    q2 = z - 1;
                    for (int p = q1; p <= q2; p++)
                    {
                        if (road2[i - 1][p][0] != -1)
                        {
                            chang_road = false;
                            break;
                        }
                    }
                    if (chang_road == true) {
                        if (forward_car == true)road2[i - 1][z][0] = road2[i - 1][z + 5][0];
                        else {
                            road2[i - 1][z][0] = road2[i][j][0];
                        }
                        road2[i][j][0] = -1;
                    }
                }
                if (chang_road == false)
                {
                    int x = road2[i][j][0] + 1;
                    x = x + j;//x为他能走到的点
                    if (x >= k - 1) {
                        road2[i][j][0] = -1;
                    }
                    else {
                        for (int w1 = 1; w1 <= car_dis; w1++)
                        {
                            if (road2[i][w1 + x][0] != -1) {
                                int v = x + w1 - car_dis;
                                road2[i][v][0] = road2[i][x + w1][0];
                                flag = false;//车辆已经移动
                            }
                        }
                        if (flag == true) {//如果车辆尚未移动
                            road2[i][x][0] = road2[i][j][0] + 2;
                        }
                    }//car's move
                    road2[i][j][0] = -1;
                }
            }
            if (j == 0 && road2[i][j][0] == -1)
            {
                start_car = true;
                for (int k = 0; k < 5; k++)
                {
                    if (road2[i][k][0] != -1) { start_car = false; break; }
                }
                if (start_car == true) {
                    car_num--;
                    road2[i][j][0] = 0;
                }
            }
        }
    }
}

}

void traverse3()
{
for (int i = 0; i < 2; i++)
{
if (i == 0) {
for (int j = l - 1; j >= 0; j–)
{
flag = true;//车辆尚未移动
if (road3[i][j][0] != -1)
{
int x = road3[i][j][0] + 1;
x = x + j;//x为他能走到的点
if (x >= l - 1) continue;
else {
for (int w1 = 1; w1 <= car_dis; w1++)
{
if (road3[i][w1 + x][0] != -1) {
int v = x + w1 - car_dis;
road3[i][v][0] = road3[i][x + w1][0];
flag = false;//车辆已经移动
}
}
if (flag == true) {//如果车辆尚未移动
road3[i][x][0] = road3[i][j][0] + 2;
}
}//car’s move
road3[i][j][0] = -1;
}

            //查看是否可以发车
            if (j == 0 && road3[i][j][0] == -1)
            {
                start_car = true;
                for (int k = 1; k < 5; k++)
                {
                    if (road3[i][k][0] != -1) { start_car = false; break; }
                }
                if (start_car) {
                    car_num--;
                    road3[i][j][0] = 0;
                }
            }
        }
    }
    else if (i == 1) {//The second road, car driver wants ro merge soon
        int k = l * 2 / 3;
        for (int j = k - 1; j >= 0; j--)
        {
            flag = true;
            if (road3[i][j][0] != -1)//检查此处是否有车
            {
                forward_car = false;
                chang_road = true;
                int z = road3[i][j][0] + 1;
                z += j;//此车能向前移动到多少米
                int q1 = j - car_dis;
                int q2 = j + car_dis - 1;
                //判断他是否可以变道
                for (int p = j; p <= q2; p++) {
                    if (road3[i - 1][p][0] != -1) { chang_road = false; break; }
                }
                if (chang_road == true) {
                    for (int p = j; p <= z; p++)
                    {
                        if (road3[i - 1][p][0] != -1) {
                            z = p - 5;//z更新
                            forward_car = true;
                            break;
                        }
                    }
                    q1 = z - 5;
                    q2 = z - 1;
                    for (int p = q1; p <= q2; p++)
                    {
                        if (road3[i - 1][p][0] != -1)
                        {
                            chang_road = false;
                            break;
                        }
                    }
                    if (chang_road == true) {
                        if (forward_car == true)road3[i - 1][z][0] = road3[i - 1][z + 5][0];
                        else {
                            road3[i - 1][z][0] = road3[i][j][0];
                        }
                        road3[i][j][0] = -1;
                    }
                }
                if (chang_road == false)
                {
                    int x = road3[i][j][0] + 1;
                    x = x + j;//x为他能走到的点
                    if (x >= k - 1) {
                        road3[i][j][0] = -1;
                    }
                    else {
                        for (int w1 = 1; w1 <= car_dis; w1++)
                        {
                            if (road3[i][w1 + x][0] != -1) {
                                int v = x + w1 - car_dis;
                                road3[i][v][0] = road3[i][x + w1][0];
                                flag = false;//车辆已经移动
                            }
                        }
                        if (flag == true) {//如果车辆尚未移动
                            road3[i][x][0] = road3[i][j][0] + 2;
                        }
                    }//car's move
                    road3[i][j][0] = -1;
                }
            }
            if (j == 0 && road3[i][j][0] == -1)
            {
                start_car = true;
                for (int k = 0; k < 5; k++)
                {
                    if (road3[i][k][0] != -1) { start_car = false; break; }
                }
                if (start_car == true) {
                    car_num--;
                    road3[i][j][0] = 0;
                }
            }
        }
    }
}

}

void gen_excel()
{

}
int main()
{
while (scanf(“%d %d”, &l,&car_num) != EOF) {
printf(“%d %d\n”, l, car_num);
memset(road1, -1, sizeof(road1));
memset(road2, -1, sizeof(road2));
memset(road3, -1, sizeof(road3));
while (t++)
{
traverse1();
traverse2();
traverse3();
printf(“car_num:%d\n”, car_num);
if (car_num <= 0)break;

    }
    printf("t:%d\n", t);
}
return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值