您当前的位置: 首页 > 

MangataTS

暂无认证

  • 0浏览

    0关注

    423博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

AcWing 1934. 贝茜放慢脚步(二路归并)

MangataTS 发布时间:2022-02-05 23:51:23 ,浏览量:0

题目链接

https://www.acwing.com/problem/content/description/1936/

思路

题目的标签是二路归并,其实就是贪心,可以对比我们之前学习归并算法那里,我们现在有两个参照轴,时间轴和坐标轴,我们现在就是需要将这两个轴上发生的事件(减速)有序合并起来,我们可以计算当前哪个事件先发生,先发生的就先执行,也就是归并排序的归操作,将左右区间有序合并,所以我们先对T和D排序,然后逐步选择最先发生的事件归并即可

代码
#include
using namespace std;
//----------------自定义部分----------------
#define ll long long
#define mod 1000000007
#define endl "\n"
#define PII pair

int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};

ll ksm(ll a,ll b) {
	ll ans = 1;
	for(;b;b>>=1LL) {
		if(b & 1) ans = ans * a % mod;
		a = a * a % mod;
	}
	return ans;
}

ll lowbit(ll x){return -x & x;}

const int N = 2e6+10;
//----------------自定义部分----------------
int n,m,q,a[N];
vector T,D;

int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);
	cin>>n;
	string op;
	int x;
	for(int i = 1;i >op>>x;
		if(op == "T") T.push_back(x);
		else D.push_back(x);
	}
	D.push_back(1000);
	sort(T.begin(),T.end());
	sort(D.begin(),D.end());
	int i = 0,j = 0;
	double t = 0,s,v = 1.0;
	while(i             
关注
打赏
1665836431
查看更多评论
0.0633s