2019 Blue Bridge Cup preliminary round


Maximum rainfall

Meaning of the questions:

1-49 to the 49 numbers, requires divided into 7 groups, each consisting of 7 digits, each group is the median score for each group.
The total score is the median score for each group, you can now decide how to group, asking maximum score under the best circumstances it is.

Ideas:

A total of seven groups, each group total score is the score of the median, then the minimum score of three is useless, greedy with 21 to fill a minimum number: 1-21.
For the remaining four groups, each group is the median scores, and therefore each group the minimum number of three is useless, greedy with the remaining number of minimum 12 to fill: 22-33
then the last the total score is the minimum remaining count: 34


Fibonacci sequence and the golden section

Meaning of the questions:

Here Insert Picture Description
n<=2e9

Ideas:

At first glance I thought it was the scope of the data matrix fast power, then there is no modulo identify problems, if I figure out the answer is definitely large numbers.
In fact, the topic has reminded the ratio will approach the golden section.
It found that when the playing table when n is greater than 20, f (n) / f ( n + 1) are 0.61803399, need only count on the line Qi Fibonacci number sequence of 1-21.

code:

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxm=1e4+5;
int f[maxm];
signed main(){
    f[1]=f[2]=1;
    for(int i=3;i<=21;i++){
        f[i]=f[i-1]+f[i-2];
    }
    int n;
    cin>>n;
    if(n>=20){
        n=20;
    }
    printf("%.8f\n",f[n]*1.0/f[n+1]);
    return 0;
}

Reign string

Meaning of the questions:

Xiaoming corresponding figure 1 with the letters A, B corresponding to 2, and so on, with the corresponding Z 26. For more than 27 digital
Xiaoming with two or more strings of bits corresponds to, for example, corresponding to 27 AA, AB corresponding to 28, AZ corresponding to 52, LQ 329 corresponds.
What Will 2019 corresponding string?

Ideas:

A loud noise like a promising 26-band, but soon discovered that the subject is not in 0-25, but 1-26.
When a site is found 26 time (ie mold 26 equal to 0), do not let this carry bit, he changed from 0 to 26 on the line.
This change from the normal 0-25 1-26, A to Z respectively correspond to
other steps and almost normal binary conversion
finally calculate the answer is BYQ

code:

#include<bits/stdc++.h>
using namespace std;
signed main(){
    stack<char>q;
    int n=2019;
    while(n){
        int t=n%26;
        if(t==0){
            q.push('Z');
            n-=26;//少掉一个进位,这里改成减1也可以,效果是一样的
        }else{
            q.push('A'+t-1);
        }
        n/=26;
    }
    while(!q.empty()){
        cout<<q.top();
        q.pop();
    }
    return 0;
}

Postfix expression

Meaning of the questions:

Here Insert Picture Description

Ideas:

Give an example:
0 2
. 1 2. 3
optimal solution. 1 2 3 - -, the postfix expression is converted to infix 3- (1-2), the answer is 4.

This example is to illustrate for purposes of this question, it may be added at any position in parentheses.

If there is no negative sign, the answer is that all numbers and.

Here are negative situation into account.
Because you can parentheses, then you can use a minus sign to direct a bunch of other negative and become positive numbers, so you can directly negative to positive numbers.
However, to consider the special circumstances:
1. When all the numbers are negative, because of the need as a number minuend, so there will be a negative number can not become positive, negative greedy to let the smallest absolute value of positive change.
2. When all the numbers are positive, because at least there must be a negative sign to work, it is necessary to subtract a number, greedy minus the smallest positive number.
At least one example of negative sign acts: x- (yz), a number in brackets should subtract row no matter how

ps:
feel the classified details of the lot, it is easy to overturn.

code:

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxm=2e5+5;
int a[maxm];
int n,m;
signed main(){
    cin>>n>>m;
    int len=n+m+1;
    int e=0;//记录负数的个数
    int ans=0;
    for(int i=1;i<=len;i++){
        cin>>a[i];
        if(a[i]<0)e++;
        ans+=a[i];
    }
    if(m){//如果有负号
        sort(a+1,a+1+len);
        if(e){//如果有负数
            if(e==len){//如果全是负数,那么只有一个负数不会被变成正数
                for(int i=1;i<=len-1;i++){
                    ans-=a[i]*2;
                }
            }else{//否则所有负数都可以变成正数
                for(int i=1;i<=e;i++){
                    ans-=a[i]*2;
                }
            }
        }else{//如果没有负数,因为至少减去一个数,因此贪心地减去最小的
            ans-=a[1]*2;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Takeaway priority

Meaning of the questions:

Here Insert Picture Description

Ideas:

1e5 range of data, if the time is certainly a direct analog timeout.
Because most items 1e5 months, and each store does not affect other stores, so you can consider for each store separately simulation.
Note that when the simulated operating sequence.

code:

#include<bits/stdc++.h>
using namespace std;
const int maxm=1e5+5;
vector<int>g[maxm];
int mark[maxm];
int a[maxm];
signed main(){
    int n,m,T;
    cin>>n>>m>>T;
    for(int i=1;i<=m;i++){
        int ts,id;
        cin>>ts>>id;
        g[id].push_back(ts);
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        sort(g[i].begin(),g[i].end());
        int last=0;
        int now=0;
        int ok=0;
        for(int v:g[i]){
            if(v==last){//同一时间多个订单的情况
                now+=2;
                if(now>5)ok=1;
            }else{
                now-=(v-1)-last;
                if(now<0)now=0;
                if(now<=3)ok=0;//这个要先判断然后再+2
                now+=2;
                if(now>5)ok=1;
                last=v;
            }
        }
        now-=T-last;
        if(now<0)now=0;
        if(now<=3)ok=0;
        if(ok)ans++;
    }
    cout<<ans<<endl;
    return 0;
}

candy

Meaning of the questions:

Here Insert Picture Description

Ideas:

n maximum 100, m up to 20, or a straight binary dfs certainly not enumerated.
Maximum 20 m was found in the voltage range may be shaped, like pressure dp consider solved.
So that d (sta) to reach the state sta requires a minimum number of packages purchased through each packet of sweets to update.
In the initial state d (0) = 0.

code:

#include<bits/stdc++.h>
using namespace std;
const int maxm=105;
int a[maxm];
int d[1<<21];
int n,m,k;
signed main(){
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++){
        int now=0;
        for(int j=1;j<=k;j++){
            int x;
            cin>>x;
            x--;
            now|=(1<<x);
        }
        a[i]=now;
    }
    for(int i=0;i<(1<<m);i++){
        d[i]=1e9;
    }
    d[0]=0;
    for(int i=1;i<=n;i++){
        for(int j=0;j<(1<<m);j++){
            if(d[j]>=n)continue;//实测这里剪一下可以快好多
            d[j|a[i]]=min(d[j|a[i]],d[j]+1);
        }
    }
    int ans=d[(1<<m)-1];
    if(ans==1e9)ans=-1;
    cout<<ans<<endl;
    return 0;
}

RSA decryption

Meaning of the questions:

Here Insert Picture Description

Ideas:

Because C, n is known, calculate the X can be obtained e.

Since n is known, and it is known that only two n prime factors p and q, it is possible to calculate the values of p and q by trial division locally.
Calculated by p = 891234941, q = 1123984201.

Title known by d divided by e (p-1) I (q-1) is the number 1, (p-1) ( q-1) is now known, is set to k, the k = 1001733991047948000 local computing .
The de≡1 (mod k), while the left and right by the inverse element d k d at die sense -1 , the equation becomes e≡d -1 (MOD k)
problem in the conversion mode in order to calculate d k Meanings inverse element.

To know where Euler's theorem:
Let m be a positive integer, a is an integer and gcd (a, m) = 1 , then A [Phi] (m) ≡1 (MOD m)

D is known as the subject (p-1) (q- 1) prime, i.e. d coprime to k, so d [Phi] (k) ≡1 (MOD k), then d * d [Phi] (k) -1 ≡ 1 (mod k).
Obtained in the inverse element d k mold meaning d [Phi] (k) -1 , the calculated [Phi] (k) -1 with the rapid power can then calculate the inverse element d, i.e. e.

Local calculate φ (k) is 267048288597043200.

Because the calculation D [Phi] (k) -1 time, the modulus k is relatively large, it will burst longlongs multiplication, so it needs fast multiplication.
Calculate D [Phi] (K) -1 = 823816093931522017LL.

The subject then directly equation C = X E MOD X n-a can be calculated.
Calculate X = 579706994112328949.

The use and function of a value calculated in the code hanging inside.

code:

#include<bits/stdc++.h>
using namespace std;
#define int long long
int mul(int a,int b,int mod){//快速乘
    int ans=0;
    while(b){
        if(b&1){
            ans=(ans+a)%mod;
        }
        a=(a+a)%mod;
        b>>=1;
    }
    return ans;
}
int ppow(int a,int b,int mod){//快速幂
    int ans=1%mod;
    while(b){
        if(b&1){
            ans=mul(ans,a,mod);
        }
        a=mul(a,a,mod);
        b>>=1;
    }
    return ans;
}
int phi(int n){//计算欧拉函数
    int ans=n;
    for(int i=2;i*i<=n;i++){
        if(n%i==0){
            ans=ans/i*(i-1);
            while(n%i==0)n/=i;
        }
    }
    if(n>1)ans=ans/n*(n-1);
    return ans;
}
int getprime(int n){//试除法
    for(int i=2;i*i<=n;i++){
        if(n%i==0)return i;
    }
    return 1;
}
signed main(){
    int n=1001733993063167141LL;
    int d=212353;
    int C=20190324;
    //
    int p=891234941;//p=getprime(n)
    int q=1123984201;//q=n/p
    int k=1001733991047948000LL;//k=(p-1)*(q-1)
    int phik=267048288597043200LL;//phik=phi(k)
    int invd=823816093931522017LL;//invd=ppow(d,phik-1,k)
    int e=invd;
    int X=579706994112328949LL;//X=ppow(C,e,n);
    cout<<X<<endl;
    return 0;
}

Published 430 original articles · won praise 36 · views 20000 +

Guess you like

Origin blog.csdn.net/weixin_44178736/article/details/104959288