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,终于 ...
随机推荐
- auctex 11.86的墓志铭
卸载了emacs23,在Ubuntu 软件中心搜索并安装了emacs24.3.把auctex11.86也卸载了(自然,在.emacs文件里也注释掉了它的加载路径,但是我不会删去那段代码的.让注释的那段 ...
- shell_常规小脚本
shell 1.检查Mysql的健康状态 #!/bin/bashpgrep -x mysqld &> /dev/nullif [ $? -ne 0 ]thenecho “At time: ...
- Okhttp教程 (1)
1. 在build.gradle里引入okhttp库 dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testComp ...
- ZOJ-1610 Count the Colors(线段树染色,求染色段)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1610 https://vjudge.net/contest/318019# ...
- AdminWebSessionManager AdminAuthorizingRealm ShiroConfig ShiroExceptionHandler
package org.linlinjava.litemall.admin.shiro; import com.alibaba.druid.util.StringUtils; import org.a ...
- 非IoC方式访问Servlet API的两种方法
使用ActionContext访问 ActionContext来自com.opensymphony.xwork2.ActionContext 具体实现代码段如下: <span style=&qu ...
- UML Learning
在建筑业中,建模是一项经过检验并被广泛接受的工程技术,建立房屋和大厦的建筑模型,能帮助用户得到实际建筑物的印象.在软件建模中也具有同样的作用,建模提供了系统的蓝图. 建模是为了能够更好地理解正在开发的 ...
- [LC] 144. Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values. Example: Input: [1,null,2,3 ...
- [LC] 129. Sum Root to Leaf Numbers
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number ...
- whatsoever|
ADV (用于名词词组后,强调否定陈述)丝毫,任何,无论什么You use whatsoever after a noun group in order to emphasize a negative ...