码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-10-04 14:14:01      阅读:641      评论:0      收藏:0      [点我收藏+]

标签:

 

Ugly Problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0
Special Judge


Problem Description
Everyone hates ugly problems.

You are given a positive integer. You must represent that number by sum of palindromic numbers.

A palindromic number is a positive integer such that if you write out that integer as a string in decimal without leading zeros, the string is an palindrome. For example, 1 is a palindromic number and 10 is not.
 

 

Input
In the first line of input, there is an integer T denoting the number of test cases.

For each test case, there is only one line describing the given integer s (1s101000).
 

 

Output
For each test case, output “Case #x:” on the first line where x is the number of that test case starting from 1. Then output the number of palindromic numbers you used, n, on one line. n must be no more than 50. en output n lines, each containing one of your palindromic numbers. Their sum must be exactly s.
 

 

Sample Input
2
18
1000000000000
 

 

Sample Output
Case #1:
2
9
9
Case #2:
2
999999999999
1
Hint
9 + 9 = 18
999999999999 + 1 = 1000000000000
 

 

Statistic | Submit | Clarifications | Back

 

 

 

题目链接:

  http://acm.hdu.edu.cn/showproblem.php?pid=5920

题目大意:

  输入一个长整数s(s<=101000),求将其拆分为不超过50个回文串之和的方案。

题目思路:

  【模拟】

  将前半段取出来,-1,构造成回文串c,s-=c,直到c=1。

  特殊处理0~20的情况。

技术分享
  1 //
  2 //by coolxxx
  3 //#include<bits/stdc++.h>
  4 #include<iostream>
  5 #include<algorithm>
  6 #include<string>
  7 #include<iomanip>
  8 #include<map>
  9 #include<stack>
 10 #include<queue>
 11 #include<set>
 12 #include<bitset>
 13 #include<memory.h>
 14 #include<time.h>
 15 #include<stdio.h>
 16 #include<stdlib.h>
 17 #include<string.h>
 18 //#include<stdbool.h>
 19 #include<math.h>
 20 #define min(a,b) ((a)<(b)?(a):(b))
 21 #define max(a,b) ((a)>(b)?(a):(b))
 22 #define abs(a) ((a)>0?(a):(-(a)))
 23 #define lowbit(a) (a&(-a))
 24 #define sqr(a) ((a)*(a))
 25 #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
 26 #define mem(a,b) memset(a,b,sizeof(a))
 27 #define eps (1e-10)
 28 #define J 10
 29 #define mod 1000000007
 30 #define MAX 0x7f7f7f7f
 31 #define PI 3.14159265358979323
 32 #pragma comment(linker,"/STACK:1024000000,1024000000")
 33 #define N 2004
 34 using namespace std;
 35 typedef long long LL;
 36 double anss;
 37 LL aans,sum;
 38 int cas,cass;
 39 int n,m,lll,ans;
 40 char s[N];
 41 int a[54][N],b[N],c[N];
 42 void gjdjian(int a[],int b[])
 43 {
 44     int i;
 45     for(i=1;i<=b[0];i++)
 46         a[i]-=b[i];
 47     for(i=1;i<=a[0];i++)
 48         if(a[i]<0)
 49             a[i]+=J,a[i+1]--;
 50     while(a[0]>1 && !a[a[0]])a[0]--;
 51 }
 52 void gjdprint(int a[])
 53 {
 54     int i;
 55     for(i=a[0];i;i--)
 56         printf("%d",a[i]);
 57     puts("");
 58 }
 59 void print()
 60 {
 61     int i,j;
 62     printf("Case #%d:\n",cass);
 63     printf("%d\n",lll);
 64     for(i=1;i<=lll;i++)
 65         gjdprint(a[i]);
 66 }
 67 int main()
 68 {
 69     #ifndef ONLINE_JUDGEW
 70     freopen("1.txt","r",stdin);
 71 //    freopen("2.txt","w",stdout);
 72     #endif
 73     int i,j,k;
 74 //    init();
 75 //    for(scanf("%d",&cass);cass;cass--)
 76     for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
 77 //    while(~scanf("%s",s))
 78 //    while(~scanf("%d",&n))
 79     {
 80         lll=0;mem(a,0);
 81         scanf("%s",s);
 82         n=strlen(s);
 83         b[0]=n;
 84         for(i=0;i<n;i++)b[n-i]=s[i]-0;
 85         while(!(b[0]==1 && b[1]==0))
 86         {
 87             if(b[0]==1)
 88             {
 89                 a[++lll][0]=1;
 90                 a[lll][1]=b[1];
 91                 break;
 92             }
 93             else if(b[0]==2 && b[2]==1)
 94             {
 95                 if(b[1]==0)
 96                 {
 97                     a[++lll][0]=1;
 98                     a[lll][1]=9;
 99                     a[++lll][0]=1;
100                     a[lll][1]=1;
101                     break;
102                 }
103                 else if(b[1]==1)
104                 {
105                     a[++lll][0]=2;
106                     a[lll][1]=1;
107                     a[lll][2]=1;
108                     break;
109                 }
110                 else
111                 {
112                     a[++lll][0]=2;
113                     a[lll][1]=1;
114                     a[lll][2]=1;
115                     a[++lll][0]=1;
116                     a[lll][1]=b[1]-1;
117                     break;
118                 }
119             }
120             else
121             {
122                 for(i=b[0];i>b[0]/2;i--)
123                     c[i-b[0]/2]=b[i];
124                 c[0]=(b[0]+1)/2;
125                 int d[2]={1,1};
126                 gjdjian(c,d);
127                 j=c[0]+c[0];
128                 while(j>b[0])j--;
129                 lll++;
130                 a[lll][0]=j;
131                 for(i=c[0];i;i--,j--)
132                     a[lll][c[0]-i+1]=a[lll][j]=c[i];
133                 gjdjian(b,a[lll]);
134             }
135         }
136         print();
137     }
138     return 0;
139 }
140 /*
141 //
142 
143 //
144 */
View Code

 

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

标签:

原文地址:http://www.cnblogs.com/Coolxxx/p/5930385.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!