暴搜

#include<cstdio>
#include<algorithm>
using namespace std;
int n,K,Div=1,a[21],m,ans=100;
bool vis[21];
void calc(int now)
{
int t=0;
bool flag=0;
for(int i=m;i>=1;--i) if(!vis[i])
{
if((!flag) && a[i]==0)
return;
t=t*10+a[i];
flag=1;
}
if(t%Div==0)
ans=min(ans,now);
}
void dfs(int cur,int now)
{
if(cur>m)
{
calc(now);
return;
}
vis[cur]=1;
dfs(cur+1,now+1);
vis[cur]=0;
dfs(cur+1,now);
}
int main()
{
// freopen("b.in","r",stdin);
scanf("%d%d",&n,&K);
bool flag=0;
while(n)
{
a[++m]=n%10;
if(a[m]==0)
flag=1;
n/=10;
}
if(flag)
ans=m-1;
for(int i=1;i<=K;++i)
Div*=10;
dfs(1,0);
printf("%d\n",ans);
return 0;
}

【DFS】Codeforces Round #402 (Div. 2) B. Weird Rounding的更多相关文章

  1. 【推导】【DFS】Codeforces Round #429 (Div. 1) B. Leha and another game about graph

    题意:给你一张图,给你每个点的权值,要么是-1,要么是1,要么是0.如果是-1就不用管,否则就要删除图中的某些边,使得该点的度数 mod 2等于该点的权值.让你输出一个留边的方案. 首先如果图内有-1 ...

  2. 【贪心】【DFS】Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) C. Andryusha and Colored Balloons

    从任意点出发,贪心染色即可. #include<cstdio> #include<algorithm> using namespace std; int v[200010< ...

  3. 【DFS】Codeforces Round #398 (Div. 2) C. Garland

    设sum是所有灯泡的亮度之和 有两种情况: 一种是存在结点U和V,U是V的祖先,并且U的子树权值和为sum/3*2,且U不是根,且V的子树权值和为sum/3. 另一种是存在结点U和V,他们之间没有祖先 ...

  4. 【推导】【贪心】Codeforces Round #402 (Div. 2) E. Bitwise Formula

    按位考虑,每个变量最终的赋值要么是必为0,要么必为1,要么和所选定的数相同,记为2,要么和所选定的数相反,记为3,一共就这四种情况. 可以预处理出来一个真值表,然后从前往后推导出每个变量的赋值. 然后 ...

  5. 【贪心】Codeforces Round #402 (Div. 2) C. Dishonest Sellers

    按照b[i]-a[i],对物品从大到小排序,如果这个值大于零,肯定要立刻购买,倘若小于0了,但是没买够K个的话,也得立刻购买. #include<cstdio> #include<a ...

  6. 【推导】Codeforces Round #402 (Div. 2) A. Pupils Redistribution

    一次交换,会让Group A里面的某个数字的数量-1,另一个数字的数量+1:对Group B恰好相反. 于是答案就是xigma(i=1~5,numA[i]-numB[i]>0)(numA[i]- ...

  7. 【题解】Codeforces Round #798 (Div. 2)

    本篇为 Codeforces Round #798 (Div. 2) 也就是 CF1689 的题解,因本人水平比较菜,所以只有前四题 A.Lex String 题目描述 原题面 给定两个字符串 \(a ...

  8. Codeforces 716A Crazy Computer 【模拟】 (Codeforces Round #372 (Div. 2))

    A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  9. Codeforces 716B Complete the Word【模拟】 (Codeforces Round #372 (Div. 2))

    B. Complete the Word time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

随机推荐

  1. Backup and Restore MySQL Database using mysqlhotcopy

    mysqlhotcopy is a perl script that comes with MySQL installation. This locks the table, flush the ta ...

  2. Could not resolve com.android.support:multidex:1.0.2

    http://blog.csdn.net/goodlixueyong/article/details/50992835

  3. hadoop更换硬盘

    hadoop服务器更换硬盘操作步骤(datanode hadoop目录${HADOOP_HOME}/bin    日志位置:/var/log/hadoop)1.登陆服务器,切换到mapred用户,执行 ...

  4. 测试数据库DG搭建为正式库以后做准备

    Data guard 部署 1.系统准备(备库只需建立数据库软件) 两台操作系统 oracle linux 7 Node1 172.16.70.191 Node2 172.16.70.192 Orac ...

  5. powershell for rename server name

    Rename server name if server has not yet joined AD $Hostname = "newname" $username = " ...

  6. 纯手工 CheckboxTree 实现

    数据结构及页面显示格式: INSERT INTO AS_CombRules VALUES('', '', '', '', '', '', '') 实现 CheckboxTree 功能: html代码: ...

  7. Python基础(4)_集合、布尔类型

    一.集合 集合的作用一:关系运算集合的作用二:去重 定义集合:集合内的元素必须是唯一的:集合内的元素必须是可hash的,也是就不可变类型:集合是无序的 s={'egon',123,'egon','1' ...

  8. bzoj 2324 ZJOI 营救皮卡丘 费用流

    题的大概意思就是给定一个无向图,边有权值,现在你有k个人在0点,要求走到n点,且满足 1:人们可以分头行动,可以停在某一点不走了 2:当你走到x时,前x-1个点必须全部走过(不同的人走过也行,即分两路 ...

  9. bzoj 2753 最小生成树变形

    我们根据高度建图,将无向边转化为有向边 首先对于第一问,直接一个bfs搞定,得到ans1 然后第二问,我们就相当于要求找到一颗最小生成树, 满足相对来说深度小的高度大,也就是要以高度为优先级 假设现在 ...

  10. cygwin与vim配置

    参考 http://www.jeepshoe.org/810958442.htm cygwin安装包管理器 通过终端安装apt-cyg之前选要安装以下软件包wget tar gawk bzip2 ap ...