【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 ...
随机推荐
- How to reclaim space in InnoDB when innodb_file_per_table is ON
When innodb_file_per_table is OFF and all data is going to be stored in ibdata files. If you drop so ...
- bzoj 2426 【HAOI2010】工程选址 贪心
[HAOI2010]工厂选址 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 447 Solved: 308[Submit][Status][Disc ...
- eclipse关闭错误警告提示
- DSP投放进阶指南
- barba.js 优化页面跳转用户体验
barba.js 原理就是在a页面中显示b页面的内容,样式为刷新,给用户以页面跳转后无刷新体验,注意样式命名,ab页面引用的样式和js要相同 可以在页面之间创建良好的转换,增强用户的体验. 减少HTT ...
- ActiveMQ(3) ActiveMQ创建(simpleAuthenticationPlugin)安全认证
控制端安全认证: ActiveMQ目录conf下jetty.xml: <bean id="securityLoginService" class="org.ecli ...
- HDU3790---(双权最短路径)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3790 最短路径问题 Time Limit: 2000/1000 MS (Java/Others) M ...
- centos 防火墙关闭/开启
从配置菜单关闭防火墙是不起作用的,索性在安装的时候就不要装防火墙查看防火墙状态:/etc/init.d/iptables status暂时关闭防火墙:/etc/init.d/iptables stop ...
- C# 反射 名称不区分大小写
一 Type type = Type.GetType(className,false,true); //第一个是“类型的全名”,第二个参数:找不到时触发异常,第三个参数:寻找的时候是否忽略大小写 二 ...
- Linux 之test expr命令
test指令(使用指令man查询) 功能:检查文件类型,值比较. test的各种参数和使用. test EXPRESSION1 –a EXPRESSION2 当表达式1和表达式2同时为真时值为真 te ...