当前位置: 首页 > news >正文

开一个做网站的公司网络营销七个步骤

开一个做网站的公司,网络营销七个步骤,长沙seo排名收费,正规的网站制作与推广CF1560D Make a Power of Two 题解题目链接字面描述题面翻译题目描述输入格式输出格式样例 #1样例输入 #1样例输出 #1提示思路代码实现备注题目 链接 https://www.luogu.com.cn/problem/CF1560D 字面描述 题面翻译 给定一个整数 nnn。每次操作你可以做两件事情中的一件&am…

CF1560D Make a Power of Two 题解

  • 题目
    • 链接
    • 字面描述
      • 题面翻译
      • 题目描述
      • 输入格式
      • 输出格式
      • 样例 #1
        • 样例输入 #1
        • 样例输出 #1
      • 提示
  • 思路
  • 代码实现
  • 备注

题目

链接

https://www.luogu.com.cn/problem/CF1560D

字面描述

题面翻译

给定一个整数 nnn。每次操作你可以做两件事情中的一件:

  • 删去这个数中的一个数位(如果这个数只剩下一位,则可以把它删空)。
  • 在这个数的右边添加一个数位。

你可以以任意顺序执行无限次操作。但请注意,在删去一个数位之后,这个数可能包含前导零(例如在删去 301301301 中的 333 这一位之后,这个数就会变成 010101 而不是 111)。

你需要执行若干次操作,使得这个数最终变成一个 222 的次幂,或者说存在一个非负整数 kkk 使得这个数最终是 2k2^k2k。最终答案不能包含前导零。请求出需要执行的操作的最小次数。

ttt 组数据,1⩽t⩽1041\leqslant t\leqslant 10^41t1041⩽n⩽1091\leqslant n\leqslant 10^91n109

题目描述

You are given an integer $ n $ . In $ 1 $ move, you can do one of the following actions:

  • erase any digit of the number (it’s acceptable that the number before the operation has exactly one digit and after the operation, it is “empty”);
  • add one digit to the right.

The actions may be performed in any order any number of times.

Note that if, after deleting some digit from a number, it will contain leading zeroes, they will not be deleted. E.g. if you delete from the number $ 301 $ the digit $ 3 $ , the result is the number $ 01 $ (not $ 1 $ ).

You need to perform the minimum number of actions to make the number any power of $ 2 $ (i.e. there’s an integer $ k $ ( $ k \ge 0 $ ) such that the resulting number is equal to $ 2^k $ ). The resulting number must not have leading zeroes.

E.g. consider $ n=1052 $ . The answer is equal to $ 2 $ . First, let’s add to the right one digit $ 4 $ (the result will be $ 10524 $ ). Then let’s erase the digit $ 5 $ , so the result will be $ 1024 $ which is a power of $ 2 $ .

E.g. consider $ n=8888 $ . The answer is equal to $ 3 $ . Let’s erase any of the digits $ 8 $ three times. The result will be $ 8 $ which is a power of $ 2 $ .

输入格式

The first line contains one integer $ t $ ( $ 1 \le t \le 10^4 $ ) — the number of test cases. Then $ t $ test cases follow.

Each test case consists of one line containing one integer $ n $ ( $ 1 \le n \le 10^9 $ ).

输出格式

For each test case, output in a separate line one integer $ m $ — the minimum number of moves to transform the number into any power of $ 2 $ .

样例 #1

样例输入 #1

12
1052
8888
6
75
128
1
301
12048
1504
6656
1000000000
687194767

样例输出 #1

2
3
1
3
0
0
2
1
3
4
9
2

提示

The answer for the first test case was considered above.

The answer for the second test case was considered above.

In the third test case, it’s enough to add to the right the digit $ 4 $ — the number $ 6 $ will turn into $ 64 $ .

In the fourth test case, let’s add to the right the digit $ 8 $ and then erase $ 7 $ and $ 5 $ — the taken number will turn into $ 8 $ .

The numbers of the fifth and the sixth test cases are already powers of two so there’s no need to make any move.

In the seventh test case, you can delete first of all the digit $ 3 $ (the result is $ 01 $ ) and then the digit $ 0 $ (the result is $ 1 $ ).

思路

本题最终的目的是将一个[1,1e9]的整数通过2种操作变为2的非负整数次幂。

将20 - 255 每一个数位上的数打表预处理,用原数列一一与表中元素比较,计算操作次数,记录最小值。

时间复杂度: O(10t)≈1e5O(10t)≈1e5O(10t)1e5

代码实现

#include<bits/stdc++.h>
#define ll long long
using namespace std;const int maxn=100;
const int inf=2e9;
int t,ans=inf,tot;
ll op=1,x;
ll a[maxn];
int k[maxn];//记录表中每一元素的长度
ll cnt[maxn][maxn];
int main(){//预处理++k[0];cnt[0][1]=1;for(int i=1;i<=55;i++){op=(ll)op*2;ll op1=op;while(op1){cnt[i][++k[i]]=(ll)op1%10;op1=(ll)op1/10;}}/*for(int i=1;i<=40;i++){for(int j=k[i];j>=1;j--)printf("%lld",cnt[i][j]);printf("\n");}*/scanf("%d",&t);while(t--){ans=inf;scanf("%lld",&x);tot=0;while(x){a[++tot]=(ll)x%10;x=(ll)x/10;}//for(int i=tot;i>=1;i--)printf("%d",a[i]);//计算比较for(int i=0;i<=55;i++){int st1=tot,st2=k[i];while(st1>0&&st2>0){if(a[st1]==cnt[i][st2])--st2;--st1;}//if(i==41)printf("41 %d %d\n",k[i],st2);ans=min(ans,tot-k[i]+2*st2);// tot-(k[i]-st2) 删除的操作次数操作次数 & st2 添加的操作次数}printf("%d\n",ans);}return 0;
}

备注

写入好题本

http://www.hkea.cn/news/146648/

相关文章:

  • 大连网站网站搭建制作百度识图 上传图片
  • 给人做网站多少钱黑科技引流推广神器怎么下载
  • 沈阳做网站最好的公司百度快照怎么删除
  • 设置本机外网ip做网站网站免费制作平台
  • 有什么推荐做简历的网站2024的新闻有哪些
  • 申请做网站 论坛版主惠州seo外包服务
  • 网站照片上传不了域名解析ip
  • 胖小七网站建设2022最新国际新闻10条简短
  • wordpress 网站备份厦门seo外包服务
  • 网站建设及推广培训杭州百度快照优化排名
  • 简单手机网站开发软件关键词排名代发
  • visio画网站开发类图注册域名后怎么建网站
  • 道里网站运营培训北京网络营销咨询公司
  • 目前做网站流行的语言seo关键词排名优化哪家好
  • 长沙营销型网站制作费用seo图片优化
  • 学生诚信档案建设网站seo数据分析
  • 北京住房城乡建设厅网站首页1688官网入口
  • 网站建设需要懂什么软件徐州百度seo排名优化
  • wordpress网站样式网站排名查询
  • 郑州网站建设推销外贸网站推广与优化
  • 当当网站开发系统说明搜索引擎排名google
  • 国外男女直接做的视频网站企业邮箱登录入口
  • 成都可以做网站的公司百度手机助手最新版下载
  • 赤峰网站建设招聘市场营销互联网营销
  • 网站开发后端需要哪些技术友情链接检索数据分析
  • 金华竞价排名 金华企业网站建设常见的网络营销平台有哪些
  • p2p网站开发关键词seo是什么意思
  • 自己免费怎么制作网站合肥今天的最新消息
  • 今日头条新闻10条简短seo网络优化招聘信息
  • 赣州人才网官方网站关键词seo优化软件