ACM's POJ 1019 method

Source: Internet
Author: User
Tags ack

Met a few younger brother, has always wanted to put their experience to express some, let the people in the back in a more youthful time, recognize the direction, efforts.

Yesterday I suddenly remembered that I did a few days in college, ACM, finally did not insist. Then I feel it is very good to take the younger brothers to do the ACM topic.

POJ is still familiar with the interface, but the university registered account also forgot. Think of not a few questions were ack~ and then re-registered an account.

Of course, is the 1019 topic, but also thought that the topic of water, the results of the whole morning and the time before it was ack.

-----------------about the test instructions of the 1019 topics---------------------

There is a sequence, the sequence is such a s1s2 ... SK, each SK is also a sequence of numbers from 1 to K.

For example, the first 80 bits of the sequence are as follows

11212312341234512345612345671234567812345678912345678910123456789101112345678910

Requirement: Enter the position of a number and then output the number in that position.

Like what:

3 will output 2

8 will output 2

80 outputs 0 (according to the first 80 bits of the sequence in the problem)

81 Outputs 1 (according to the problem, the next number in the sequence is 11, so the digit bit of the 81st bit output is 1)

-----------------answer the idea-----------------------------------------

Observation sequence, the whole sequence s1s2 ... SK is a sub-sequence of K, while the K-subsequence is the K-1 subsequence plus the largest number.

So my idea can be divided into three steps:

1. Determines the sub-sequence where the input position resides

2. Determine the number in a subsequence (the number may be 10 or hundreds)

3. Determine specific characters in a number

-----------------Specific Reference Code-----------------------------------

#include <stdio.h>
#include <math.h>

int number, TMP;
int big, big_length, sub_str_length;
int Sub_big, POS, result;
int array[10];
int ind;

int main ()
{
int count;
scanf ("%d", &count);

while (count--)
{
scanf ("%i", &number);

Determining the sub-sequence
Big = 1;
Sub_str_length = 1;
while (1)
{
if (Sub_str_length < number)
{
Number-= Sub_str_length;
Big + +;

Maximum number of sub-series length
TMP = big;
big_length = 0;
while (TMP)
{
big_length++;
TMP = TMP/10;
}
Sub_str_length + = Big_length;
}else
{
Break
}

}

The exact number in the sub-sequence, and the position of the number
pos = 0;
Sub_big = 0;
while (POS < number)
{
sub_big++;
TMP = Sub_big;
result = 0;
while (TMP)
{
Result + +;
POS + +;
if (pos = = number)
Goto Print;

TMP = TMP/10;
}
}

Print specific characters based on the number and position in the current number
Print
while (Sub_big)
{
array[ind++] = sub_big% 10;
Sub_big/= 10;
}
printf ("%d\n", Array[ind-result]);
}
return 0;
}

ACM's POJ 1019 method

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.