【DFS】Codeforces Round #402 (Div. 2) B. Weird Rounding
暴搜
#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的更多相关文章
- 【推导】【DFS】Codeforces Round #429 (Div. 1) B. Leha and another game about graph
题意:给你一张图,给你每个点的权值,要么是-1,要么是1,要么是0.如果是-1就不用管,否则就要删除图中的某些边,使得该点的度数 mod 2等于该点的权值.让你输出一个留边的方案. 首先如果图内有-1 ...
- 【贪心】【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< ...
- 【DFS】Codeforces Round #398 (Div. 2) C. Garland
设sum是所有灯泡的亮度之和 有两种情况: 一种是存在结点U和V,U是V的祖先,并且U的子树权值和为sum/3*2,且U不是根,且V的子树权值和为sum/3. 另一种是存在结点U和V,他们之间没有祖先 ...
- 【推导】【贪心】Codeforces Round #402 (Div. 2) E. Bitwise Formula
按位考虑,每个变量最终的赋值要么是必为0,要么必为1,要么和所选定的数相同,记为2,要么和所选定的数相反,记为3,一共就这四种情况. 可以预处理出来一个真值表,然后从前往后推导出每个变量的赋值. 然后 ...
- 【贪心】Codeforces Round #402 (Div. 2) C. Dishonest Sellers
按照b[i]-a[i],对物品从大到小排序,如果这个值大于零,肯定要立刻购买,倘若小于0了,但是没买够K个的话,也得立刻购买. #include<cstdio> #include<a ...
- 【推导】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]- ...
- 【题解】Codeforces Round #798 (Div. 2)
本篇为 Codeforces Round #798 (Div. 2) 也就是 CF1689 的题解,因本人水平比较菜,所以只有前四题 A.Lex String 题目描述 原题面 给定两个字符串 \(a ...
- 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 ...
- 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 ...
随机推荐
- VC++使用CImage在内存中Jpeg转换Bmp图片
VC++中Jpeg与Bmp图片格式互转应该是会经常遇到,Jpeg相比Bmp在图片大小上有很大优势. 本文重点介绍使用现有的CImage类在内存中进行转换,不需要保存为文件,也不需要引入第三方库. Li ...
- ext4文件系统由文件的inode号定位其inode Table
在ubuntu中(以16.06为例),stat filename 可以查看文件的inode数值,但是如何确定该inode项具体在哪个块组下的inode Table中不是那么容易,接下来通过一步步计算来 ...
- Web.xml过滤器配置及执行顺序概念
第一个过滤器 @Overridepublic void doFilter(ServletRequest request, ServletResponse response,FilterChain ch ...
- java 获取当前应用程序路径
package javaapplication1; import javax.swing.JOptionPane; /** * * @author Administrator */ public cl ...
- Python学习笔记 - day6 - 函数
函数 函数在编程语言中就是完成特定功能的一个词句组(代码块),这组语句可以作为一个单位使用,并且给它取一个名字.可以通过函数名在程序的不同地方多次执行(这叫函数的调用).函数在编程语言中有基本分为:预 ...
- sprintf,snprintf的用法(可以作为linux中itoa函数的补充)【转】
转自:http://blog.csdn.net/educast/article/details/25068445 函数功能:把格式化的数据写入某个字符串 头文件:stdio.h 函数原型:int sp ...
- expect基础及实例
expect基础及实例 http://blog.csdn.net/zhuying_linux/article/details/6900805
- 【反演复习计划】【bzoj4407】于神之怒加强版
#include<bits/stdc++.h> #define N 5000010 #define yql 1000000007 using namespace std; typedef ...
- 【 Linux 】三大主流软件负载均衡器对比(LVS、Nginx、HAproxy)
三大主流软件负载均衡器对比(LVS.Nginx.HAproxy) (资料来自网络,做了部分的补充说明) LVS: 1. 抗负载能力强,性能高,能达到F5的60%,对内存和CPU资源消耗比较低 ...
- Newtonsoft.Json 序列化和反序列化 以及时间格式
1.JSON序列化 string JsonStr= JsonConvert.SerializeObject(Entity); eg: A a=new A(); a.Name="Elain ...