[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 ...
随机推荐
- C语言博客-指针
一.PTA实验作业(5分) 题目1:6-1 两个4位正整数的后两位互换 1. 本题PTA提交列表 2. 设计思路 3.代码截图 4.本题调试过程碰到问题及PTA提交列表情况说明. 无 题目2:6-3 ...
- 248&258--高级软件工程第三次作业
0 小组成员 马帅 / 2017202110248 齐爽爽 / 2017282110258 1 项目 GitHub 地址 GitHub:https://github.com/whumashuai/QT ...
- C语言第五次博客作业
一.PTA实验作业 题目1:6-6 使用函数输出水仙花数 1. 本题PTA提交列表 2. 设计思路 (1) 首先先定义narcissistic函数. (2)定义四个整形变量n,a,d,cnt,sum, ...
- 201621123062《java程序设计》第四周作业总结
1. 本周学习总结 1.1 写出你认为本周学习中比较重要的知识点关键词 关键词:重载.继承.多态.static.final.抽象类 1.2 尝试使用思维导图将这些关键词组织起来.注:思维导图一般不需要 ...
- 冲刺No.4
Alpha冲刺第四天 站立式会议 项目进展 今日团队开始对项目的核心功能中的事务管理员模块与学生模块进行了编码,主要内容是对学生基本信息的增删改与事务管理员信息的增删改,这部分的内容是整个项目最基础的 ...
- 团队作业4——第一次项目冲刺(Alpha版本)
第一天http://www.cnblogs.com/ThinkAlone/p/7861070.html 第二天http://www.cnblogs.com/ThinkAlone/p/7861191.h ...
- Python内置函数(45)——ascii
英文文档: ascii(object) As repr(), return a string containing a printable representation of an object, b ...
- python-map的用法
map()函数 map()是 Python 内置的高阶函数,它接收一个函数 f 和一个 list,并通过把函数 f 依次作用在 list 的每个元素上,得到一个新的 list 并返回. 1.当seq只 ...
- 【漏洞复现】PHPCMS wap模块 SQL注入(附EXP)
漏洞影响版本:v9.5.8.v9.6.0 Step1: 访问:http://www.xxx.com/index.php?m=wap&a=index&siteid=1, 获取返回的coo ...
- gradle入门(1-2)gradle的依赖管理
Gradle支持以下仓库格式: Ivy仓库 Maven仓库 Flat directory仓库 一.添加仓库 1.添加Ivy仓库 1.1.通过URL地址添加一个Ivy仓库 我们可以将以下代码片段加入到b ...