You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
113 lines
2.4 KiB
113 lines
2.4 KiB
///*
|
|
// * algorithm02.cpp
|
|
// *
|
|
// * Created on: May 23, 2024
|
|
// * Author: 28032
|
|
// */
|
|
////要求有多少人被感染,可以先求有多少人不会被感染
|
|
////将跑者的位置列在数组上,以感染者为分界线划分成两群人
|
|
////左边的不会被感染的人是速度比右边最慢的人还慢的人
|
|
////右边的不会被感染的人是速度比左边最快的人还快的人
|
|
//#include <iostream>
|
|
//#include <vector>
|
|
//
|
|
//using namespace std;
|
|
//
|
|
//int N,num,**runner,cnt;
|
|
//
|
|
//void Swap(int a,int b)
|
|
//{
|
|
// for(int i = 0;i < 2;i++)
|
|
// {
|
|
// int tmp = runner[i][a];
|
|
// runner[i][a] = runner[i][b];
|
|
// runner[i][b] = tmp;
|
|
// }
|
|
//}
|
|
//
|
|
//int part(int* r, int low, int hight) //划分函数
|
|
//{
|
|
// int i = low, j = hight, pivot = r[low]; //基准元素
|
|
// while (i < j)
|
|
// {
|
|
// while (i<j && r[j]>pivot) //从右向左开始找一个 小于等于 pivot的数值
|
|
// {
|
|
// j--;
|
|
// }
|
|
// if (i < j)
|
|
// {
|
|
// Swap(i++,j);
|
|
// }
|
|
// while (i < j && r[i] <= pivot) //从左向右开始找一个 大于 pivot的数值
|
|
// {
|
|
// i++;
|
|
// }
|
|
// if (i < j)
|
|
// {
|
|
// Swap(i,j--);
|
|
// }
|
|
// }
|
|
// return i; //返回最终划分完成后基准元素所在的位置
|
|
//}
|
|
//void Quicksort(int* r, int low, int hight)
|
|
//{
|
|
// int mid;
|
|
// if (low < hight)
|
|
// {
|
|
// mid = part(r, low, hight); // 返回基准元素位置
|
|
// Quicksort(r, low, mid - 1); // 左区间递归快速排序
|
|
// Quicksort(r, mid+1, hight); // 右区间递归快速排序
|
|
// }
|
|
//}
|
|
//
|
|
//
|
|
//int main()
|
|
//{
|
|
// cin>>N>>num;
|
|
// cnt = 0;
|
|
//
|
|
// runner = new int*[2];
|
|
//
|
|
// pair<int,int> infected;
|
|
//
|
|
// for(int i = 0;i < 2;i++)
|
|
// {
|
|
// runner[i] = new int[N];
|
|
// for(int j = 0;j < N;j++)
|
|
// cin>>runner[i][j];
|
|
// }
|
|
// infected.first = runner[0][num-1];
|
|
// infected.second = runner[1][num-1];
|
|
//
|
|
// Quicksort(runner[0],0,N-1);
|
|
//
|
|
// int LeftMaxSpeed = -1e9,
|
|
// RightMinSpeed = 1e9;
|
|
// for(int i = 0;i < N;i++)
|
|
// {
|
|
// if(runner[0][i] < infected.first)
|
|
// LeftMaxSpeed = max(LeftMaxSpeed,runner[1][i]);
|
|
// else if(runner[0][i] > infected.first)
|
|
// RightMinSpeed = min(RightMinSpeed,runner[1][i]);
|
|
// else
|
|
// {
|
|
// LeftMaxSpeed = max(LeftMaxSpeed,runner[1][i]);
|
|
// RightMinSpeed = min(RightMinSpeed,runner[1][i]);
|
|
// num = i;
|
|
// }
|
|
// }
|
|
// for(int i = 0;i < num;i++)
|
|
// if(runner[1][i] <= RightMinSpeed)
|
|
// cnt++;
|
|
// for(int i = num + 1;i < N;i++)
|
|
// if(runner[1][i] >= LeftMaxSpeed)
|
|
// cnt++;
|
|
//
|
|
// cout<<N-cnt;
|
|
//
|
|
// return 0;
|
|
//}
|
|
//
|
|
//
|
|
//
|