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 ...
随机推荐
- VC/MFC中通过CWebPage类调用javascript函数(给js函数传参,并取得返回值)
转自:http://www.cnblogs.com/javaexam2/archive/2012/07/14/2632959.html ①需要一个别人写好的类CWebPage,将其对于的两个文件Web ...
- Android实现“退出确认”对话框
@Override public void onBackPressed() { new AlertDialog.Builder(this).setTitle("确认退出吗?") . ...
- Windows下使用Gflags检查内存越界
环境:windows xp. vs2005 Gflags可用于查找内存越界的问题. 访问一块申请的内存时,当访问的地址超过申请的范围时,就发生了内存越界的问题. 编写测试程序MemoryOverflo ...
- 第十一课——codis-server的高可用,对比codis和redis cluster的优缺点
[作业描述] 1.配置codis-ha 2.总结对比codis的集群方式和redis的cluster集群的优缺点 =========================================== ...
- I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA 问题
临时解决版本进入python后只需下面命令 import os os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
- ifram+form方式实现文件、图片上传、预览
1.前端代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...
- 使用Nana进行C++ GUI开发
Nana官网地址:nanapro.org 简单示例:NanaDemo.cpp #include <nana/gui.hpp> #include <nana/gui/widgets/b ...
- mysql 约束条件 auto_increment 自动增长 创建表时设置自增字段
auto_increment mysql) )auto_increment; Query OK, rows affected (0.01 sec) mysql> show create tabl ...
- linux下dubbo调试 ---telnet命令
linux下启动dubbo服务端, 怎么调试? 方法有二: 1. 自己写简单消费者功能,进行各种情况测试.(这确实是有必要的) 2. 使用telnet直接连接上dubbo,使用命令调用,然后调试.(这 ...
- 安卓android的联系人的contacts, raw contacts, and data的区别
https://stackoverflow.com/questions/5151885/android-new-data-record-is-added-to-the-wrong-contact/51 ...