Sorting out Luogu questions

Posted by Monshery on Mon, 23 Dec 2019 18:39:01 +0100

1. Summation of series

It is known that S_n= 1+1/2+1/3 + +1/nSn​=1+1/2+1/3+… +1/n. Obviously, for any integer KK, when nn is large enough, s ﹣ NSN is greater than KK.

In this paper, an integer k k (1 \le k \le 151 ≤ K ≤ 15) is given, which requires a minimum n n to be calculated, so that s_n > KSN > K.

#include<iostream>
using namespace std;

int main()
{
    int K,n=0;
    double S=0.00; //The data type of summation problem S is floating-point data or double precision type
    cin>>K;
    while(S<=K)
    {
        n++;
        S+=(1.0/n);  // Conversion int - > double (1.0/int) exists for data type
    
    }
    cout<<n;
    return 0;
}

2. Three strikes

99 numbers of 1,2, cdots, 91,2,... 9 were divided into 33 groups, which were made up of 33 three digits, and the 33 three digits were made up of a proportion of 1:2:31:2:3. All the 33 three digits satisfying the conditions were calculated.

Note the split of hundreds, tens and ones. Split the digits of three numbers and store them in the array. Each number can only appear once.

#include<iostream>
using namespace std;

int main()
{
	int a[9];
	int p,q,r,s,t,u,v,w,x, z;
	for(int i=1;i<=3;i++)
	{
		for(int j=1;j<=9;j++)
		{
			for(int k=1;k<=9;k++)
			{
				p=i*100+j*10+k;
				q=2*p;
				r=3*p;
				//Hundreds, tens and ones of the second number
				s=q/100;
				t=(q%100)/10;
				u=q%10;
				//Hundreds, tens and ones of the third number
				v=r/100;
				w=(r%100)/10;
				x=r%10;
				a[0]=i;
				a[1]=j;
				a[2]=k;
				a[3]=s;
				a[4]=t;
				a[5]=u;
				a[6]=v;
				a[7]=w;
				a[8]=x;
				z=0;
				for(int m=0;m<9;m++)
				{
					for(int n=m+1;n<9;n++)
					{
					if(a[m]==a[n])
						z=1;
					}
				}
				if(z!=1&&r<=999&&t!=0&&u!=0&&w!=0&&x!=0)
					cout<<p<<" "<<q<<" "<<r<<endl;
			}
		}
	
	}
	return 0;
}


int cf(int x){//We define a function that splits every bit we put together, so it's called split √ 
    while(x!=0){        
        gw=x%10;
        x=(x-gw)/10; //In fact, it can be x/10 completely. For the convenience of understanding, we reduce the bits of X to 0, and then / 10 cut the 0, and continue to split the number of the current period
        d[gw]++;//Counter plus 1
    }
}