Method for Determining scores (Blue Bridge cup) and Blue Bridge cup with scores

Source: Internet
Author: User

Method for Determining scores (Blue Bridge cup) and Blue Bridge cup with scores

Problem description: Score

100 can be expressed as a score:

100 = 3 + 69258/714

It can also be expressed:

100 = 82 + 3546/197

Note: Contains numbers and numbers with scores.

1 ~ 9

Appear separately and only once (excluding 0)

For example, 100 has 11 notation.

Question requirements:

Reads a positive integer from the standard input.

N (N <1000*1000)

The program outputs this number in digital 1 ~ 9. All types of data with scores are composed without repetition.

Note: you do not need to output each representation. Only the number of representations is counted!

For example:

User input: 100

Program output: 11

For example:

User input: 105

Program output: 6

Resource conventions:

Peak memory consumption <64 M

CPU consumption <3000 ms

Ideas:

The problem solved can be converted to n = I + j/k; ---> j = (n-I) * k. It can be solved by brute force solution.

Because a total of 9 digits can be used, k can take up to four digits, and I can take up to n-1.

So the code is as follows (considering that the general test does not use the time test function, the old time measurement function is omitted here );

# Include <stdio. h> // # include <string. h> int judge (int I, int j, int k) // used to determine whether the three have the same number {int a [11] = {0}, g; while (I> 0) {a [g = I % 10] ++; if (a [g]> 1) // only return 0; i/= 10;} while (j> 0) {a [g = j % 10] ++; if (a [g]> 1) return 0; j/= 10;} while (k> 0) {a [g = k % 10] ++; if (a [g]> 1) return 0; k/= 10;} if (a [0]> 0) // The number range is 1 ~ 9 return 0; for (I = 1; I <= 9; I ++) {if (a [I] = 0) return 0;} return 1 ;} int main () {int n; while (~ Scanf ("% d", & n) {int I, j, k, count = 0; for (I = 1; I <= n-1; I ++) // The maximum I value is n-1 {for (k = 1; k <= 9999; k ++) // k is used as the denominator and the change interval has nine digits, k can be up to four digits {if (I! = K) {j = (n-I) * k; if (judge (I, j, k) count ++; // count for counting }}printf ("% d \ n", count) ;}return 0 ;}




2013 Blue Bridge Cup C language undergraduate group B's seventh question incorrect ticket program answer

What netizens said on the upstairs is very simple. In fact, it is difficult to calculate because each row is not sure about the number of rows to be placed.

I input one character and one character. If it is a number, it will be stored. If it encounters \ 0, it will be atoi (). If it encounters \ n, it will end.
Finally, judge whether \ n is equal to the input.

The idea is simple and the implementation is complicated ..
I did not answer this question during the exam ..
Now it runs successfully.
# Include <stdio. h>
# Include <stdlib. h>
Const int n= 10000;
Int mysort (const void * a, const void * B)
{

Return * (int *) a-* (int *) B;
}
Int main ()
{
Int count = 0;
Int n, I = 0, j = 0, k = 0;
Int a [N];
Char ch [7];
Scanf ("% d \ n", & n );
For (count = 0; count <n ;)
{
Scanf ("% c", & ch [j]);
If (ch [j] <= '9' & ch [j]> = '0 ')
J ++;
Else if (ch [j] = '')
{
A [k ++] = atoi (ch );
J = 0;
}
Else if (ch [j] = '\ n ')
{
Count ++;
A [k ++] = atoi (ch );
J = 0;
}
}
K --;
Qsort (a, k, sizeof (int), mysort );
I = a [0];
For (j = 1; j <k; j ++)
{

If (a [j] = I | a [j] = I + 2)
Printf ("% d", a [j]);
I = a [j];
}
Return 0;
}

What is the result of the Blue Bridge Cup C ++ in 2014?

I remember it was around April ~~~ I wish you a prize ~~~

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.