2021-09-20 swipe questions and punch in every day

OJ p2018 cow story Problem description There is a cow. I...
Title Description
Input format
Output format
Input and output samples
Title Description
Input and output samples

OJ

p2018 cow story

Problem description

There is a cow. It gives birth to a heifer every year. Each heifer starts from the fourth year and gives birth to a heifer at the beginning of each year. Please program how many cows are there in the nth year?

input

The input data consists of multiple test cases, each of which occupies one line, including an integer n (0 < n < 55). The meaning of n is described in the title.
n=0

output

For each test case, the number of cows in year n is output.

Sample input

2 4 5 0

Sample output

2 4 6

This question is very similar to the undead rabbit we came into contact with before, but the undead rabbit can start giving birth one year after birth. It takes four years for cattle here to start giving birth. But in fact, the ideas of the two questions are very similar to the Fibonacci sequence. The divine rabbit is the Fibonacci sequence, that is, starting from the third number, each number is the sum of the first two digits. Here is: starting from the fifth number, each number is the sum of the previous number and the first three numbers. It's easy to find the law.

#include<iostream> using namespace std; #include<vector> #include<algorithm> #include<list> #include<string> #include<map> #include <set> #include <iomanip> int main() { vector<int>v; vector<int>math; int n,a,b; cin >> n; v.resize(n+4); v[0]=1; v[1]=2; v[2]=3; v[3]=4; while (n != 0) { if (n <= 4) { math.push_back(n); } else { for (int i = 4; i < n; i++) { v[i] = v[i-1] + v[i-3]; } math.push_back(v[n-1]); } cin >> n; } for (auto i : math) { cout << i << endl; } return 0; }

Luogu  

P1428 little fish is more lovely than

Title Description

People are more angry than people; Fish is harder to die than fish. Xiaoyu recently participated in a "more lovely" competition, which compares the loveliness of each fish. The participating fish are arranged in a row from left to right, with their heads facing to the left, and then each fish will get an integer value to indicate the loveliness of the fish. Obviously, the larger the integer is, the lovelier the fish is, and the loveliness of any two fish may be the same. Because all the fish heads face to the left, each fish can only see the loveliness of the fish on its left. They are calculating how many fish are not as lovely as themselves within their own eyesight. Please help these lovely little fish who don't have enough brains to calculate.

Input format

Enter an integer on the first line   nn, indicating the number of fish.

Input in the second line   nn   An integer, separated by spaces, representing the loveliness of each small fish from left to right.

Output format

Inline output   nn   An integer, separated by spaces, in turn indicates how many fish in each small fish's eyes are not as lovely as themselves.

Input and output samples

Enter #1

6 4 3 0 5 1 2

Output #1

0 0 0 3 1 2

Each time you enter a number, see how many numbers in the container are smaller than yourself.

#include<iostream> using namespace std; #include<vector> #include<algorithm> #include<list> #include<string> #include<map> #include <set> #include <iomanip> int main() { int n, num,myself,sum=0; vector<int>v; vector<int>math; cin >> n; while (n--) { cin >> num; myself = num; v.push_back(num); for (int i = 0; i < v.size() - 1; i++) { if (myself > v[i]) { sum++; } } math.push_back(sum); sum = 0; } for (int i : math) { cout << i << " "; } return 0; }

P5744 [deep foundation 7. Learning 9] training  

Title Description

The trainees of a training institution have the following information:

  • Name (string)
  • Age (one year old, integer)
  • Last year's NOIP score (integer and guaranteed to be a multiple of 5)

After a one-year training, the scores of all students have improved by 20% (of course, the full score of NOIP is 600, which can not be exceeded).

To input student information, please design a structure to store these student information, and design a function to simulate the training process. Its parameters are such structure types, return the same structure types, and output student information.

Input and output samples

Enter #1

3 kkksc03 24 0 chen_zhe 14 400 nzhtl1477 18 590

Output #1

kkksc03 25 0 chen_zhe 15 480 nzhtl1477 19 600

Pay attention to add 1 to the age, multiply the score by 1.2, and output it in turn

#include<iostream> using namespace std; #include<vector> #include<algorithm> #include<list> #include<string> #include<map> #include <set> #include <iomanip> int main() { int n, a, sc; cin >> n; vector<int>age; vector<string>name; vector<double>score; string na; int i = 0; while (i < n) { cin >> na; cin >> a; cin >> sc; sc *= 1.2; if (sc > 600) { sc = 600; } a++; name.push_back(na); age.push_back(a); score.push_back(sc); i++; } for (int i = 0; i < n; i++) { cout << name[i] << " " << age[i] << " " <<score[i] << endl; } return 0; }

21 September 2021, 06:05 | Views: 9989

Add new comment

For adding a comment, please log in
or create account

0 comments