div2题目题解:I. Powers Of Two

用COMSOL计算复合材料板频散曲线:从建模到绘图全流程 导波在板结构中传播时,不同频率成分的速度不同,即频散现象。理解频散曲线是识别导波模态、确定相速度与群速度的基础,也是无损检测和结构健康监测中信号解读的关键。对于碳纤维增强复合材料等各向异性板,频散关系更加复杂,传统解析方法难以求解,数值仿真成为主流手段。通过COMSOL结合周期性边界条件与特征频率扫描,可以高效计算出复合材料板的频散曲线,进而绘制相速度和群速度随频率变化的图谱,为实验模态识别、换能器激励频率选择提供依据。本文以一个2毫米单向碳纤维板为例,详细介绍几何建模、材料参数设置、网格收敛验证、参数扫描 阅读详情

题目:
I. Powers Of Two
time limit per test4 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
A positive integer x is called a power of two if it can be represented as x=2y, where y is a non-negative integer. So, the powers of two are 1,2,4,8,16,….

You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two.

Input
The only line of the input contains two integers n and k (1≤n≤109, 1≤k≤2⋅105).

Output
If it is impossible to represent n as the sum of k powers of two, print NO.

Otherwise, print YES, and then print k positive integers b1,b2,…,bk such that each of bi is a power of two, and ∑i=1kbi=n. If there are multiple answers, you may print any of them.

Examples
inputCopy
9 4
outputCopy
YES
1 2 2 4
inputCopy
8 1
outputCopy
YES
8
inputCopy
5 1
outputCopy
NO
inputCopy
3 7
outputCopy
NO

题意:
给n,k让你用k个二次幂数表示n;
我们知道9用二次幂数表示就是1 8,样例要用4个二次幂数来表示9就是1 2 2 4:
算是一个半水不水的手速题目:
首先要判断:最少要多少个二次幂数来表示n,如果k小于这个最小值,那就很尴尬了,所以要有特判,至于做法:
首先要用二进制表示n:
我们举个例子:19就是10011;(16+2+1)
这个10011放数组存着,然后就是记录1的个数,这个个数就是我们要用的表示出来n要用的最少的二次幂数的个数:

int i=n;
	int num=2;
	int time;
	int num_1=0;
	for(time=0;i>0;time++)
	{
		if(i%num){num_1++;all[time]=1;i-=(num/2);}
		else all[time]=0;
		num*=2;
	}
	int point=time;//二进制的位数
	//input finished;
	int goal;
	if(k<num_1||k>n)printf("NO\n");
	

代码如上,可以看到是这样获取的;
然后就是做法,得到了19变成10011这个数组,我们怎么做下一步?
假设:k为4;

10011如果变成02011会不会等于原来?显然相等,2个8和1个16是相等的,如果需要k个数,但是我只有num_1个1,如何表示呢,只能从高位到低位一直化,相当于什么?大面额的钱给他敞开了来花;上代码:
完整代码:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <climits>
#include <queue>
#include <stack>
#include <map>
//鬼畜头文件
using namespace std;
#define INF 0x3f3f3f3f
#define ULL unsigned long long
#define LL long long
//鬼畜define
int n,k;
int all[40];
int main()
{
	scanf("%d %d",&n,&k);
	int i=n;
	int num=2;
	int time;
	int num_1=0;
	for(time=0;i>0;time++)
	{
		if(i%num){num_1++;all[time]=1;i-=(num/2);}
		else all[time]=0;
		num*=2;
	}
	int point=time;//二进制的位数
	//input finished;
	int goal;
	if(k<num_1||k>n)printf("NO\n");
	else
	{
		printf("YES\n");
		for(int time1=point-1;time1>=0;time1--)
		{
			int P=k-num_1;
			if(P==0){break;}
			if(all[time1]<=P)
			{
				num_1+=all[time1];
				all[time1-1]+=all[time1]*2;
				all[time1]=0;
				goal=time1;
			}
			else
			{
				num_1+=P;
				all[time1-1]+=P*2;
				all[time1]-=P;
				goal=time1;
			}
		}
		int num=1;
		for(int time=0;time<=goal;time++)
		{
			for(int time2=0;time2<all[time];time2++)
			{
				printf("%d ",num);
			}
			num*=2;
		}
		printf("\n");
	}
 
 
}
【AI大模型应用开发】【LlamaIndex教程】2. 存储模块:如何在 LlamaIndex 中使用自定义的向量数据库?(附代码) 前面文章两行代码就实现了文档的切分和向量化存储以及持久化存储。如果我们想用自定义的向量化数据库呢? 阅读详情

相关推荐

地平线RDKX3初始配置与USB无线网卡

地平线X3无线网卡配置

Richard_Mei的博客 4077

(笔记)LeetCode231 Power of Two题解

/** * 判断n是否是2的幂次方 * * 一、 * 1 是 2的0次幂 * 2 是 2的1次幂 * 4 是 2的2次幂 * 8 是 2的3次幂 * 16是 2的4次幂 * * 二、 * 2/2 商1 余0 * 4/2 商2 余0 * 8/2 商3 余0 * 16/2 商4 余..

u011046452的博客 455

LVGL8.x 实体按键与Keypad驱动的无缝对接实战

本文详细解析了LVGL8.x中实体按键与Keypad驱动的两种对接方案:坐标映射的Button方式与事件驱动的Keypad方式。重点阐述了如何模块化裁剪lv_port_indev.c模板文件,并深入讲解了Keypad驱动与Group焦点管理系统的核心协作机制,为无触摸屏的嵌入式设备提供流畅的UI交互解决方案。

weixin_29164497的博客 446

2020 GDUT Winter Personal Training Contest I (Div. 2) I - Powers Of Two 题解

原题 题目大意 给定一个整数n,要求用k个2的幂次方表示 题目分析 啊啊啊啊啊啊啊啊没来得及交啊 想知道一个数怎么拆成二进制的话上网查查快速幂就行,这个不难的 到了这道题的话,因为要凑够k个数,那么简单的分离是不足够的,不过我们可以先来两个剪枝 当分离出来的数(也就是指数二进制中1)的个数比k还多的时候,那就不能再用k个数去表示n了(见in3) 当全部数被分成了1还不小于k个数的时候,也不能凑...

juseice的博客 193

常见机械臂模型不用找!Mujoco这儿都有!

高质量的模型集合,franka panda,so-arm100,ur之类的机械臂都有。常见机械臂模型不用找!Mujoco这儿都有!大概346M,网速不行的可以下载zip。

darcsdn 992

【水文】calico-node 启动失败 Init:CrashLoopBackOff

Defaulted container "calico-node" out of: calico-node, upgrade-ipam (init), install-cni (init), mount-bpffs (init) Error from server (BadRequest): container "calico-node" in pod "calico-node-4j7td" is waiting to start: PodInitializing

大健的日常的博客 1万+

Codeforces 1095C. Powers Of Two(二进制拆分)

A positive integerxxis called apower of twoif it can be represented asx=2yx=2y, whereyyis a non-negative integer. So, thepowers of twoare1,2,4,8,16,…1,2,4,8,16,…. You are given two positive...

点点滴滴 388

【AI Agent 实战】OpenClaw 全面解析 + 全平台一键部署教程(本地 AI 智能体)

本文收录于 AI 智能体 & 自动化实战系列,手把手带你从零部署本地可控的 AI 执行助手关键词:OpenClaw、AI Agent、本地 AI 部署、自动化助手、Docker 部署

爱人爱己,风生水起 7877

div2 c题专项训练

对于构造的反例的第一位,使用k个字母中在s中第一次出现位置下标最大的那个一定是最优的。这个字母加入到反例中,将s的相应前缀删除,重复上述过程。如果最后构造出的反例长度大于等于n,那么输出YES;否则输出NO,一个没有出现的子串可以构造为当前构造出的反例加上若干个在剩下的s中没有出现的字母,将反例长度扩充为n输出即可。c题普遍不考察高深算法,而考察对问题的分析能力和简单的数学推导。发现k个字母能form的长度为n的串数量是非常多的,如果去检验每一个串是否在s中是否出现复杂度过大且代码不好实现。

2301_82345937的博客 491

Python 爬虫实战:网站反爬机制绕过终极指南(技术原理 + 实战代码 + 避坑技巧)

在 Python 爬虫的世界里,反爬机制是每一个爬虫开发者都必须面对的挑战。网站为了保护自身数据不被恶意爬取,会设置各种反爬机制,这使得爬虫开发变得更加复杂和有趣。本文将详细介绍常见的网站反爬机制及其绕过方法,结合技术原理、实战代码和避坑技巧,帮助你成为一名优秀的爬虫开发者。

u014481728的博客 1005

TC3XX - MCAL知识点(十一):WDG EB-tresos配置说明与代码浅析

在AUTOSAR中,看门狗栈实现了三种监控机制:实时监控:用于周期软件的定时监控期限监督:针对非周期软件逻辑监督:用于监督执行顺序的正确性看门狗(WDG)驱动实现AUTOSAR(4.2.2)中规定的看门狗SWS,提供初始化、改变操作模式和设置触发条件(超时)等服务,供看门狗硬件(WDT)用户使用。WDG驱动的用户包括:模式管理模块(用于初始化),WdgM通过Wdglf设置触发条件和驱动运行模式设置。WdgM实施上述监督机制。AUTOSAR扩展触发概念,以支持窗口看门狗模式。

梦想技术家 3601

Codeforces#640div4解题报告

Codeforces #640div4 A 原题 A positive (strictly greater than zero) integer is called round if it is of the form d00…0. In other words, a positive integer is round if all its digits except the leftmost (most significant) are equal to zero. In particular, all

Jeremy写字的地方 460

【控制模块算法】控制理论的进修之路

系列文章目录 提示:这里可以添加系列文章的所有文章的目录,目录需要自己手动添加 TODO:写完再整理 文章目录系列文章目录前言一、(经典)自动控制理论【本科阶段】二、现代控制理论【本科阶段】三、最优控制理论【硕士阶段】总结 前言 认知有限,望大家多多包涵,有什么问题也希望能够与大家多交流,共同成长! 本文先对对控制理论的理解做个简单的介绍,具体内容后续再更,其他模块可以参考去我其他文章 提示:以下是本篇文章正文内容 一、(经典)自动控制理论【本科阶段】 一般控制工程、自动化相关的考研专业课就是自动

qq_35635374的博客 1448

Codeforces Round #529 (Div. 3) C. Powers Of Two题解及思路

         time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Ivan wants to play a game with you. He picked some string ss of length nn consis...

qq_42426141的博客 291

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

Codeforces Round #486 (Div. 3) D. Points and Powers of Two

D. Points and Powers of Twotime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are nn distinct points on a coordinate line, the coordinate of ii...

qq_36603180的博客 264

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

Codeforces Round #529 (Div. 3) 题解

刷了一套题散散心,Div 3,全部是 1 A,感觉比以前慢了好多好多啊。 这几天也整理了一下自己要做的事情,工作上要努力... ... 晚上还是要认认真真背英语的。 找了几个同学问了一下,有点想自己做点 project 了,再学学机器学习,深度学习之类的,弄点小 AI project 玩玩吧... ...没事看点各种科技新闻开开眼界。 【题目链接】 A -Repeating ...

weixin_33720078的博客 185

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

Codeforces Round #529 (Div. 3) C. Powers Of Two(数学????)

传送门 题意:   给出一个整数 n ,问能否将 n 分解成 k 个数之和,且这 k 个数必须是2的幂。   如果可以,输出"YES",并打印出任意一组解,反之输出"NO"; 题解:   预备知识补充:   如何求出 num 最少需要多少个2的幂之和?   例如 :     num = 3 = 20+21至少需要两个     num = 4 = 22 至少需要一个    ...

weixin_30454481的博客 181

Codeforces Round #486 (Div. 3) D. Points and Powers of Two【贪心】

D. Points and Powers of Twotime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are nn distinct points on a coordinate line, the coordinate of ii...

哇-WA 的博客 265

Codeforces Round #486(Div. 2) D. Points and Powers of Two

传送门:点击打开链接题意:找最长的序列,使得该序列的任意两个值的差是2的倍数. 输出长度,并输出元素。分析:可以证明最长长度为三。对stl不熟啊,代码写的搓。学习了一下大佬的代码。我的代码:#include &lt;bits/stdc++.h&gt; using namespace std; int main() { #ifdef _DEBUG #endif int n; cin &gt;...

常胜将军的博客 207

Educational Codeforces Round 83 (Rated for Div. 2) A - C

A.Two Regular Polygons 题意:在一个凸的正多边形中,选择任意多顶点,能否再构造一个凸正多边形。 思路:水题,只要构造出来的正多边形的边数是原正多边形边数的因数即可。 Code: #include<bits/stdc++.h> using namespace std; int main(int argc,char *argv[]){ int t; i...

QiPianZuo的博客 1778

Codeforces Round #529 (Div. 3) ABCD题解

A. Repeating Cipher 简单思维题 题目大意:给你一个经过加密的字符串S,S = S1S2S3.....;而Si意味着这个字母他会书写i次;列如baabbb,这是加密后的样子加密前就是bab;题目需要你输出加密前的字符串; 思路:用一个中间变量t充当i,每解密一个字母后,就t++;然后我循环输出的s[i+=t],每次就输出加密后Si的最后一个字母。就是需要的答案了。 #i...

qq_42129242的博客 358

Codeforces 988D 题解

&lt;988D&gt;题意:给定若干个数,问在其中挑选几个数组成一个集合,使得集合中任意以两个数a, b(a &gt; b)的差值均为2^n。思路:这题要先找规律,这个规律就是,集合中的元素最多有3个,证明如下:假设集合内目前只有三个元素:x,y,z 且 x &lt; y &lt; z则根据题意,有如下关系:z - y = 2^a (1)y - x = 2^b (2)z - x = 2^c (3...

FrozenAllen的博客 577

Codeforces Round #529 -C- Powers Of Two(二进制拆分)

A positive integer xx is called a power of two if it can be represented as x=2yx=2y, where yy is a non-negative integer. So, the powers of two are 1,2,4,8,16,…1,2,4,8,16,…. You are given two positive...

black_hole6的博客 898

Codeforces 1095C. Powers Of Two——————multiset

C. Powers Of Two A positive integer x is called a power of two if it can be represented as x=2yx=2^yx=2y, where y is a non-negative integer. So, the powers of two are 1,2,4,8,16,…. You are given two p...

鸿杰 的博客 1166

div2题目题解:J. Circular Dance

题目: J. Circular Dance time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output There are n kids, numbered from 1 to n, dancing in a circle around the C...

DevourPower的博客 505

Codeforces529 -C Round #- Powers Of Two(二进制拆分)

A positive integerxxis called apower of twoif it can be represented asx=2^y , whereyyis a non-negative integer. So, thepowers of twoare1,2,4,8,16,…1,2,4,8,16,…. You are given two positive i...

qq_40293424的博客 259
上一篇: div2题目题解:J. Circular Dance
下一篇: GDUT_寒假训练题解报告_数论专题_个人题解报告——题目:D - Beautiful Numbers (CodeForces - 300C)【逆元、组合数公式】
DevourPower
博客等级 码龄7年 52粉丝 78原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值