20201012 Blue Bridge Training Problem Solution

There are a total of six questions. I only did one that day. It was too difficult. I cried and filled it up until there were four.

A HDU 6555

The meaning of the question: I will give you a number n and ask you whether n/1+n/2+n/3+…n/n is an odd or even number
. Thought: I have no idea. I don’t even bother to read the question. What a nasty word hahaha)
1 1
2 3
3 5
4 8
. . . . .
Observe that the number by which each number increases from the previous number is the number of factors of that number.
It is known that only square numbers have an odd number of factors and non-square numbers have an even number of factors.
Therefore, only the square numbers in 1~n are required. Complexity √n
Below is the AC code

int main() {
    
    
    int T;
    sd(T);
    for(int cas=1;cas<=T;cas++){
    
    
        int n;
        sd(n);
        int ans=0;
        for(int i=1;i*i<=n;i++){
    
    
            ans++;
        }
        if(ans&1) printf("Case %d: odd\n",cas);
        else printf("Case %d: even\n",cas);
    }

	return 0;
}

B HDU 6556

this question. . . . I'm going to vomit.
I wrote a simulation myself and considered a variety of situations. I
wrote it for almost two hours.
Then I converted the 12-digit system into a 24-hour system, and then discussed the situation in seconds. -
Hey, if you consider using the 24-hour system, it's fine...
The following is AC code

map<string,int> mp;
void init(){
    
    
    mp["London"]=0;
    mp["Beijing"]=8;
    mp["Washington"]=-5;
    mp["Moscow"]=3;
}
int main() {
    
    
    init();
    int T;
    sd(T);
    for(int cas=1;cas<=T;cas++){
    
    
        int m,s;
        string a,b,c;
        scanf("%d:%d",&m,&s);
        cin>>a>>b>>c;
        if(a=="AM"&&m==12) m=0;
        if(a=="PM"&&m!=12) m+=12;
        //现在是24小时制了
        printf("Case %d: ",cas);
        m+=mp[c]-mp[b];
        if(m>=24) printf("Tomorrow "),m-=24;
        else if(m<0) printf("Yesterday "),m+=24;
        else printf("Today ");
        //现在是24小时制
        printf("%d:%02d ",m==0?12:(m>12?m-12:m),s);
        if(m>=0&&m<=11) printf("AM\n");//这里整错了- -
        else printf("PM\n");
    }
	return 0;
}

D HDU 6558

A question of probability dp. If you don't see the depth, use memory search.
Note that the search to the end returns 1/p instead of 1! ! ! Because the final success rate is 1/p, pay attention here! ! !
Just write the recursion step by step.
Note that this recursive formula needs to be carefully thought about why it is +1 after two funs instead of outside a fun.

double p;
double dp[1010];
double fun(double q){
    
    
    int i=(int)(q*1000);
    if(dp[i]!=-1) return dp[i];
    if(q==1.0) return 1.0/p;//奇奇怪怪 改成1/p就过了!!!
    double ans=p*(1.0-q)*fun(min(1.0,q+0.02))+(1.0-p)*fun(min(1.0,q+0.015))+1.0;
    return dp[i]=ans;
}
int main() {
    
    
    int T;
    sd(T);
    int cas=0;
    while(T--){
    
    
        for(int i=0;i<=1000;i++) dp[i]=-1;
        scanf("%lf",&p);
        p/=100;
        printf("Case %d: %.10lf\n",++cas,fun(0.02));
    }
	return 0;
}

F CodeForces 26A

I ask you how many numbers from 1 to n are composed of at most two different prime numbers.
First, sieve out all the prime numbers from 1 to 3000,
and then decompose the numbers from 1 to n. There are several different types of prime factors for this number.
output ans for 2 ans++

const int maxn=3010;
int n;
int con[maxn];
int prime[maxn];
int num[maxn];
int main() {
    
    
    cl(con,0);
    int cnt=0;
    for(int i=2;i<=3000;i++){
    
    
        if(con[i]) continue;
        prime[++cnt]=i;
        for(int j=2;i*j<=3000;j++){
    
    
            con[i*j]=1;
        }
    }
    int n;
    sd(n);
    int ans=0;
    rep(i,6,n){
    
    
        int ii=i;
        int t=1;
        for(int j=1;prime[j]<=i&&j<=cnt;j++){
    
    //注意这里加个 j<=cnt!!!
            num[j]=0;
        }
        while(ii){
    
    
            while(ii%prime[t]==0){
    
    
                ii/=prime[t];
                num[t]++;
            }
            t++;
            if(t>cnt) break;
        }
        int sum=0;
        for(int j=1;prime[j]<=i&&j<=cnt;j++){
    
    
            if(num[j]>0) sum++;
            if(sum>2) break;
        }
        if(sum==2) ans++;
    }
    printf("%d\n",ans);
	return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326147707&siteId=291194637