【codeforces 779B】Weird Rounding
【题目链接】:http://codeforces.com/contest/779/problem/B
【题意】
问你要删掉几个数字才能让原来的数字能够被10^k整除;
【题解】
/*
数字的长度不大;
让你删掉最小的数字个数
使得这个数字能被10^k整除;
搜索;
枚举哪些数字被删掉了;
bool记录;
最后再全部乘起来;
枚举删掉1个,删掉两个即可、3、4...;
注意前导0只能有一个的情况就好
*/
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 15;
string s;
int po_w[12],k,len,di,num;
bool bo[15];
void dfs(int x, int now)
{
if (now >= num)
{
int nu = 0,t = 0,fir=-1;
rep1(i, 1, len)
if (bo[i])
{
if (fir == -1)
fir = s[i] - '0';
t++;
nu = nu * 10 + s[i] - '0';
}
if (fir == 0 && t > 1) return;
if (nu%di == 0)
{
printf("%d\n", num);
exit(0);
}
return;
}
if (x > len)
return;
bo[x] = false;
dfs(x + 1, now + 1);
bo[x] = true;
dfs(x + 1, now);
}
int main()
{
//freopen("F:\\rush.txt", "r", stdin);
po_w[0] = 1;
rep1(i, 1, 9)
po_w[i] = po_w[i - 1] * 10;
cin >> s;
len = s.size();
s = ' ' + s;
scanf("%d", &k);
di = po_w[k];
memset(bo, true, sizeof bo);
for (num = 0;num <= len-1;num++)
dfs(1, 0);
return 0;
}
【codeforces 779B】Weird Rounding的更多相关文章
- 【codeforces 789D】Weird journey
[题目链接]:http://codeforces.com/problemset/problem/789/D [题意] 给你n个点,m条边; 可能会有自环 问你有没有经过某两条边各一次,然后剩余m-2条 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【51.27%】【codeforces 604A】Uncowed Forces
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 604D】Moodular Arithmetic
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【27.40%】【codeforces 599D】Spongebob and Squares
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
随机推荐
- 利用mysql5.6 的st_distance 实现按照距离远近排序。 (转载)
http://blog.csdn.net/zhouzhiwengang/article/details/53612481
- 洛谷 P1178 到天宫做客
P1178 到天宫做客 题目描述 有一天,我做了个梦,梦见我很荣幸的接到了猪八戒的邀请,到天宫陪他吃酒.我犹豫了.天上一日,人间一年啊!当然,我是个闲人,一年之中也没有多少时日是必须在人间的,因此,我 ...
- vue使用(二)
本节目标: 1.数据路径的三种方式 2.{{}}和v-html的区别 1.绑定图片的路径 方法一:直接写路径 <img src="http://p ...
- python3 turtle 画国际象棋棋盘
python3 turtle 画国际象棋棋盘 #!/usr/bin/env python # -*- coding:utf-8 -*- # Author:Hiuhung Wan import turt ...
- 【AtCoder Beginner Contest 074 C】Sugar Water
[链接]h在这里写链接 [题意] 让你在杯子里加糖或加水. (4种操作类型) 糖或水之间有一定关系. 糖和水的总量也有限制. 问你糖水浓度的最大时,糖和糖水的量. [题解] 写个dfs就好. 每次有4 ...
- (7)Launcher3客制化之,改动单屏幕后,Fix在Hotseat拖动应用删除报错
改动单屏幕后,在workspace里面拖动图标.到删除button上松开的时候,报错问题. 而且无法再次显示拖动的图标. 拖动松开手时候触发 public void onDropCompleted(f ...
- C语言结构体的字节对齐原则
为什么要对齐? 现代计算机中内存空间都是按照byte划分的,从理论上讲似乎对任何类型的变量的访问可以从任何地址开始,但实际情况是在访问特定类型变量的时候经常在特 定的内存地址访问,这就需要各种类型数据 ...
- JavaScript系列--JavaScript数组高阶函数reduce()方法详解及奇淫技巧
一.前言 reduce() 方法接收一个函数作为累加器,数组中的每个值(从左到右)开始缩减,最终计算为一个值. reduce() 可以作为一个高阶函数,用于函数的 compose. reduce()方 ...
- python没有++和--操作
- iOS中OC给Category加入属性
引: 非常多人知道能够用Category给已有的类加入一些新方法,可是不同于swift中的extension,Objective-C中的Category(类别)是不支持直接加入属性的.那假设就是须要加 ...