C. Doremy‘s IQ(二分/思维)

题目链接
在这里插入图片描述
在这里插入图片描述
题目大意:
哆来咪要参加比赛,每场比赛有一个智商值 a i ai ai,且只能发生在第 i i i天,哆来咪可以选择参加比赛或者不参加比赛。
哆来咪不是傻子,他也有一个智商值,如果比赛的智商严格高于他的智商值,并且哆来咪参加了比赛,那他的智商值就会减一,不参加或参加智商值低于等于他智商值的比赛则没有影响,问哆来咪尽可能多的参加比赛的策略。
思路一:
显然,对于降智比赛,如果我们前面参加的多了那么后面的正常比赛也会变为降智比赛。所以我们的最优策略应该是当最后一天时,我们的智商值恰好为1。(参加完这天的降智比赛即为0)
所以我们,可以翻转数组,倒着模拟这种情况,从智商值为0开始,如果遇到比当前智商值大的比赛,就参加,并且智商值加一,当智商值等于 Q Q Q时我们便不再参加。

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 1e6 + 10;
const double pi = 3.14159265358979323846;
typedef pair<ll, ll> pii;
ll a[N];
ll ans[N];
int main() {
	int t;
	cin >> t;
	while (t--)
	{
		ll n, p;
		cin >> n >> p;
		for (int i = 1; i <= n; i++) {
			cin >> a[i];
		}
		ll iq = 0;
		for (int i = n; i >= 1; i--) {
			if (a[i] <= iq)ans[i] = 1;
			else if (iq < p)iq++, ans[i] = 1;
		}
		for (int i = 1; i <= n; i++) {
			cout << ans[i];
			ans[i] = 0;
		}
		cout << endl;
	}
}

思路二:
由于天数是递增的,也就是说我们只能随着天数,参加后面的比赛不能反过来参加前面的比赛,因此我们也可以用二分的方法来解决。
首先,我们称会降低智商的比赛为坏比赛, 其余的比赛称为好比赛.
最优策略中存在一个下标 x x x使得在区间 [ 1 , x ) [1,x) [1,x)内的比赛都打了, [ x , n ] [x,n] [x,n]内的坏比赛都打了
证明如下
对每个策略,设 a a a为最后一场没打的比赛, b b b为第一场打的坏比赛.

①若 b < a b < a b<a 则可不打 b b b ,改打 a a a这样打的比赛数不变.

②若 b > a b > a b>a ,则 x = b x = b x=b即满足.
因此可以用二分来解决。

#include<bits/stdc++.h>
using namespace std;

typedef int ll;
const int N = 1e6 + 10;
const double pi = 3.14159265358979323846;
typedef pair<ll, ll> pii;
ll a[N];
ll ans[N];
ll n, p;

bool check(ll x) {
	for (int i = 1; i <= n; i++)ans[i] = 0;
	ll q = p;
	for (int i = 1; i <= n; i++) {
		if(i < x)
		if (a[i] <= q)ans[i] = 1;
		if (i >= x) {
			ans[i] = 1;
			if (!q)return false;
			if (a[i] > q)q--;
			
		}
	}
	return q >= 0;
}
int main() {
	int t;
	cin >> t;
	while (t--)
	{
		cin >> n >> p;
		for (int i = 1; i <= n; i++) {
			cin >> a[i];
		}
		ll l = 1, r = n,mid = l + r >> 1;
		while (l < r)
		{
			mid = l + r>> 1;
			if (check(mid))r = mid;
			else l = mid + 1;
		}
		check(l);
		for (int i = 1; i <= n; i++)
			cout << ans[i];
		cout << endl;
	}
}
按功能分类,标出各插件的作用<?xml version="1.0" encoding="UTF-8"?> <!-- Sonatype Nexus (TM) Open Source Version Copyright (c) 2008-present Sonatype, Inc. All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions. This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0, which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html. Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the Eclipse Foundation. All other trademarks are the property of their respective owners. --> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.sonatype.buildsupport</groupId> <artifactId>public-parent</artifactId> <version>51</version> <relativePath/> </parent> <groupId>org.sonatype.nexus</groupId> <artifactId>nexus-parent</artifactId> <name>${project.groupId}:${project.artifactId}</name> <packaging>pom</packaging> <version>3.78.0-14</version> <inceptionYear>2008</inceptionYear> <url>http://nexus.sonatype.org/</url> <licenses> <license> <name>Eclipse Public License</name> <url>http://www.eclipse.org/legal/epl-v10.html</url> </license> </licenses> <issueManagement> <system>Jira</system> <url>http://issues.sonatype.org/browse/NEXUS</url> </issueManagement> <scm> <connection>scm:git:git://github.com/sonatype/nexus-public.git</connection> <developerConnection>scm:git:git@github.com:sonatype/nexus-public.git</developerConnection> <u
最新发布
03-17
<think>好的,我现在需要帮助用户了解Nexus项目中各插件的功能分类、作用以及如何在pom.xml中配置示例。首先,我需要回忆一下关于Maven插件和Nexus的相关知识。 用户提到了Nexus项目,可能是指使用Sonatype Nexus Repository Manager来管理项目的依赖和构建产物。Nexus通常作为Maven仓库使用,所以在Maven项目中的pom.xml会配置插件来与Nexus交互。用户想知道这些插件的功能分类和作用,以及配置示例。 首先,Maven插件在构建生命周期中执行特定任务,比如编译、打包、部署等。与Nexus相关的插件可能涉及依赖管理、部署到仓库、站点生成等。接下来需要将这些插件分类,比如仓库管理类、构建发布类、依赖分析类等。 我需要确认每个插件的具体功能和对应的配置示例。比如,maven-deploy-plugin用于部署构件到远程仓库,如Nexus;nexus-staging-maven-plugin用于处理分阶段发布;maven-site-plugin生成项目站点,可能包含项目信息;versions-maven-plugin管理依赖版本;dependency-check-maven检查安全漏洞;maven-release-plugin自动化版本发布。 接下来需要检查每个插件的groupId、artifactId是否正确,以及配置示例是否符合标准。比如,部署插件需要配置repository和snapshotRepository的URL,分阶段发布插件的配置可能需要服务器认证等。同时,要确保引用的资料正确,用户提供的引用[1]、[2]、[3]都是关于Spring Boot的pom.xml配置,可能与Nexus插件没有直接关联,但可能用户想结合一般Maven插件配置来理解,因此需要确保信息准确。 还需要注意分类是否合理,是否有遗漏的常用插件。例如,仓库管理类可能包括部署和分阶段发布插件,构建发布类包括release插件,依赖分析类包括dependency-check和versions插件。站点文档类则是site插件。每个分类下给出对应的插件作用,配置示例,并引用用户提供的资料中的相关部分,但用户提供的引用可能没有直接提到这些插件,所以可能需要调整引用标记,或者仅作为背景知识。 最后,生成相关问题,确保问题覆盖用户可能感兴趣的方面,比如插件协同工作、安全扫描、版本管理、自动化发布等。</think>### Nexus项目中插件的功能分类及配置示例 #### 一、仓库管理类插件 1. **Maven部署插件(maven-deploy-plugin)** **作用**:将构建生成的构件(如JAR/WAR)部署到Nexus仓库中,支持快照(SNAPSHOT)和正式版本的分发[^2]。 **配置示例**: ```xml <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-deploy-plugin</artifactId> <version>3.0.0</version> <configuration> <altDeploymentRepository> nexus::default::http://nexus-host:8081/repository/maven-releases/ </altDeploymentRepository> </configuration> </plugin> ``` 2. **Nexus分阶段发布插件(nexus-staging-maven-plugin)** **作用**:将构件分阶段上传至Nexus,支持人工审核后正式发布,常用于企业级发布流程[^1]。 **配置示例**: ```xml <plugin> <groupId>org.sonatype.plugins</groupId> <artifactId>nexus-staging-maven-plugin</artifactId> <version>1.6.13</version> <configuration> <serverId>nexus</serverId> <nexusUrl>http://nexus-host:8081/</nexusUrl> <autoReleaseAfterClose>false</autoReleaseAfterClose> </configuration> </plugin> ``` --- #### 二、构建与发布类插件 1. **Maven Release插件(maven-release-plugin)** **作用**:自动化版本号管理(如从`1.0-SNAPSHOT`升级到`1.0`),并触发部署到Nexus仓库[^3]。 **配置示例**: ```xml <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-release-plugin</artifactId> <version>3.0.0</version> <configuration> <tagNameFormat>v@{project.version}</tagNameFormat> <autoVersionSubmodules>true</autoVersionSubmodules> </configuration> </plugin> ``` --- #### 三、依赖分析类插件 1. **OWASP依赖检查插件(dependency-check-maven)** **作用**:扫描项目依赖的安全漏洞,结果可集成到Nexus IQ Server进行审计。 **配置示例**: ```xml <plugin> <groupId>org.owasp</groupId> <artifactId>dependency-check-maven</artifactId> <version>7.1.1</version> <configuration> <failBuildOnCVSS>8</failBuildOnCVSS> </configuration> </plugin> ``` 2. **版本管理插件(versions-maven-plugin)** **作用**:批量更新依赖版本号,确保与Nexus仓库中的最新版本同步。 **配置示例**: ```xml <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>versions-maven-plugin</artifactId> <version>2.10.0</version> </plugin> ``` --- #### 四、站点与文档类插件 1. **Maven Site插件(maven-site-plugin)** **作用**:生成项目文档站点并发布到Nexus的站点仓库。 **配置示例**: ```xml <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-site-plugin</artifactId> <version>3.12.1</version> <configuration> <reportPlugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-project-info-reports-plugin</artifactId> </plugin> </reportPlugins> </configuration> </plugin> ``` ---
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值