当前位置:网站首页>E - Lucky Numbers
E - Lucky Numbers
2022-06-13 04:37:00 【想吃蛋黄肉粽】
传送门:
题意:给你一个长为n-1的序列s,还有一个长为m的x序列,他们被称为幸运数字。
定义一个长为n的序列a满足下列条件那么这是一个好序列:
a[i]+a[i+1]=s[i]
构造一个好序列使得序列中有最多的数字是幸运数字。
分析:m<=10,考虑枚举,把每个a[i]=x[j]。容易发现确定a序列的一个值就能确定a序列,也就是可以说a序列的特征值是a[1]。假设最优解的序列是a[1],a[2],s[3]...,那么当且仅当a[i]=a[i]的时候这个序列出现一次,至此,可以将问题转化为 求出现最多的序列的次数。用map和特征值求解即可。
代码:
#include<bits/stdc++.h>
using namespace std;
#define int long long
int sum[100005];
int ss[100005];
int x[15];
map<int,int>mp;
signed main()
{
int n,m;
cin>>n>>m;
for(int i=1;i<=n-1;i++)
{
cin>>sum[i];
}
for(int i=2;i<=n;i++)
{
ss[i]=sum[i-1]-ss[i-1];
}
for(int i=1;i<=m;i++)
{
cin>>x[i];
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
int now=x[j];
int tmp;
if(i%2) tmp=now-ss[i];
else tmp=ss[i]-now;
mp[tmp]++;
}
}
int maxx=0;
for(auto it:mp)
{
maxx=max(maxx,it.second);
}
cout<<maxx<<endl;
}
边栏推荐
- 力扣刷题338.比特位计数
- 【Flutter 问题系列第 67 篇】在 Flutter 中使用 Get 插件在 Dialog 弹窗中不能二次跳转路由问题的解决方案
- Recommended temporary online image compression tool
- Catalan number
- Reread the classic: end to end object detection with transformers
- [sword finger offer] interview question 25 Merge two ordered linked lists
- 2022氯化工艺操作证考试题库及模拟考试
- Applet waterfall flow
- Redis data persistence
- Vercel 使用 HTTP 缓存
猜你喜欢

【Try to Hack】upload-labs通关(暂时写到12关)
![C#获取WebService接口的所有可调用方法[WebMethod]](/img/44/4429b78c5b8341ed9a4a08d75a683e.png)
C#获取WebService接口的所有可调用方法[WebMethod]
![[automated test] what you need to know about unittest](/img/7c/b3c50dd9808e4b4a44ef4250604cd0.png)
[automated test] what you need to know about unittest

2022 ICLR | CONTRASTIVE LEARNING OF IMAGE- AND STRUCTURE BASED REPRESENTATIONS IN DRUG DISCOVERY

Analyse du principe de mise en œuvre d'un éditeur de texte open source markdown - to - rich

Ultra quicksort reverse sequence pair

正态分布(高斯分布)

Powershell 加域 Add-Computer模块

Redis主从复制、哨兵模式、集群

Google Chrome browser reports an error: net:: err_ BLOCKED_ BY_ CLIENT
随机推荐
Small program input element moving up
【Flutter 问题系列第 67 篇】在 Flutter 中使用 Get 插件在 Dialog 弹窗中不能二次跳转路由问题的解决方案
Simple static web page + animation (small case)
Common ways to traverse map sets
Explanation of line segment tree
2022年氧化工艺操作证考试题库及模拟考试
H5 the blue background color appears when clicking the picture
The could not find com scwang. smart:refresh-layout-kernel:2.0.3. Required by: project: the app cannot load the third-party package
Swiper plug-in
SEO specification
Analyse du principe de mise en œuvre d'un éditeur de texte open source markdown - to - rich
2022 ICML | Pocket2Mol: Efficient Molecular Sampling Based on 3D Protein Pockets
[sword finger offer] interview question 25 Merge two ordered linked lists
Sword finger offer 56 - I. number of occurrences in the array
Recommended temporary online image compression tool
Day45. data analysis practice (1): supermarket operation data analysis
Li Kou brush question 647 Palindrome substring
力扣刷题647.回文子串
Crawler scrapy framework learning 1
在线音频调节技术汇总