20190915 China Merchants Bank Credit Card

China Merchants Bank Credit Card 20190915

1.

On a number axis, each point 1-n is marked with'L' or'R', and initially there is a robot at each point. Now all robots perform the following operations together 10^100 times at the same time:

If the point is marked with'L', the robot moves to the left; if the point is marked with'R', the robot moves to the right.

Ensure that the point 1 is'R' and the point n is'L'. How many robots are there at each point in the end?

Input description: The input includes a string s that only contains'R' and'L', indicating the mark of each point during initialization.

2<=|s|<=10 to the 5th power, where |s| represents the length of the string.

Test sample:

Input one: RRLRL

The output is: 01211

Input two: RRRRRLRLRL

Output: 0000331111

analysis:

Look at the parity of the nearest L to the right of each R, the subscript difference, odd numbers are +1 on R to the left of L, and even numbers are +1 on L. L is the same.

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<sstream>
#include<cmath>
#include<climits>
#include<queue>
#include<cstring>
#include<set>
using namespace std;
queue<int> rque,lque;
string str;
vector<int> count1(100005,0);
int main(){
    cin>>str;
	//scanf("\n",&str);
	int n=str.size();
	for(int i=0;i<n;i++){
        if(str[i]=='R'){
            rque.push(i);
        }
        else{
            while(!rque.empty()){
                int temp=rque.front();
                rque.pop();
                if((i-temp)&1!=0)
                    count1[i-1]++;
                else
                    count1[i]++;
            }
        }
    }
    for(int i=n-1;i>=0;i--){
        if(str[i]=='L'){
            lque.push(i);
        }
        else{
            while(!lque.empty()){
                int temp=lque.front();
                lque.pop();
                if((temp-i)&1!=0){
                    count1[i+1]++;
                }
                else
                    count1[i]++;
            }
        }
    }
	for(int i=0;i<n;i++)
	    printf("%d ",count1[i]);
    printf("\n");
	//system("PAUSE");
	return 0;
}

2.

A string composed of numbers and ?,? Can represent 0-9, find the number of digits that can be represented by this string and the remainder is 5 after the remainder.

After 40%, first provide a general idea.

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<sstream>
#include<cmath>
#include<climits>
#include<queue>
#include<cstring>
#include<set>
#define mod 1000000007
using namespace std;
string str;
vector<vector<int> > dp(100005,vector<int>(13,0));
int main(){
    cin>>str;
	int n=str.size();
    int base=0;
	for(int i=n-1;i>=0;i--){
        if(str[i]=='?'){
            vector<int> tmp(13,0);
            for(int j=0;j<10;j++){
                tmp[((int)pow(10,base)*j)%13]++;
            }
            if(i+1>=n){
                for(int k=0;k<13;k++){
                    dp[i][k]=tmp[k];
                }
                base++;
                continue;
            }
            for(int j=0;j<13;j++){
                for(int k=0;k<13;k++){
                    long long ans=(dp[i+1][j]*tmp[k])%mod;
                    int index=(j+k)%13;
                    dp[i][index]=(dp[i][(j+k)%13]+ans)%mod;
                }
            }
        }
        else{
            int num=str[i]-'0';
            int tmp=((int)pow(10,base)*num)%13;
            //cout<<tmp<<endl;
            if(i+1>=n){
                dp[i][tmp]++;
                base++;
                continue;
            }
            for(int j=0;j<13;j++){
                //dp[i][(j+tmp)%13]=(dp[i][(j+tmp)%13]+dp[i+1][j]+1)%mod;
                dp[i][(j+tmp)%13]=dp[i+1][j];
            }
        }
        base++;
    }
	printf("%d\n",dp[0][5]);
    /*for(int i=0;i<n;i++){
        for(int j=0;j<13;j++)
        printf("%d ",dp[i][j]);
        printf("\n");
    }*/
	//system("PAUSE");
	return 0;
}

 

Guess you like

Origin blog.csdn.net/LXQ1071717521/article/details/101769579