Algorithm-Basic Primer

Source: Internet
Author: User

Introductory Training Fibonacci Series

Problem description

The recursive formula for the Fibonacci sequence is: Fn=fn-1+fn-2, wherein f1=f2=1.

When n is large, FN is also very large, and now we want to know what the remainder of FN divided by 10007 is.

Input format

The input contains an integer n.

Output format

The output line contains an integer that represents the remainder of FN divided by 10007.

Note: In the subject, the answer is to require FN divided by 10007 of the remainder, so as long as we can calculate the remainder can be, and do not need to calculate the exact value of FN, and then divide the calculated results by 10007 to take the remainder, the direct calculation of the remainder is often more than the original number of the first and then take more simple.

Sample input

10

Sample output

55

Sample input

22

Sample output

7704

Data size and conventions

1 <= n <= 1,000,000.

#include <iostream>

using namespace Std;

const int mod=10007;

const int maxn=1000000;

int F[MAXN];

int main ()

{

F[1]=f[2]=1;

int n;

cin>>n;

for (int i=3;i<=n;i++)

{

F[i]= (f[i-1]+f[i-2])%mod;

}

cout<<f[n];

return 0;

}

Basic Practice Letter Graphics

Problem description

Using letters to make some beautiful graphics, here's an example:

ABCDEFG

Babcdef

Cbabcde

Dcbabcd

Edcbabc

This is a 5 row 7-column graph, find out the pattern of the graph, and output an n-row m-column graph.

Input format

Enter a row that contains two integers n and m, representing the number of columns of the number of rows of the graph you want to output.

Output format

Output n lines, each m characters, for your graphics.

Sample input

5 7

Sample output

ABCDEFG

Babcdef

Cbabcde

Dcbabcd

Edcbabc

Data size and conventions

1 <= N, M <= 26.

#include <iostream>

using namespace Std;

int main ()

{

int n,m;

cin>>n>>m;

int array[n][m];

for (int i=0;i<n;i++)

{

Array[i][0]=65+i;

}

for (int j=0;j<m;j++)

{

Array[0][j]=65+j;

}

for (int i=1;i<n;i++)

{

for (int j=1;j<m;j++)

{

ARRAY[I][J]=ARRAY[I-1][J-1];

}

}

for (int i=0;i<n;i++)

{

for (int j=0;j<m;j++)

{

cout<< (char) array[i][j];

}

cout<<endl;

}

return 0;

}

Basic Practice Series Features

Problem description

Give the number of N to find the maximum, the minimum, and the number of N.

Input format

The first behavior is an integer n, which represents the number of numbers.

The second line has n number, for the given n number, the absolute value of each number is less than 10000.

Output format

Output three lines, one integer per line. The first row represents the largest of these numbers, the second row represents the smallest of these numbers, and the third row represents the number's and.

Sample input

5

1 3-2 4 5

Sample output

5

-2

11

Data size and conventions

1 <= N <= 10000.

#include <iostream>

using namespace Std;

int main ()

{

int n;

int max,min,sum=0;

cin>>n;

int array[10000];

for (int i=0;i<n;i++)

{

cin>>array[i];

}

max=-10000;min=10000;

for (int i=0;i<n;i++)

{

if (Array[i]>max)

{

Max=array[i];

}

if (array[i]<min)

{

Min=array[i];

}

Sum+=array[i];

}

cout<<max<<endl;

cout<<min<<endl;

cout<<sum;

return 0;

}

Note-10000 and 10000

Algorithm-Basic Primer

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.