CF1157D N Problems During K Days(简单构造)
题目
原数据是水成啥样了,\(<\longrightarrow <=,>=\longrightarrow <=,\)这也能过 被\(hack\)后身败名裂
做法
简单的贪心吧
开始先填上\(1\)~\(k\),然后如果能全部\(+1\)就加:这样一定能为后面的构造创造出更多的可能(\(2\)倍的限制)
后面就找到能填的最小的位置反复填就行了
Code
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL maxn=1e6+9;
LL n,k;
LL a[maxn];
int main(){
cin>>n>>k;
LL ret(0);
for(LL i=1;i<=k;++i) a[i]=i,ret+=a[i];
if(ret>n){
puts("NO"); return 0;
}
LL tmp(n-ret);
if(tmp>=k){
LL lun(tmp/k);
for(LL i=1;i<=k;++i) a[i]+=lun;
ret+=lun*k;
}
LL up(0);
while(true){
tmp=n-ret;
if(!tmp) break;
LL now(std::max(k-tmp+1,up));
if(a[now-1]*2<a[now]+1){
LL f(0);
for(LL j=now+1;j<=k;++j){
if(a[j-1]*2>=a[j]+1){
f=j;
break;
}
}
if(!f){
puts("NO"); return 0;
}
up=f;
for(LL j=f;j<=k;++j) ++a[j];
ret+=k-f+1;
}else{
for(LL i=now;i<=k;++i) ++a[i];
ret+=k-now+1;
}
}
puts("YES");
for(LL i=1;i<=k;++i) cout<<a[i]<<' ';
return 0;
}
CF1157D N Problems During K Days(简单构造)的更多相关文章
- CF1157D N Problems During K Days
思路: 在1, 2, 3, ... , k的基础上贪心构造. 实现: #include <bits/stdc++.h> using namespace std; typedef long ...
- Codeforces Round #555 (Div. 3) D. N Problems During K Days 【数学思维】
一 题面 D. N Problems During K Days 二 分析 对于这题,刚开始我就是陷入了对公式的执着,企图用公式直接确定第一个数,然后试着去找序列.经过思考和手动模拟后发现是很难保证正 ...
- 问题 H: 小k的简单问题
问题 H: 小k的简单问题 时间限制: 1 Sec 内存限制: 128 MB提交: 107 解决: 57[提交] [状态] [命题人:jsu_admin] 题目描述 地图上有n个村庄,小k每个月需 ...
- 基于邻接表的长度为k的简单路径的求解
描述 一个连通图采用邻接表作为存储结构.设计一个算法,判断无向图中任意给定的两点是否存在一条长度为k的简单路径. 输入 多组数据,每组m+3数据行.第一行有两个数字n,m和k,代表有n个顶点,m条边和 ...
- Codeforces Gym 100187K K. Perpetuum Mobile 构造
K. Perpetuum Mobile Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/pro ...
- Codeforce Round #555 Div.3 D - N Problems During K Days
构造题 话说挺水的题..当时怎么就WA到自闭呢.. 先把每个位置按照最低要求填满,也就是相差1..然后从最后一位开始把剩下的数加上,直到不能加为止. #include <bits/stdc++. ...
- Yet Another Ball Problem CodeForces - 1118E (简单构造)
大意: 求构造n个pair, 每个pair满足 对于每k组, 让$b_i$为$[1,k]$, $g_i$循环右移就好了 int n, k, cnt; int main() { scanf(" ...
- CF1082D:Maximum Diameter Graph (简单构造)
Graph constructive problems are back! This time the graph you are asked to build should match the fo ...
- 字典集合Dictionary<K,V>和构造的应用==>>体检套餐项目
效果 首先,我们先来准备我们需要的类 1.检查项目类 using System; using System.Collections.Generic; using System.Linq; using ...
随机推荐
- JS图片加载时获取图片宽高信息
; var img = new Image(); img.src = node.find("img[class='img1_1']").attr("src"); ...
- poj_3159 最短路
题目大意 有N个孩子(N<=3000)分糖果.有M个关系(M<=150,000).每个关系形如:A B C 表示第B个学生比第A个学生多分到的糖果数目,不能超过C.求第N个学生最多比第1个 ...
- 【BZOJ2726】[SDOI2012]任务安排 斜率优化+cdq分治
[BZOJ2726][SDOI2012]任务安排 Description 机器上有N个需要处理的任务,它们构成了一个序列.这些任务被标号为1到N,因此序列的排列为1,2,3...N.这N个任务被分成若 ...
- 动态svg效果
import React from 'react'; import TweenOne from 'rc-tween-one'; import SvgDrawPlugin from 'rc-tween- ...
- Spring Security OAuth2 token权限隔离
由于项目OAuth2采用了多种模式,授权码模式为第三方系统接入,密码模式用于用户登录,Client模式用于服务间调用, 所有不同的模式下的token需要用 @PreAuthorize("h ...
- Xcode升级了6.3 出现的警告:Auto property synthesis will not synthesize property
1. Auto property synthesis will not synthesize property 'title'; it will be implemented by its supe ...
- 购物车-删除单行商品-HTMLTableElement.deleteRow()
wta 问题发源的代码: /*删除单行商品*/ function deleteRow(rowId){ var Index=document.getElementById(rowId).rowIndex ...
- 前端开发 - HTML - 总结
html head标签 title 显示网站的标题 meta 提供有关页面的原信息 link 链接css资源文件.网站图标 style 定义内部样式表 script 链接脚本js文件 body标签 块 ...
- Zookeeper简介及使用
一.Zookeeper简介 1.zookeeper简介 动物管理员 Apache ZooKeeper致力于开发和维护开源服务器,实现高度可靠的分布式协调. 2.什么是ZooKeeper? ZooKee ...
- MapReduce的核心编程思想
1.MapReduce的核心编程思想 2.yarn集群工作机制 3.maptask并行度与决定机制 4.maptask工作机制 5.MapReduce整体流程 6.shuffle机制 7.yarn架构