[Good question] Good question sharing

 

1001-Rounding_Array Simulation, Enumeration, Greedy Exercises (nowcoder.com)

topic description

Rounding is a good thing. For example, if you only scored 45 points in the test, after rounding up, you get 50 points and then rounding up, you will get a full score! qdgg just finished the topology test. The results are very unsatisfactory. But the teacher felt that it was not easy for him to listen to the class seriously every day. So he decided to give him a chance to improve his grades: let his grades be rounded at any position after the decimal point (or rounded to the nearest integer).
But there are limits. qdgg can only round t times. Please help qdgg find the highest score he can achieve in no more than t rounds. Note that he can choose not to use all t chances. Furthermore, he can even choose not to round the grades at all.
In this problem, the classic rounding rules are used: when rounding a number to the nth digit, one has to look at the number n+1, and if it is less than 5, the nth digit is left unchanged, while all subsequent digits are replaced by is 0. Otherwise, if the n+1 digits are greater than or equal to 5, the digit at position n will be incremented by 1 (if this digit is equal to 9, this may change some other digits as well), and all subsequent digits will be Replace with 0. Finally, all trailing zeros are discarded.
For example, if the number 1.14 is rounded to the first decimal place, the result is 1.1, while if 1.5 is rounded to the nearest whole number, the result is 2. The number 1.299996121 rounded to the fifth decimal place will give the number 1.3.

Enter a description:

The first line of input contains two integers n and t indicating the length of the decimal (including the decimal point) and the number of times of rounding. 

The second line is a string representing the initial score of qdgg.

Output description:

One line represents the highest score that qdgg can get (do not output trailing zeros)

1012-Blocks and storage boxes_Nuke Contest Grammar Introductory Class Array Simulation, Enumeration, Greedy Exercises (nowcoder.com)

 Now there is a storage box of size n*1. We have countless small squares of size 1*1 and 2*1 in our hands. We need to fill the storage box with these squares. How many different ways do we have to fill it up? this storage box

Enter a description:

The first line is the number of samples T, 
and the 2nd to 2+T-1 lines each have an integer n (n<=80), describing n in each sample.

Output description:

For each sample output the corresponding number of methods
#include <iostream>
using namespace std;

long long a[90];

int main()
{
    a[0] = 1;
    a[1] = 1;
    int n;
    cin >> n;
    for(int i = 2;i <= 80;i ++)
    {
        a[i] = a[i-1] + a[i-2];
    }
    while(n --)
    {
        int x;
        cin >> x;
        cout << a[x] << endl;
    }
}

Time (time) (nowcoder.com)

topic description

         Apojacsleam is someone who loves special moments.

        He defined a time, if the electronic watch displays ab:ba (24-hour clock), then the time is a "palindrome time" (may have leading zeros). For example, 00:00 is the palindrome time.

        Given a moment, find the previous and next palindromic moments of this moment.

Additional question J: 00:00 is 24:00, there is no such moment as 24:00

Additional question J: The input may have a leading 0, but the output does not have a leading 0. For example, 10:1 means 10:01, and the output of 10:10 is 10:10 

Enter a description:

Two positive integers, separated by ":", represent hours and minutes, and the input time is guaranteed to be legal.

Output description:

Two lines, two moments (without the leading 0), separated by ":", indicating the previous moment and the next moment
#include <cstdio>

using namespace std;

int main() {
    int a, b, A, B;
    scanf("%d:%d", &a, &b);
    A = a, B = b;
    while (true) {
        b--;       //找之前的时间
        if (b < 0) //回到上个小时
            a--;
        b = (b + 60) % 60; //防止负数
        a = (a + 24) % 24;
        if (a % 10 == b / 10 && b % 10 == a / 10) {//回文
            printf("%d:%d\n", a, b);
            break;
        }
    }
    while (true) {
        B++;         //找之后的时间
        if (B == 60) //去到下个小时
            A++;
        B = (B + 60) % 60;
        A = (A + 24) % 24;
        if (A % 10 == B / 10 && B % 10 == A / 10) {
            printf("%d:%d\n", A, B);
            break;
        }
    }
    return 0;
}

 "Water" huge waves (nowcoder.com)

This question does not require the output of leading 0, if you want to output leading 0 , you can use %02d (width is 2, the left end is filled with 0) 

topic description

Patchouli has mastered a water attribute magic

Before that, she had endured the goblins on the lake of mist for a long time

Now, she decided to fight back!

There are n goblins lined up on the lake of fog, and the flying height of each goblin increases strictly monotonically, and the height is 1≤x≤1000

Patchouli can clear the goblins in a continuous subrange in the column, if and only if they are cleared, Patchouli can still restore the flying heights of all goblins in this subrange

For example, if the flying heights of the goblins are 1, 3, 4, 5, 6, and 8, then the two goblins with flying heights of 4 and 5 can be cleaned up, because after cleaning, the data between the two spaces is uniquely determined

Paqiuli can choose to clear at most one continuous subinterval at a time. How many fairies can Paqiuli clear at one time?

Enter a description:

The first line has an integer n, indicating that there are n fairies, and the next line has n numbers ai, indicating the flying height of each fairy

Output description:

Output a line, an integer represents the answer
#include<iostream>
using namespace std;
const int N=1010;
int a[N];
int main()
{
    int n,max1=0,b=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    a[n+1]=1001;
    for(int i=1;i<=n;i++)
    {
        int j=0;
        while(a[i]+1==a[i+1]&&a[i]-a[i-1]==1)//双指针算法  
        {                                    //这里要用while 而不是if
            j++;
            i++;
        }
        max1=max(max1,j);//取最大值
    }
    printf("%d",max1);
    return 0;
}

Problem - 1777A - Codeforces

The title of cf is wonderful, some can not be written according to its literal meaning

If you write like this, it will explode 

Because a[i+1]*=a[i] is not suitable

#include<iostream>
using namespace std;
const long long N=100010;
long long a[N];
int main()

{
	long long t;
	cin>>t;
	while(t--){
		long long n,num=0;
		cin>>n;
		for(long long i=0;i<n;i++)
		{
			cin>>a[i];
		}
		for(long long i=0;i<n-1;i++)
		{
			if(a[i]%2==0&&a[i+1]%2==0||a[i]%2==1&&a[i+1]%2==1)
			{
				num++;
				a[i+1]*=a[i];
			}
		}
		cout<<num<<endl;
	}
}


 correct solution

#include<iostream>
using namespace std;
const long long N=100010;
long long a[N];
int main()

{
	long long t;
	cin>>t;
	while(t--){
		long long n,num=0;
		cin>>n;
		for(long long i=0;i<n;i++)
		{
			cin>>a[i];
		}
		for(long long i=0;i<n-1;i++)
		{
			if(a[i]%2==0&&a[i+1]%2==0||a[i]%2==1&&a[i+1]%2==1)
			{
				num++;
				//a[i+1]*=a[i];
			}
		}
		cout<<num<<endl;
	}
}

Code over!

Guess you like

Origin blog.csdn.net/m0_72853403/article/details/129007242