ACM-data computing, acm computing

Source: Internet
Author: User

ACM-data computing, acm computing
Number calculation-(recursion (timeout) and non-recursion) time limit (Common/Java): 1000 MS/3000 MS running memory limit: 65536 KByte
Total submissions: 1050 pass the test: 312

Description

It is required to find the number of numbers with the following properties (including the natural number n of the input ):
Enter a natural number n (n <= 1000), and then process the natural number as follows:
1. No processing;
2. Add a natural number to its left, but the natural number cannot exceed half of the original number;
3. After the number is added, continue to process according to this rule until the natural number cannot be added.

Input

A natural number n

Output

One number, indicating the number of conditions

Sample Input

6

Sample output

6

Prompt

Example: The number of conditions is 6, 16, 26,126, 36,136

Question Source

NOIP2001 popularity Group

1 # include <iostream> 2 using namespace std; 3 static int sum = 1; 4 static int arr [1000] = {0}; 5 void fun (int & k) // Recursive Method 6 {7 if (k = 0) 8 return; 9 for (int I = 1; I <= k; I ++) 10 {11 sum ++; 12 int k2 = I/2; 13 fun (k2); 14} 15} 16 17 int f (int & k) {// use a non-recursive method to save the computation result 18 int count = 0; 19 if (k = 0) 20 return 0; 21 int I; 22 for (I = 1; I <= k; I ++) {23 if (arr [I]! = 0) {24 count + = arr [I]; 25} 26 else {27 int k2 = I/2; 28 arr [I] = f (k2) + 1; 29} 30} 31 if (count! = 0) 32 return count; 33 return arr [k]; 34} 35 int main () 36 {37 int n1; 38 cin> n1; 39 int k = n1/2; 40 fun (k); 41 cout <sum <endl; 42 cout <f (n1) <endl; 43 return 0; 44}

Http://acm.njupt.edu.cn/acmhome/problemdetail.do? & Method = showdetail & id = 1010

 
Acm enters a series of data computing and 12345 until the end of the file (what does this mean)

The input end with a file. This is a common input method in ACM.

# Include <stdio. h>
Int main ()
{
Double;
Double sum;
Sums = 0.0;
While (scanf ("% lf", & )! = EOF)
Sum + =;
Printf ("%. 4f \ n", sum );
Return 0;
}

Calculation of numbers in strings using C language ACM simple question

# Include <stdio. h>
# Include <string. h>
Int main ()
{
Int cases, len;
Int I;
Int ans;
Char str [100];
Scanf ("% d", & cases );
While (cases --)
{
Ans = 0;
Scanf ("% s", str );
Len = strlen (str );
For (I = 0; I <len; ++ I)
{
If (str [I]> = '0' & str [I] <= '9 ')
Ans ++;
}
Printf ("% d \ n", ans );
}
Return 0;
}

This is my program code, and the AC has passed.
Your program has some bad habits.
Hope this will be useful to you

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.