CodeForces 342B Xenia and Spies

本文探讨了一种在特定约束条件下,智能间谍如何快速且安全地传递重要信息的方法。通过分析间谍行动路线和警方监视策略,提出了一种最优传递路径,确保信息在最短时间内从起点传达到终点,同时避免被警方发现。

B. Xenia and Spies
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. 

Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the note to one of his neighbours in the row. In other words, if this spy's number is x, he can pass the note to another spy, either x - 1 or x + 1 (if x = 1 or x = n, then the spy has only one neighbour). Also during a step the spy can keep a note and not pass it to anyone.

But nothing is that easy. During m steps Xenia watches some spies attentively. Specifically, during step ti (steps are numbered from 1) Xenia watches spies numbers li, li + 1, li + 2, ..., ri (1 ≤ li ≤ ri ≤ n). Of course, if during some step a spy is watched, he can't do anything: neither give the note nor take it from some other spy. Otherwise, Xenia reveals the spies' cunning plot. Nevertheless, if the spy at the current step keeps the note, Xenia sees nothing suspicious even if she watches him.

You've got s and f. Also, you have the steps during which Xenia watches spies and which spies she is going to watch during each step. Find the best way the spies should act in order to pass the note from spy s to spy f as quickly as possible (in the minimum number of steps).

Input

The first line contains four integers nms and f (1 ≤ n, m ≤ 105; 1 ≤ s, f ≤ ns ≠ fn ≥ 2). Each of the following m lines contains three integers ti, li, ri (1 ≤ ti ≤ 109, 1 ≤ li ≤ ri ≤ n). It is guaranteed that t1 < t2 < t3 < ... < tm.

Output

Print k characters in a line: the i-th character in the line must represent the spies' actions on step i. If on step i the spy with the note must pass the note to the spy with a lesser number, the i-th character should equal "L". If on step i the spy with the note must pass it to the spy with a larger number, the i-th character must equal "R". If the spy must keep the note at the i-th step, the i-th character must equal "X".

As a result of applying the printed sequence of actions spy s must pass the note to spy f. The number of printed characters k must be as small as possible. Xenia must not catch the spies passing the note.

If there are miltiple optimal solutions, you can print any of them. It is guaranteed that the answer exists.

Sample test(s)
input
3 5 1 3
1 1 2
2 2 3
3 3 3
4 1 1
10 1 3
output
XXRR

看到这道题不经要吐槽一下

Day 4, Day 5这两天萌萌哒队长都放了很多重题

特别是Div2 ╮(╯▽╰)╭

结果碧荷大大6分钟就交了7道题

把新来的童鞋都吓坏了(⊙o⊙)…


言归正传,这道题大意是有一个间谍在被审讯的过程中要把一本重要的书传给另一个人

所有人按照一字排开,只能一个人一个人地传过去

但是警察蜀黍也不傻啊,总会盯着几个人看的

被盯着的时候总不能传吧o(╯□╰)o

假设把书传给身边的人需要一个单位时间

如果运气不好被警察蜀黍盯上了只能把书留着暂时不传,一次也记作一个单位时间

给出相应时间点警察蜀黍会盯着看的人的范围,问第i个间谍要传给第j个间谍至少需要多少个单位时间


想法很简单,贪心

一直朝着目标方向传,如果此时被盯着就不传,如果没被盯就传过去

直到传到目标间谍手里


但是有间谍j有可能在间谍i的左边或右边

所以要分两个方向处理


代码如下:

#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;

char seq[1000000+5];

int main() {
  int n, m, s, f;
  cin >> n >> m >> s >> f;
  int state[m][3];
  for (int i = 0; i < m; i++) cin >> state[i][0] >> state[i][1] >> state[i][2];
  
  int cnt = 0;
  if (s < f) {
    memset(seq, 'R', sizeof(seq));
    for (int i = 0; i < m; i++) {
      int prev_pos = s+state[i][0]-cnt;
      //cout << prev_pos-1 << endl;
      if (prev_pos-1 >= f) break;
      if ((prev_pos >= state[i][1] && prev_pos <= state[i][2]) ||
          (prev_pos-1 >= state[i][1] && prev_pos-1 <= state[i][2])) { cnt++; seq[state[i][0]] = 'X'; }
      //cout << state[i][0] << endl;
    }
  }
  else {
    memset(seq, 'L', sizeof(seq));
    for (int i = 0; i < m; i++) {
      int prev_pos = s-(state[i][0]-cnt);
      if (prev_pos+1 <= f) break;
      if ((prev_pos >= state[i][1] && prev_pos <= state[i][2]) ||
          (prev_pos+1 >= state[i][1] && prev_pos+1 <= state[i][2])) { cnt++; seq[state[i][0]] = 'X'; }
    }
  }
  //cout << cnt+f-s << endl;
  for (int i = 1; i <= cnt+abs(f-s); i++) cout << seq[i];
  //cout << seq[3] << endl;
  cout << endl;
  return 0;
}


内容概要:本文围绕“光伏-储能-数据中心”系统的容量优化配置展开研究,旨在通过构建数学模型并结合Matlab编程实现,对园区内光伏发电、储能设备与数据中心算力负荷之间的多能互补关系进行协同优化。研究综合考虑可再生能源出力的波动性、储能系统的充放电特性以及数据中心的动态用电需求与算力调度特性,建立以最小化综合成本、降低碳排放强度、提升能源自给率等为目标的多目标优化模型,并采用先进的智能优化算法(如粒子群、灰狼、鲸鱼等)进行求解,从而确定光伏装机容量与储能系统配置的最优方案。文中提供了完整的Matlab代码实现流程,涵盖数据预处理、模型构建、算法求解与结果可视化全过程,属于综合能源系统与信息基础设施深度融合的前沿交叉课题。; 适合人群:具备电力系统、能源工程、自动化或计算机等相关专业背景,熟悉Matlab编程与基本优化算法原理,从事新能源利用、绿色数据中心、综合能源系统规划与低碳调度等方向的研究生、科研人员及工程技术人员。; 使用场景及目标:① 掌握光伏-储能-数据中心耦合系统的建模思路与多能流协同机制;② 学习基于Matlab的多目标容量优化配置方法与智能算法应用技巧;③ 为工业园区、数字经济园区及绿色数据中心的能源系统规划、节能减排与可持续运行提供科学决策依据和技术解决方案。; 阅读建议:建议结合所提供的Matlab代码,深入理解目标函数设计、约束条件设定及算法实现细节,可通过调整负荷参数、改变气候数据、引入新的优化目标或约束条件等方式进行拓展性实验,以深化对系统特性的认知并提升实际科研与工程应用能力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值