CF-45D. Event Dates(贪心)

本文介绍了一种解决历史事件日期选择问题的算法。该算法帮助确定一系列著名历史事件的确切发生日期,在已知每个事件可能发生的时间段的情况下,确保任意两天内不会发生超过一个事件。通过选择每个时间段的最早日期,并调整后续时间段的开始日期来避免冲突。

D. Event Dates
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

On a history lesson the teacher asked Vasya to name the dates when n famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [li, ri] (inclusive) on which the event could have taken place. However Vasya also remembers that there was at most one event in one day. Help him choose such n dates of famous events that will fulfill both conditions. It is guaranteed that it is possible.

Input

The first line contains one integer n (1 ≤ n ≤ 100) — the number of known events. Then follow n lines containing two integers li and rieach (1 ≤ li ≤ ri ≤ 107) — the earliest acceptable date and the latest acceptable date of the i-th event.

Output

Print n numbers — the dates on which the events took place. If there are several solutions, print any of them. It is guaranteed that a solution exists.

Sample test(s)
input
3
1 2
2 3
3 4
output
1 2 3 
input
2
1 3
1 3
output
1 2 

思路:每次选择左边界最小,次之右边界最小,选择此区间的左边界值l作为此区间代表,并删去本区间,然后提升剩余区间的左边界使之大于那个区间的代表l,重复此步骤即可


#include<iostream>
#include<cstring>
using namespace std;
const int mm=110;
class node
{
  public:int l,r;
}f[mm];
bool vis[mm];
int ans[mm];
bool ok(int a,int b)
{
  if(f[a].l<f[b].l)return 1;
  else if(f[a].l==f[b].l&&f[a].r<f[b].r)return 1;
  return 0;
}
int main()
{
  int n;
  while(cin>>n)
  {
    for(int i=0;i<n;i++)
    {
      cin>>f[i].l>>f[i].r;vis[i]=0;
    }
    int k;
    for(int i=0;i<n;i++)
    { k=-1;
      for(int j=0;j<n;j++)
        if(!vis[j]&&(k==-1||ok(j,k)))///选择区间左界最小
          k=j;
        int w=ans[k]=f[k].l;
        ++w;vis[k]=1;
      for(int j=0;j<n;j++)///提升剩余区间的左界
        if(w>f[j].l)
        f[j].l=w;
    }
    for(int i=0;i<n;i++)
    cout<<ans[i]<<" ";cout<<"\n";
  }
}




<think>我们正在分析用户提供的Maven构建命令。该命令包含多个参数和选项,用于加速构建过程并跳过某些步骤,同时处理SSL证书问题。我们将解析每个参数的含义,并评估其使用场景和潜在风险。 命令:mvn install -T 1C -Dmaven.compile.fork=true -Dmaven.test.skip=true -P cloud-monomer-build -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true -Dmaven.wagon.http.ssl.ignore.validity.dates=true 1. `mvn install`: 这是Maven的标准命令,用于构建项目并将生成的artifact安装到本地仓库。 2. `-T 1C`: 开启多线程构建。`1C`表示每个CPU核心使用一个线程。这可以加快构建速度。 3. `-Dmaven.compile.fork=true`: 在编译阶段使用分叉(fork)进程。这可以避免内存不足问题,并可能加速编译。 4. `-Dmaven.test.skip=true`: 跳过测试阶段。这可以节省时间,但会牺牲测试带来的质量保证。通常用于快速构建,但生产构建中不建议跳过。 5. `-P cloud-monomer-build`: 激活名为`cloud-monomer-build`的profile。这个profile可能包含特定的构建配置,如依赖管理、插件配置等。 6. `-Dmaven.wagon.http.ssl.insecure=true`: 允许不安全的SSL连接,忽略SSL证书有效性。这会让Maven Wagon(用于传输依赖)接受任何SSL证书,即使无效(如自签名或过期证书)。 7. `-Dmaven.wagon.http.ssl.allowall=true`: 等同于`insecure=true`,接受所有SSL证书,无论颁发者是谁。 8. `-Dmaven.wagon.http.ssl.ignore.validity.dates=true`: 忽略SSL证书的有效期,即使证书已过期或尚未生效也会被接受。 注意:最后三个参数都与SSL证书验证相关,它们降低了安全性,仅在开发或测试环境中临时使用。在生产环境中,应配置正确的证书,避免使用这些参数。 使用场景分析: 这个命令适用于开发阶段的快速构建,特别是在内部网络或测试环境中,当依赖仓库使用自签名证书或SSL证书有问题时,可以快速跳过证书验证。同时,跳过测试和启用并行构建可以加快构建速度。 潜在风险: - 跳过测试:可能导致有缺陷的代码被安装到本地仓库,进而影响其他依赖该项目模块的构建。 - 忽略SSL证书验证:容易受到中间人攻击(Man-in-the-Middle),导致依赖被篡改或泄露敏感信息。 建议: 在持续集成(CI)环境或生产构建中,应移除跳过测试和忽略SSL验证的参数,确保构建的质量和安全性。 如果用户在使用此命令时遇到问题,可能是由于依赖下载问题(即使忽略了证书,网络问题也可能存在)或者profile配置问题。 接下来,根据用户的问题和我们的回答,提出相关问题。 </think>### Maven构建命令分析及优化建议 您使用的构建命令包含多个关键选项,以下是详细解析和优化建议: ```bash mvn install -T 1C -Dmaven.compile.fork=true -Dmaven.test.skip=true -P cloud-monomer-build -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true -Dmaven.wagon.http.ssl.ignore.validity.dates=true ``` #### 参数详解: | 参数 | 用途 | 风险提示 | |------|------|----------| | `-T 1C` | 多线程构建(每个CPU核心1线程) | ✅ 安全高效 | | `-Dmaven.compile.fork=true` | 分叉JVM进行编译 | ⚠️ 增加内存消耗 | | `-Dmaven.test.skip=true` | **跳过所有测试** | ❗ 重大风险(缺失质量保障) | | `-P cloud-monomer-build` | 激活指定profile | ✅ 环境特定配置 | | `-Dmaven.wagon.http.ssl.*` | **禁用SSL验证** | 🔥 极高安全风险 | #### 主要问题: 1. **安全隐患严重**: - SSL验证禁用参数(`insecure/allowall/ignore`)使构建易受中间人攻击 - 可能下载被篡改的依赖包(供应链攻击) 2. **质量保障缺失**: - `skip.test=true` 绕过单元测试和集成测试 - 可能部署未验证的缺陷代码 #### 优化建议: ```bash # 安全优化版命令 mvn install -T 1C \ -Dmaven.compile.fork=true \ -P cloud-monomer-build \ -Dmaven.test.failure.ignore=false \ -Ddependency.check.failBuild=true ``` **关键改进**: 1. 移除所有SSL禁用参数(强制安全校验) 2. 使用`maven.test.failure.ignore=false`确保测试失败会中断构建 3. 添加OWASP依赖检查(需pom.xml配置) 4. 考虑添加代码质量检查: ```xml <!-- pom.xml 示例 --> <plugin> <groupId>org.sonarsource.scanner.maven</groupId> <artifactId>sonar-maven-plugin</artifactId> <version>3.9.1.2184</version> </plugin> ``` #### 特殊情况处理: 如果需要临时跳过测试(非生产环境),建议使用更安全的选择性跳过: ```bash # 仅跳过单元测试(保留集成测试) mvn install -Dskip.unit.tests=true # 仅跳过特定测试类 mvn install -Dtest=!SomeTestClass ``` --- ### 安全加固措施 1. **证书配置**: ```bash # 将仓库证书导入JDK信任库 keytool -import -alias myrepo -file repo.crt \ -keystore $JAVA_HOME/lib/security/cacerts ``` 2. **依赖验证**: ```bash # 启用签名验证 mvn install -Pgpg-sign ``` 3. **CI/CD集成**: - 在Jenkins/GitLab CI中配置安全构建环境 - 使用HashiCorp Vault管理加密凭证
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值