题目链接

题意:给定一个很大的数,把他们分为数个回文数的和,分的个数不超过50个,输出个数并输出每个数,special judge。

题解:现场赛的时候很快想出来了思路,把这个数从中间分为两部分,当位数为偶数的时候3456就分为34和56,34-1=33,回文数3333,3456-3333=123然后继续算;当位数为奇数的时候34567就分为34和67,5-1=4,回文数34443,34567-34443=124然后继续算。但是一年都没有写过高精度减法的题了,这个大模拟写了很久最后判断奇偶性都判断蒙了- - !,汗。考虑的太复杂了,前导0,奇偶性,如果前面比后面小就不减1的情况,有的是我想多了,找了一份比较短的代码虚心学习一下,写的很棒。

#include<bits/stdc++.h>
using namespace std;
const int N=+; bool getPal(char *s) { //得到回文数
int n=strlen(s);
if(n==)return ;
if(n==&&s[]=='') {
s[]='';
s[]=;
return ;
}
s[(n+)/-]--;
for(int i=(n+)/-; i>; i--) {
if(s[i]<'')s[i]+=,s[i-]--;
else break;
}
if(s[]=='') {
for(int i=; i<n; i++)s[i]=s[i+];
n--;
}
for(int i=(n+)/; i<n; i++)
s[i]=s[n-i-];
return ;
}
bool subStr(char *a,char *b) { //减去回文数
int na=strlen(a);
int nb=strlen(b);
for(int i=na-,j=nb-; j>=; i--,j--) {
if(a[i]>=b[j])a[i]=a[i]-b[j]+'';
else a[i]=a[i]+-b[j]+'',a[i-]--;
}
int p;
for(p=; a[p]==''; p++);
if(p==na)return ;
for(int i=; p<=na; p++,i++)a[i]=a[p];
return ;
}
char s[N],ans[][N];
int cnt;
int main() {
//freopen("f.txt","r",stdin);
int T;
scanf("%d",&T);
for(int cas=; cas<=T; cas++) {
scanf("%s",s);
for(cnt=;; cnt++) {
strcpy(ans[cnt],s);
if(getPal(ans[cnt])||subStr(s,ans[cnt]))break;
} printf("Case #%d:\n%d\n",cas,cnt+);
for(int i=; i<=cnt; i++)
printf("%s\n",ans[i]);
}
return ;
}

HDU 5920 Ugly Problem 高精度减法大模拟 ---2016CCPC长春区域现场赛的更多相关文章

  1. HDU 5920 Ugly Problem 【模拟】 (2016中国大学生程序设计竞赛(长春))

    Ugly Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  2. HDU - 5920 Ugly Problem 求解第一个小于n的回文数

    http://acm.hdu.edu.cn/showproblem.php?pid=5920 http://www.cnblogs.com/xudong-bupt/p/4015226.html 把前半 ...

  3. HDU 5920 Ugly Problem

    说起这道题, 真是一把辛酸泪. 题意 将一个正整数 \(n(\le 10^{1000})\) 分解成不超过50个回文数的和. 做法 构造. 队友UHC提出的一种构造方法, 写起来比较方便一些, 而且比 ...

  4. HDU 1022 Train Problem I(栈模拟)

    传送门 Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of st ...

  5. hdu 4771 Stealing Harry Potter's Precious (2013亚洲区杭州现场赛)(搜索 bfs + dfs) 带权值的路径

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4771 题目意思:'@'  表示的是起点,'#' 表示的是障碍物不能通过,'.'  表示的是路能通过的: ...

  6. HDU 4811 Ball -2013 ICPC南京区域现场赛

    题目链接 题意:三种颜色的球,现给定三种球的数目,每次取其中一个放到桌子上,排成一条线,每次放的位置任意,问得到的最大得分. 把一个球放在末尾得到的分数是它以前球的颜色种数 把一个球放在中间得到的分数 ...

  7. D - Ugly Problem HDU - 5920

    D - Ugly Problem HDU - 5920 Everyone hates ugly problems. You are given a positive integer. You must ...

  8. hdu-5920 Ugly Problem(贪心+高精度)

    题目链接: Ugly Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  9. hdu 5920(模拟)

    Ugly Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

随机推荐

  1. gspx请求周期(备忘)

  2. OC第五节 ——点语法和@property

    一.setter和getter函数     1.回忆:如何访问对象中的成员变量    2.setter和getter函数的作用            setter  方法:   修改对象的字段/实例变 ...

  3. 【PHP面向对象(OOP)编程入门教程】2.什么是类,什么是对象,类和对象这间的关系

    类的概念:类是具有相同属性和服务的一组对象的集合.它为属于该类的所有对象提供了统一的抽象描述,其内部包括属性和服务两个主要部分.在面向对象的编程语言中,类是一个独立的程序单位,它应该有一个类名并包括属 ...

  4. HDU 5120 Intersection(2014北京赛区现场赛I题 计算几何)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5120 解题报告:给你两个完全相同的圆环,要你求这两个圆环相交的部分面积是多少? 题意看了好久没懂.圆环 ...

  5. input多选计算

    CSS代码: body { counter-reset: icecream; } input:checked { counter-increment: icecream; } .total::afte ...

  6. zend framework2 入门实例代码album模型

    下载album模型 一.目录结构说明 - zf_project - config    - autoload      global.php    -- 数据库在这里配置      local.php ...

  7. poj3984

    定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, ...

  8. apache virtualhost 针对ip开放访问

    http://serverfault.com/questions/246003/apache-httpd-how-can-i-deny-from-all-allow-from-subnet-but-d ...

  9. centos 安装gcc时,出错:Found 10 pre-existing rpmdb problem(s), 'yum check' output follows:

    别人折腾的系统. 刚开始,准备安装下tornado,报错,需要安装 gcc 和 python-devel gcc安装报错,如标题所示: 谷歌了一把: http://stackoverflow.com/ ...

  10. HIFI播放器--磨机吐槽篇

    最近看到淘宝店提供各种随身播放器磨机服务,说的是天花乱坠,给你更换零件, 甚至更改电路,搭载上去,是如何如何的好,整个播放器就上升了几个等次,收费还 不低,至少是好几百,我实在是忍不住吐槽了,你们这些 ...