Tsinghua 07 computer questions

Source: Internet
Author: User
Question 1 (Executable File Name Program1.exe )Returns the number of prime factors of an integer n (n> 1. Note: 1 is not a prime factor of N: If n is a prime number, n is a prime factor of N. Duplicate calculation is required for the same prime factor. For example, 120 = 2*2*2*3*5, there are 5 prime factors in total. Input: positive integer N, 1 <n <109 output: N prime factor number sample input:

 

120

 

Sample output

 

5

 

  Question 2 (Executable File Name: program2.exe)For a decimal number A, convert a to a binary number, then sort it in reverse order by bit, and then convert it to a decimal number B. we multiply the value of B to Binary Reverse Order count. For example, if the decimal number is 173, the binary format is 101011101, and the reverse order is 10110101, the decimal number is 181,181, that is, the binary Reverse Order Number of 173 is entered: A 1000-bit (that is, 10999) decimal number. Output: the binary reverse order of the input decimal number. Sample input:

 

173

 

Sample output:

 

181

 

  Question 3 (Executable File Name: program3.exe)There are several stamps that require the minimum number of stamps to be selected to generate a given total value. For example, if one, three, and four stamps are required to be scored as 10, three stamps are used: 3, 3, and 4. Input: the total number of stamps required to be merged is m, m <100, followed by n, n <20, indicating that there are n stamps. Next there are n positive integers, which represent the face values of the N stamps in ascending order. Output: the minimum number of stamps that can generate a total value of M. If no solution is available, 0 is output. Sample input:

 

10 5 1 3 3 3 4

 

Sample output:

 

3

 

(Responsible editor: Admin)

# Include <iostream> <br/> # include <stack> <br/> # include <queue> <br/> using namespace STD; <br/> stack <int> S; <br/> queue <int> q; <br/> char data [1005]; <br/> int ans [1005]; <br/> int Wei; <br/> int divide (char data []) <br/>{< br/> int I; <br/> while (strlen (data)> 0) <br/>{< br/> int n = strlen (data); <br/> Int J = 0, jin = 0; <br/> for (I = 0; I <n; I ++) <br/> {<br/> int temp = (Jin * 10 + (data [I]-'0')/2; <br/> Jin = (Jin * 10 + (dat A [I]-'0') % 2; <br/> if (I = 0 & temp = 0) <br/> continue; <br/> else <br/> data [J ++] = temp + '0 '; <br/>}< br/> data [J] = '/0'; <br/> q. push (Jin); <br/>}< br/> return 0; <br/>}< br/> int multi () <br/>{< br/> int I, j, Jin; <br/> Wei = 0; <br/> memset (ANS, 0, sizeof (ANS )); <br/> while (! Q. empty () <br/>{< br/> int temp = Q. front (); <br/> q. pop (); <br/> Jin = 0; <br/> for (I = 0; I <= Wei; I ++) <br/> {<br/> J = (ANS [I]) * 2 + Jin) % 10; <br/> Jin = (ANS [I]) * 2 + Jin)/10; <br/> ans [I] = J; <br/>}< br/> If (Jin! = 0) <br/> ans [I] = Jin, Wei ++; <br/> If (temp = 0) <br/> continue; <br/> I = 0; <br/> while (ANS [I] = 9) <br/> {<br/> ans [I] = 0; <br/> I ++; <br/>}< br/> if (I <= Wei) <br/> ans [I] + = 1; <br/> else <br/> ans [++ Wei] = 1; <br/>}< br/> for (I = Wei; I> = 0; I --) <br/> cout <ans [I]; <br/> cout <Endl; <br/> return 0; <br/>}< br/> int main () <br/> {<br/> // freopen ("D: // in.txt", "r ", stdin); <br/> while (CIN> data) <br/>{< br/> divide (data); <br/> multi (); <br/>}< br/> return 0; <br/>} 

# Include <iostream> <br/> using namespace STD; <br/> int A [25]; <br/> int f [105]; <br/> int main () <br/> {<br/> // freopen ("D: // in.txt", "r", stdin ); <br/> int n, m, I, J, K; <br/> while (CIN> m) <br/>{< br/> CIN> N; <br/> for (I = 0; I <n; I ++) <br/> CIN> A [I]; <br/> for (I = 1; I <= m; I ++) <br/> F [I] = 100000; <br/> F [0] = 0; <br/> for (j = 0; j <n; j ++) <br/> {<br/> for (I = m; I> = 0; I --) <br/> {<br/> if (I-A [J]> = 0 & F [I-A [J] + 1 <F [I]) <br/> F [I] = f [I-A [J] + 1; <br/>}< br/> cout <F [m] <Endl; <br/>}< br/> return 0; <br/>} 

Related Article

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.