[POJ2325] Persistent Numbers greedy + high precision/low precision

Source: Internet
Author: User

Question: We can change A number A to the product of B = A. Now we can give B and determine whether A can obtain B through computation. If yes, what is it.

Question: greedy.

Let's break down B first. If the prime factor is greater than or equal to 10, it will obviously not work.

Otherwise, we can combine the factors into A, so that the product of A is equal to B.

Greedy policy: place decimals in front of them.

Note:

I. You do not have to use a prime factor. You can use it within 10.

2. High precision is required.

3.! = B

Code:

# Include <cstdio> # include <cstring> # include <algorithm> # define N 1005 using namespace std; char s [N], t [N]; int bang [15], n; bool div (int p) {int I, x = 0; memset (t, 0, sizeof (t); for (I = 1; I <= n; I ++) {x = x * 10 + s [I]; t [I] = x/p; x % = p;} if (! X) {for (x = 1; t [x] = 0; x ++); x --; n-= x; for (I = 1; I <= n; I ++) s [I] = t [I + x]; return 1;} else return 0;} int main () {// freopen ("test. in "," r ", stdin); int I; while (scanf (" % s ", s + 1), s [1]! = '-') {Memset (bang, 0, sizeof (bang); if (! S [2]) {printf ("1% c \ n", s [1]); continue;} n = strlen (s + 1); for (I = 1; I <= n; I ++) s [I] = s [I]-'0'; for (I = 9; I> 1; I --) {while (div (I) {bang [I] ++ ;}} if (n> 1) printf ("There is no such number. "); else for (I = 2; I <= 9; I ++) while (bang [I] --) printf (" % d ", I ); puts ("");} return 0 ;}


[POJ2325] Persistent Numbers greedy + high precision/low precision

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.