题目大意:给一个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的更多相关文章

  1. Codeforces Round #379 (Div. 2) B. Anton and Digits 水题

    B. Anton and Digits 题目连接: http://codeforces.com/contest/734/problem/B Description Recently Anton fou ...

  2. [codeforces 509]C. Sums of Digits

    [codeforces 509]C. Sums of Digits 试题描述 Vasya had a strictly increasing sequence of positive integers ...

  3. Codeforces Gym 100531D Digits 暴力

    Problem D. Digits 题目连接: http://codeforces.com/gym/100531/attachments Description Little Petya likes ...

  4. 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 ...

  5. 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 ...

  6. 【codeforces 509C】Sums of Digits

    [题目链接]:http://codeforces.com/contest/509/problem/C [题意] 给你一个数组b[i] 要求一个严格升序的数组a[i]; 使得a[i]是b[i]各个位上的 ...

  7. 【81.37%】【codeforces 734B】Anton and Digits

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  8. Codeforces Round #584 C. Paint the Digits

    链接: https://codeforces.com/contest/1209/problem/C 题意: You are given a sequence of n digits d1d2-dn. ...

  9. 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 ...

随机推荐

  1. 学号:201621123032 《Java程序设计》第8周学习总结

    1:本周学习总结 2:书面作业 2.1:ArrayList代码分析 2.1.1:解释ArrayList的contains源代码 Contains方法调用indexof方法,如果元素为null,则循环比 ...

  2. zookeeper 启动失败 BindException: Address already in use 或者Error contacting service. It is probably not running

    平台:centos-6.3-i386 jdk-7u51 storm 0.9.1 python 2.6.6   hadoop 1.2.1 今天上午装storm的时候遇到这个问题,好郁闷.把网上介绍的方法 ...

  3. Linux环境下发布.net core

    一.安装Linux环境 1. 安装VM虚拟机和操作系统 VM虚拟工具安装的过程详见:http://blog.csdn.net/stpeace/article/details/78598333.直接按照 ...

  4. webapi 使用Autofac 开发经历

    2018/4/6 号 早上五点..被手机震动吵醒. 之后直接打开电脑,打算再加强下我自己的webapi这套东西. 虽然三年的工作经验接触了N多框架和各种风格的开发方式,但是让我自己来搞一套实在不会搞, ...

  5. php的开发的apache的配置及伪静态的应用

    1.Apache之所以能够解析php代码是游览器首先发送数据到模版页面,然后模版页提交数据到php页面,然后php代码经过Apache解析过后生成结果的,所以是 在Apache的配置文件中是可以看到开 ...

  6. Java.nio-随机读写汉字

    笔者最近在用多线程来计算中文文本的标点符号数目,遇到了以下问题: 在Windows下,文本中汉字通常采用Unicode编码,这就导致需要随机(RandomAccessFile)读取文本时,产生乱码现象 ...

  7. Mego(1) - NET中主流ORM框架性能对比

    从刚刚开始接触ORM到现在已有超过八年时间,用过了不少ORM框架也了解了不少ORM框架,看过N种关于ORM框架的相关资料与评论,各种言论让人很难选择.在ORM的众多问题中最突出的问题是关于性能方面的问 ...

  8. java对象转字节数组,获取泛型类

    对象转字节数组,字节数组在恢复成对象 Test.java class Test { public static void main(String args[]) throws IOException, ...

  9. Nokia大事录

    1994年,接通中国第一个GSM电话. 1995年,接通中国第一个无线数据电话. 1996年,接通中国第一个GSM1800网络电话.首家推出同时支持简繁中文短讯的移动电话--诺基亚8110.  199 ...

  10. Linux实战案例(7)安装jdk

    一.文件准备 1.1 文件名称 jdk-8u121-linux-x64.tar.gz 1.2 下载地址 http://www.oracle.com/technetwork/java/javase/do ...