本Markdown编辑器使用StackEdit修改而来,用它写博客,将会带来全新的体验哦:
// 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
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 road13[100]2;//describe the status of the road, each point 1*3, desribe the speed and acceration
int road23[100]2;
int road32[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;
}
Markdown 是一种轻量级标记语言,它允许人们使用易读易写的纯文本格式编写文档,然后转换成格式丰富的HTML页面。 —— [ 维基百科 ]
使用简单的符号标识不同的标题,将某些文字标记为粗体或者斜体,创建一个链接等,详细语法参考帮助?。
本编辑器支持 Markdown Extra , 扩展了很多好用的功能。具体请参考Github.
Markdown Extra 表格语法:
项目 | 价格 |
---|---|
Computer | $1600 |
Phone | $12 |
Pipe | $1 |
可以使用冒号来定义对齐方式:
项目 | 价格 | 数量 |
---|---|---|
Computer | 1600 元 | 5 |
Phone | 12 元 | 12 |
Pipe | 1 元 | 234 |
定义 D
定义D内容
代码块语法遵循标准markdown代码,例如:
// 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;
}
... prompt'''
生成一个脚注1.
用 [TOC]
来生成目录:
使用MathJax渲染LaTex 数学公式,详见math.stackexchange.com.
更多LaTex语法请参考 这儿.
可以渲染序列图:
或者流程图:
即使用户在没有网络的情况下,也可以通过本编辑器离线写博客(直接在曾经使用过的浏览器中输入write.blog.csdn.net/mdeditor即可。Markdown编辑器使用浏览器离线存储将内容保存在本地。
用户写博客的过程中,内容实时保存在浏览器缓存中,在用户关闭浏览器或者其它异常情况下,内容不会丢失。用户再次打开浏览器时,会显示上次用户正在编辑的没有发表的内容。
博客发表后,本地缓存将被删除。
用户可以选择 把正在写的博客保存到服务器草稿箱,即使换浏览器或者清除缓存,内容也不会丢失。
注意:虽然浏览器存储大部分时候都比较可靠,但为了您的数据安全,在联网后,请务必及时发表或者保存到服务器草稿箱。