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,终于 ...
随机推荐
- 安卓ButtomBar实现方法
这里ButtomBar有3个items,分别有icon和文字,在当前fragment时,所属的icon和文字会显示不同颜色. 1. 首先要准好ICON素材,命名规范要清楚. 2. 实现这个Buttom ...
- iOS补位动画、沙漏效果、移动UITableViewCell、模拟贪吃蛇、拖拽进度等源码
iOS精选源码 JHAlertView - 一款黑白配色的HUD之沙漏效果 继承UIButton的自定义按钮SPButton 用递归算法实现iOS补位动画 iOS 长按移动UITableViewCel ...
- mysql,主键与索引的区别和联系
关系数据库依赖于主键,它是数据库物理模式的基石.主键在物理层面上只有两个用途: 惟一地标识一行. 作为一个可以被外键有效引用的对象. 索引是一种特殊的文件(InnoDB数据表上的索引是表空间的一个组成 ...
- 查询Redis缓存
package me.zhengjie.monitor.rest; import me.zhengjie.common.aop.log.Log; import me.zhengjie.monitor. ...
- E. Alice and the Unfair Game(推导线段树)
题:https://codeforces.com/contest/1236/problem/E 粗自:https://www.cnblogs.com/YSFAC/p/11715522.html #in ...
- as such 位于句首
- SwipeRefreshLayout 下拉刷新
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com ...
- 《C程序设计语言》练习 1-6,1-7
#include<stdio.h> /*验证表达式getchar()!=EOF的值是0还是1*/ main () { int c; c=getchar()!=EOF; printf(&qu ...
- 在python的web框架Django中使用SQL Server
在pycharm中安装 安装pyodbc和Django——pyodbc是一个用python写的ODBC引擎 安装Django-pyodbc-azure 在后方网址中查 ...
- By virtue of|sustain|post |scrape off |stretch|access to|take into account of|exploit|hasten|blur |idle|bored her to|account for|accused of|cruelty
By virtue of this superior quality, this product is often sold out of stockin many areas. 我们的产品因其优秀的 ...