Codeforces Round #402 (Div. 2) B. Weird Rounding(爆搜)
来源:互联网 发布:淘宝信用卡支付设置 编辑:程序博客网 时间:2024/05/09 13:24
题目链接:http://codeforces.com/contest/779/problem/B
【中文题意】问你一个数n要至少删除他的几位可以被10^k整除,保证一定有答案存在。
【思路分析】直接爆搜就行了,因为n的位数在10位内,所以时间复杂度在2^10以内,就是枚举每一位删除和不删除的情况。有一个坑的地方就是不能有前导0,这个的话用一个flag标记一下就好了。
【AC代码】
#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<map>#include<queue>#include<stack>using namespace std;int dight[30],re,num,d=0,kk=0;int book[30];void cal(){ int ans=0,sum=0,flag=1; for(int i=num; i>=1; i--) { if(book[i]==0)sum++; if(book[i]==1) { if(flag==0)return ; if(ans==0&&dight[i]==0) { flag=0; } ans=ans*10+dight[i]; } } if(ans%d==0) { re=min(re,sum); }}void dfs(int k){ if(k>num) { cal(); return; } book[k]=1; dfs(k+1); book[k]=0; dfs(k+1);}int main(){ int n,k; while(~scanf("%d %d",&n,&k)) { re=100; num=0; int x=n; memset(book,1,sizeof(book)); while(n) { dight[++num]=n%10; n/=10; } d=1; for(int i=1; i<=k; i++) { d*=10; } if(x%d==0) { printf("0\n"); continue; } dfs(1); printf("%d\n",re); } return 0;}
0 0
- Codeforces Round #402 (Div. 2) B. Weird Rounding(爆搜)
- Codeforces Round #402 (Div. 2) B. Weird Rounding
- Codeforces Round #402 (Div. 2) B. Weird Rounding
- Codeforces Round #402 (Div. 2)B. Weird Rounding【暴力枚举】
- Codeforces Round #402 (Div. 2) B. Weird Rounding
- Codeforces #402 (Div. 2) B. Weird Rounding
- (贪心)Codeforces Round #402 B. Weird Rounding
- 【Codeforces-402B】-Weird Rounding(数学,思维)
- 【CodeForces 779B】Weird Rounding(模拟)
- 【codeforces 779B】Weird Rounding
- codeforces 779B Weird Rounding
- Codeforces 779B-Weird Rounding
- Codeforces 778B. Weird Rounding
- CodeForces 779B Weird Rounding
- codeforces 779B Weird Rounding
- Weird Rounding (Codeforces-779B)
- Codeforces Round #451 (Div. 2) A. Rounding
- Codeforces Round #407 (Div. 1) B. Weird journey
- 设计模式——常用的设计原则
- 【Linux】虚拟机中Linux扩容
- Linux内核分析实验3——分析linux内核启动过程
- Spring源码学习--ClassPathXmlApplicationContext(一)
- Ubuntu安装.deb包与依赖包
- Codeforces Round #402 (Div. 2) B. Weird Rounding(爆搜)
- git上传一个已存在的项目流程
- 设计模式——装饰模式
- How tomcat works——11 StandardWrapper
- 【GC算法】jvm垃圾收集算法详解
- Spark MLlib矩阵分解源码分析
- HDU 2089 不要62
- spring引用properties文件
- 网络(喵喵喵?)