CF 1305E. Kuroni and the Score Distribution
题目大意:题目给定两个数n和m(1<=n<=5000,0<=m<=1e9)要求构造一个数列A,A中元素
- 大于等于1,小于等于1e9且满足严格递增
- 满足ai+aj=ak的(i,j,k)恰好有m个
如果有没有这样的A输出-1。
分析:如果ai和aj确定,那么ak唯一。也可以说任意两个可以决定第三个。
首先可以猜想当A为1到n的连续自然数时这样的三元组最大。(容易用数学归纳法证明。利用下面红字得到的结论,一个一个加。em。。。)
假如前s个数已经确定为1到s的自然数按顺序的排列,当增加第s+1个数时,满足条件的(x,y,s+1)的个数就是满足as+1-y=x<y的y的个数(已知a1到as就是1到s的自然数,所以ax=x,ay=y),即满足 as+1<2*y 的y的个数。由此可以确定as+1对三元组个数的影响
同时也能得到这样的结论:
用数列Sn表示从1到n 的n个自然数按顺序排列而成的数列可以找到所有满足条件的三元组的数量。那么有:Sn+1-Sn=n/2(向下取整)。
可以先用1,2,3。。。来填充数组,超过时按上面红色的规则添加下一个数。
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAX_N=+;
int n,m;
LL a[MAX_N];
int main()
{
int tmp=1e9;
scanf("%d%d",&n,&m);
if(m==){
for(int i=n;i>=;i--) a[i]=tmp,tmp-=;
for(int i=;i<=n;i++) printf("%d ",a[i]);
}
else{
int i;
for(i=;i<=n;i++){
if(m>=(i-)/) a[i]=i,m-=(i-)/;
else break;
}
if(i>n&&m){printf("-1\n");}
else{
int cur;
for(cur=;;cur++) if(a[cur]==) break;
if(m==){
for(int j=n;j>=cur;j--)a[j]=tmp,tmp-=a[cur-]+;
}
else {
a[cur]=a[cur-m]+a[cur-m-];
for(int j=n;j>cur;j--)a[j]=tmp,tmp-=a[cur]+;
}
for(int i=;i<=n;i++) printf("%d ",a[i]);
}
}
}
欢迎转载和引用
CF 1305E. Kuroni and the Score Distribution的更多相关文章
- cf 1305 E. Kuroni and the Score Distribution
题目传送门:E. Kuroni and the Score Distribution 题目大意:给n和m,输出n个数,这些数里必须要有m对a[i]+a[j]==a[k] ( i < j < ...
- Codeforces 杂题集 2.0
记录一些没有写在其他随笔中的 Codeforces 杂题, 以 Problemset 题号排序 1326D2 - Prefix-Suffix Palindrome (Hard version) ...
- Linux command line exercises for NGS data processing
by Umer Zeeshan Ijaz The purpose of this tutorial is to introduce students to the frequently used to ...
- Scoring and Modeling—— Underwriting and Loan Approval Process
https://www.fdic.gov/regulations/examinations/credit_card/ch8.html Types of Scoring FICO Scores V ...
- 2016CVPR论文集
http://www.cv-foundation.org/openaccess/CVPR2016.py ORAL SESSION Image Captioning and Question Answe ...
- win7下使用Taste实现协同过滤算法
如果要实现Taste算法,必备的条件是: 1) JDK,使用1.6版本.需要说明一下,因为要基于Eclipse构建,所以在设置path的值之前要先定义JAVA_HOME变量. 2) Maven,使用2 ...
- CVPR2016 Paper list
CVPR2016 Paper list ORAL SESSIONImage Captioning and Question Answering Monday, June 27th, 9:00AM - ...
- ProbS CF matlab源代码(二分系统)(原创作品,转载注明出处,谢谢!)
%ProbS clear all;%% 数据读入与预处理 data = load('E:\network_papers\u1.base');test = load('E:\network_papers ...
- CF Round#240题解
第一次参加CF的比赛,MSK19.30,四个小时的时差真心累,第一次CODE到这么夜-- 一开始做了A,C两题,后来做B题的时候我体力和精神集中度就很低了,导致一直WA在4-- 今天起床后再刷B,终于 ...
随机推荐
- Python 语言基础
Python 语言基础 Python 开发环境 计算机组成 编程语言(计算机语言)是人们为了控制计算机,而设计的一种符号和文字的组合,从而实现向计算机发出指令. 形式是符号和文字的组合 目的是为了控制 ...
- 基础篇三:Nginx介绍
Nginx是一个开源,高性能,可高的http中间件,代理服务 常见的中间件服务: httpd apache基金会的产品 IIS 微软的产品 gws google的产品 选择Ng ...
- [LC] 146. LRU Cache
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the fol ...
- J. Stone game(背包问题)
题:https://nanti.jisuanke.com/t/41420 定义 dp[x][y] 表示第 x 个数到最后一个数能组成和为 y 的方案数 #include<bits/stdc++. ...
- 2018-1 WebStorm最新版本破解激活方法
在激活页面选择License Server,输入:http://idea.codebeta.cn,点击Activate即可激活. 如果失效用这个: http://idea.ibdyr.com
- Object.prototype.toString.call(obj).slice(8,-1)
1.Object.prototype.toString() 该方法返回描述某个对象数据类型的字符串,如自定义的对象没有被覆盖,则会返回“[object type]”,其中,type则是实际的对象类型. ...
- 总结oracle18.3c-centos7-安装
官网下载对应名字rpm包 oracle-database-ee-18c-1.0-1.x86_64.rpm下载依赖包 除非已有依赖 否则会报缺少依赖错误 1 curl -o oracle-databas ...
- Codeforces Round #200 (Div. 1)D. Water Tree
简单的树链剖分+线段树 #include<bits\stdc++.h> using namespace std; #define pb push_back #define lson roo ...
- django框架基础-ORM跨表操作-长期维护
############### 一对一跨表查询 ################ import os if __name__ == '__main__': os.environ.setde ...
- C# 怎样判断 datagridview 中的checkbox列是否被选中
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e){ for (int i ...