第二天:Codeforces Round 867 (Div. 3)(补题)

文章包含三个不同的算法问题解决方案。第一个问题是帮助Mushroom在给定时间内选择TubeTube上最有趣的视频。第二个问题是在数组中寻找最大乘积,通过比较最大和最小值的组合解决。第三个问题是关于计算肉桂卷的巧克力涂层,通过分析规律得出答案。所有问题都涉及到数组操作和优化时间复杂度的策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

 题意:

Mushroom Filippov 用自己做的饭菜吃午饭,决定在吃饭的时候看 TubeTube 上的视频。他不能花费超过 t 秒的时间吃饭,所以他请求你帮助他选择一个视频。

TubeTube 的信息流是由 n 个视频组成的列表,编号从 1 到 n。第 i 个视频持续 ai​ 秒,并具有娱乐价值 bi​。初始情况下,信息流是打开在第一个视频上的,Mushroom 可以在 1 秒内跳到下一个视频(如果存在下一个视频)。Mushroom 可以跳过任意数量的视频(包括零)。

帮助 Mushroom 选择一个视频,在 t 秒内观看。如果存在多个这样的视频,则他想选择最有趣的一个。输出任何适当视频的索引,或者如果没有这样的视频,则输出 -1。

值得注意的是:在一秒内可以跳到下一个视频!!!

考试时以为是dp想复杂了,没a过哭死

#include <iostream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#define IOS() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define int long long
#define fir(v) (v).first
#define se(v) (v).second
#define pb(x) push_back(x)
#define pii pair<int,int>
#define all(a) (a).begin(),(a).end()
#define mp(a,b) make_pair(a,b)
using namespace std;
const int N=1000000;
int a[N],b[N];
bool cmp(int x,int y)
{
	return x>y;
}

signed main()
{
	   IOS();
	   int q;
	   cin>>q;
	   while(q--){
	   	int n,t;
	   	cin>>n>>t;
	   	for(int i =1;i<=n;i++){
	   		cin>>a[i];
	   		a[i]+=i-1;//翻一个视频就要加一分钟 
		   }
		for(int i =1;i<=n;i++){
	   		cin>>b[i];
		   }
		 int flag=0;//是否找到答案
		 int idx=0;//下标记录 
		 int value=0;//娱乐值 
		 for(int i=1;i<=n;i++){
		 	if(a[i]<=t){//如果时间来得及 
		 		if(b[i]>value){
		 			value=b[i];
		 			flag=1;
		 			idx=i;
				 } 
			 }
		 } 
		 if(flag)cout<<idx<<endl;
		 else cout<<-1<<endl;
	   }

}

题意:找出数组中相乘最大的值

思路直接找最大的两个值和最小的两个值比较即可

#include <iostream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#define IOS() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define int long long
#define fir(v) (v).first
#define se(v) (v).second
#define pb(x) push_back(x)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define pii pair<int,int>
#define all(a) (a).begin(),(a).end()
#define mp(a,b) make_pair(a,b)
using namespace std;
const int N=1000000;
int a[N];
bool cmp(int x,int y)
{
	return x>y;
}

signed main()
{
	   IOS();
	   int t ;
	   cin>>t;
	   while(t--){
	   	int n;
	   	cin>>n;
	   	for(int i=1;i<=n;i++){
	   		cin>>a[i];
		   }
		sort(a+1,a+1+n);
		int temp=a[1]*a[2];
		int res=a[n]*a[n-1];
		if(temp>res) cout<<temp<<endl;
		else cout<<res<<endl;
	   }

}

 

 题意:算出肉桂卷有多少巧克力涂层

思路:找规律,分成最外层的,里面最长的一条,剩下的就是等差数列的两倍

#include <iostream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#define IOS() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define int long long
#define fir(v) (v).first
#define se(v) (v).second
#define pb(x) push_back(x)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define pii pair<int,int>
#define all(a) (a).begin(),(a).end()
#define mp(a,b) make_pair(a,b)
using namespace std;
const int N=1000000;
int a[N];
bool cmp(int x,int y)
{
	return x>y;
}

signed main()
{
	   IOS();
	   int t ;
	   cin>>t;
	   while(t--){
	   	int n;
	   	cin>>n;
	   	int sum=0;
	   	sum+=n*4;
	   	int temp=(1+n-2)*(n-2);
	   	sum+=temp;
		sum+=n;
		cout<<sum<<endl;
	   }

}

 题意:排列数组a是从1~n每个只出现一次的数组,如果b数组是a的前缀和+1%n,则称b数组是超排列数组。如果存在a序列则输出任意一个a序列,否则就输出-1

思路:首先考虑一个长度为 n 的排列,将前 i 个数的和对 n 取模得到的值记为 b[i],则 b 数组的值一定是从 0 到 n-1 的每个整数都恰好出现一次。因此,如果一个排列 a 是一个长度为 n 的超级排列,那么对于它的 b 数组,b[1], b[2], ..., b[n] 这 n 个数应该是一个长度为 n 的排列。

所以观察发现,

1.当 n 为奇数的时候,因为 b 数组中有奇数个偶数和奇数个奇数,所以无法构造一种排列使得 b 数组中所有数都恰好出现一次,因此不存在超级排列;

2.当 n=1 的时候,任意一个值都可以是超级排列;

3.对于长度为 n 的排列,其 b 数组的第一个数字一定为 0,最后一个数字一定为 n-1;

4.当 n 为偶数的时候,根据样例,发现就是从0~n-1构造,当i是奇数就输出n-i,i是偶数时就输出i,i为0时就输出n

#include <iostream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#define IOS() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define int long long
#define fir(v) (v).first
#define se(v) (v).second
#define pb(x) push_back(x)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define pii pair<int,int>
#define all(a) (a).begin(),(a).end()
#define mp(a,b) make_pair(a,b)
using namespace std;
const int N=1000000;
int a[N];
bool cmp(int x,int y)
{
	return x>y;
}

signed main()
{
	   IOS();
	   int t;
	   cin>>t;
	   while(t--){
	   	int n;
	   	cin>>n;
	   	if(n==1) cout<<1<<endl;
	   	else if(n%2==1)cout<<-1<<endl;
	   	else{
	   		for(int i=0;i<n;i++){
	   			if(i%2==1)cout<<n-i<<" ";
				   else if(i==0)cout<<n<<" ";
				   else cout<<i<<" ";	
			   }
			   cout<<endl;
		   }
	   }
	   

}

### Codeforces Round 927 Div. 3 比赛详情 Codeforces是一个面向全球程序员的比赛平台,定期举办不同级别的编程竞赛。Div. 3系列比赛专为评级较低的选手设计,旨在提供更简单的问题让新手能够参与并提升技能[^1]。 #### 参赛规则概述 这类赛事通常允许单人参加,在规定时间内解决尽可能多的问题来获得分数。评分机制基于解决问题的速度以及提交答案的成功率。比赛中可能会有预测试案例用于即时反馈,而最终得分取决于系统测试的结果。此外,还存在反作弊措施以确保公平竞争环境。 ### 题目解析:Moving Platforms (G) 在这道题中,给定一系列移动平台的位置和速度向量,询问某时刻这些平台是否会形成一条连续路径使得可以从最左端到达最右端。此问题涉及到几何学中的线段交集判断和平面直角坐标系内的相对运动分析。 为了处理这个问题,可以采用如下方法: - **输入数据结构化**:读取所有平台的数据,并将其存储在一个合适的数据结构里以便后续操作。 - **时间轴离散化**:考虑到浮点数精度误差可能导致计算错误,应该把整个过程划分成若干个小的时间间隔来进行模拟仿真。 - **碰撞检测算法实现**:编写函数用来判定任意两个矩形之间是否存在重叠区域;当发现新的连接关系时更新可达性矩阵。 - **连通分量查找技术应用**:利用图论知识快速求解当前状态下哪些节点属于同一个集合内——即能否通过其他成员间接相连。 最后输出结果前记得考虑边界条件! ```cpp // 假设已经定义好了必要的类和辅助功能... bool canReachEnd(vector<Platform>& platforms, double endTime){ // 初始化工作... for(double currentTime = startTime; currentTime <= endTime ;currentTime += deltaT){ updatePositions(platforms, currentTime); buildAdjacencyMatrix(platforms); if(isConnected(startNode,endNode)){ return true; } } return false; } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值