[Codeforces]852A - Digits
题目大意:给一个10^200000以内的数字,支持一种操作:在数字之间加若干个加号,把原数字变为加法运算后的结果,要求在三次操作内把数字变成个位数,输出方案。
做法:直观的想法是每两位之间都塞加号,事实证明这样并不一定最优,比如第一次操作后得到1399999,最后一次会得到13。我写了一个比较科学的玄学做法,因为如果这种贪心不够优,第一次得到的数各位和一定比较大,而得到的这个数再加上一些小数字各位和就容易变小,于是如果贪心不行,我就在第一次操作的时候随便把一些两位合并,然后再贪心,不知道能不能被hack,但应该挺科学的。
代码:
#include<cstdio>
#define MN 200000
char s[MN+];
int n,u[MN+];
bool solve()
{
int i,sm=,ss=,sss=,x,y,a[],an=,b[],bn=;
for(i=;i<=n;++i)if(u[i])sm+=(s[i]-'')*+s[i+]-'',++i;else sm+=s[i]-'';
for(x=sm;sm;sm/=)ss+=a[++an]=sm%;
for(y=ss;ss;ss/=)sss+=b[++bn]=ss%;
if(sss<)
{
for(i=;i<=n;++i)
{
if(i>)putchar('+');
putchar(s[i]);
if(u[i])putchar(s[++i]);
}
puts("");
for(i=an;i>;--i)printf("%d+",a[i]);printf("%d\n",a[]);
for(i=bn;i>;--i)printf("%d+",b[i]);printf("%d\n",b[]);
return false;
}
return true;
}
int main()
{
scanf("%d%s",&n,s+);
for(int i=;solve();)
{
for(;s[i]=='';++i);
u[i]=;i+=;
}
}
[Codeforces]852A - Digits的更多相关文章
- Codeforces Round #379 (Div. 2) B. Anton and Digits 水题
B. Anton and Digits 题目连接: http://codeforces.com/contest/734/problem/B Description Recently Anton fou ...
- [codeforces 509]C. Sums of Digits
[codeforces 509]C. Sums of Digits 试题描述 Vasya had a strictly increasing sequence of positive integers ...
- Codeforces Gym 100531D Digits 暴力
Problem D. Digits 题目连接: http://codeforces.com/gym/100531/attachments Description Little Petya likes ...
- CodeForces 1060 B Maximum Sum of Digits
Maximum Sum of Digits You are given a positive integer n. Let S(x)S(x) be sum of digits in base 10 r ...
- Codeforces Round #277.5 (Div. 2)-C. Given Length and Sum of Digits...
http://codeforces.com/problemset/problem/489/C C. Given Length and Sum of Digits... time limit per t ...
- 【codeforces 509C】Sums of Digits
[题目链接]:http://codeforces.com/contest/509/problem/C [题意] 给你一个数组b[i] 要求一个严格升序的数组a[i]; 使得a[i]是b[i]各个位上的 ...
- 【81.37%】【codeforces 734B】Anton and Digits
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Codeforces Round #584 C. Paint the Digits
链接: https://codeforces.com/contest/1209/problem/C 题意: You are given a sequence of n digits d1d2-dn. ...
- Codeforces Round #589 (Div. 2) A. Distinct Digits
链接: https://codeforces.com/contest/1228/problem/A 题意: You have two integers l and r. Find an integer ...
随机推荐
- alpha冲刺第九天
一.合照 二.项目燃尽图 三.项目进展 提问界面完成 财富值界面完成 四.明日规划 继续完善各个内容的界面呈现 继续查找关于如何自动更新爬取内容 五.问题困难 在呈现的时候还是一直会停止运行 爬取先暂 ...
- 201621123043《java程序设计》第五周学习总结
1. 本周学习总结 1.1 写出你认为本周学习中比较重要的知识点关键词 接口. Comparable接口 .Comparator接口.compareTo. 1.2 尝试使用思维导图将这些关键词组织起来 ...
- 第二十八条:利用有限制通配符来提升API的灵活性
如第二十五条所述,参数化类型是不可变的.类型Type1和Type2而言,不管Type1与Type2的关系,List<Type1>既不是List<Type2>的子类型,也不是也不 ...
- Node入门教程(3)第二章: Node 安装
Node 安装 官网下载地址: https://nodejs.org/en/download/ 安装方式 windows 下安装 建议直接选择:Windows Installer (.msi)下载进行 ...
- css3动画transition详解2
transition主要包含四个属性值:执行变换的属性:transition-property,变换延续的时间:transition-duration,在延续时间段,变换的速率变化transition ...
- python之路--day15---软件开发目录规范
软件开发目录规范 bin--启动文件 conf--配置文件 core--核心代码 db--数据文件 lib--常用功能代码 log--日志文件 readme--软件介绍
- JAVA_SE基础——15.循环嵌套
嵌套循环是指在一个循环语句的循环体中再定义一个循环语句结构,while,do-while,for循环语句都可以进行嵌套,并且可以互相嵌套,下面来看下for循环中嵌套for循环的例子. 如下: publ ...
- dede使用心得
Question one: 最近做了一些视频教程传到优酷网站上,但我想引入这些视频教程到我的网站,在发表时我发现织梦CMS自带的编辑器又不直接支持优酷等视频网站的引用.所以为了方便教程的发布,特意在网 ...
- maven常见问题处理(3-3)Gradle编译时下载依赖失败解决方法
Gradle编译时在本地仓库中如果没有发现依赖,就会从远程仓库中下载, 默认的远程仓库为 mavenCentral(),即 http://repo1.maven.org/maven2/往往访问速度特别 ...
- sql server 常用的查询语句
最近在加强sql 语句的学习,整理一下基本语法,现在记录下 select * from dbo.cangku where city='河南' select distinct(city), cangk ...