week7

Day 1

蓝桥杯模拟赛 4

 

[蓝桥杯 2022 省 B] 刷题统计

思路:统计有多少整周,再统计最后一周的天数
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
const int N=1e5+10,INF=1e9,M=1e5+10;

int main(){
    cin.tie(0),cout.tie(0);
    ll a,b,n,ans=0;
    cin>>a>>b>>n;
    ans+=(n/(5*a+2*b)*7);
    n%=(5*a+2*b);
    if(n!=0){
        int t=n/a;
        if(t>5){
            ans+=5;
            n-=(a*5);
            ans+=(n/b);
            if(n%b)ans++;
        }
        else{
            ans+=t;
            if(n%a)ans++;
        }
    }
    cout<<ans;

    return 0;
}
View Code
 

[蓝桥杯 2022 国 B] 齿轮

思路:由公式v=wr,得到最左边的半径是最右边半径的q倍;i从1到最大半径/q枚举r数组中是否存在i*q;或者求出r中所有存在的倍数,将r从小到大排序,ri的约数,若在r数组中存在,则存下其倍数
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
const int N=2e5+5;
int n,q,r[N],t;
bool a[N];
int main(){
    cin.tie(0),cout.tie(0);
    cin>>n>>t;
    int ma=0;
    for(int i=1;i<=n;++i){
        cin>>r[i];a[r[i]]=true;
        ma=max(r[i],ma);
    }
    while(t--){
        cin>>q;
        bool ok=false;
        for(int i=1;i<=ma/q;++i){
            if(a[i]&&a[i*q]){
                ok=true;
                break;
            }
        }
        if(ok)cout<<"YES\n";
        else cout<<"NO\n";
    }
    return 0;
}
View Code

 

 [蓝桥杯 2022 省 A] 求和

思路:求所有ai乘上a[i+1,...,n]的和
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
const int N=2e5+10,INF=1e9,M=1e5+10;
ll n,a[N],s[N];
int main(){
    cin.tie(0),cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;++i){
        cin>>a[i];
        s[i]=s[i-1]+a[i];
    }
    ll ans=0;
    for(int i=1;i<n;++i){
        ll b=a[i]*(s[n]-s[i]);
        ans+=b;
    }
    cout<<ans;
    return 0;
}
View Code

 

[蓝桥杯 2022 省 B] 修建灌木

思路:最高高度为修剪一个轮回的长度
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
const int N=2e5+10,INF=1e9,M=1e5+10;
int n;
int main(){
    cin.tie(0),cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;++i){
        if(i<=n/2){
            cout<<(n-i)*2<<'\n';
        }
        else{
            cout<<(i-1)*2<<'\n';
        }
    }
    return 0;
}
View Code

 

[蓝桥杯 2022 省 B] 李白打酒加强版

思路:dp
f[i,j,k]:  状态表示:所有遇花i次,到店j次,酒k斗的种类   
      状态计算:1.到店,=f[i,j-1,k/2]   2.遇花,=f[i-1,j,k+1]
初始化:f[i,j,k]=0,f[0,0,2]=1
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
const int N=110,M=1e9+7;
int n,m,f[N][N][N];
int main(){
    cin.tie(0),cout.tie(0);
    cin>>m>>n;
    for(int i=0;i<=n;++i){
        for(int j=0;j<=m;++j){
            for(int k=0;k<N;++k){
                if(i==0&&j==0&&k==2)
                    f[i][j][k]=1;
                if(i==0&&j==0)continue;
                if(i>0)
                    f[i][j][k]=(f[i][j][k]+f[i-1][j][k+1])%M;
                if(j>0&&k%2==0)
                    f[i][j][k]=(f[i][j][k]+f[i][j-1][k/2])%M;
            }
        }
    }
    cout<<f[n-1][m][1];
    return 0;
}
View Code

 

 

[蓝桥杯 2022 国 C] 斐波那契数组

思路:斐波那契数组都满足a0=a1,且an=an-1+an-2,若数组不同,它们都呈倍数关系,求出前n项斐波那契数组,记录次数最多的倍数,可使修改次数最小
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
const int N=1e5+10,INF=1e9,M=1e6+10;
ll n,a[M],b[N];
int main(){
    cin.tie(0),cout.tie(0);
    cin>>n;
    b[1]=b[2]=1;
    for(int i=3;i<=n;++i){
        b[i]=b[i-1]+b[i-2];
    }
    ll ans=0,x,ma=0;
    for(int i=1;i<=n;++i){
        cin>>x;
        ma=max(ma,x);
        if(x%b[i]==0)
            a[x/b[i]]++;
    }
    for(int i=1;i<=ma;++i){
        ans=max(ans,a[i]);
    }
    cout<<n-ans;
    return 0;
}
View Code

 

 

[蓝桥杯 2022 省 A] 数的拆分

思路:引理:如果能把一个数表示为x1y1*x2y2(y1,y2>=2) 的形式,那么一定可以表示为 u2v3 的形式。
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
const int N=4010;
int prime[N],tot;
bool not_prime[N];
void init(int n){
    for(int i=2;i<=n;++i)
        if(!not_prime[i]){
            prime[++tot]=i;
            for(int j=i+i;j<=n;j+=i)not_prime[j]=true;
        }
}
bool check(ll x)
{
    ll y = pow(x, 0.5);
    if(y * y == x || (y + 1) * (y + 1) == x)
        return true;
    y = pow(x, 1.0 / 3);
    if(y * y * y == x || (y + 1) * (y + 1) * (y + 1) == x || (y + 2) * (y + 2) * (y + 2) == x)
        return true;
    return false;
}
int main(){
    cin.tie(0),cout.tie(0);
    init(4000);
    int t;
    cin>>t;
    while(t--){
        ll x;
        cin>>x;
        if(check(x)){
            cout<<"yes\n";
            continue;
        }
        bool ok=true;
        for(int i=1;i<=tot;++i){
            if(x%prime[i]==0){
                int cnt=0;
                while(x%prime[i]==0){
                    cnt++;x/=prime[i];
                }
                if(cnt==1){
                    ok=false;
                    break;
                }
            }
        }
        if(ok&&check(x)){
            cout<<"yes\n";
        }
        else cout<<"no\n";
    }
    return 0;
}
View Code

 

 

[蓝桥杯 2022 国 B] 卡牌

 
思路:将每种卡牌按卡牌数从小到大排序,每次增加前i种的卡牌,加到与i+1种卡牌数目相同,直到m减到小于i时加不了了,当加到第n种卡牌时,加m/n副牌
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
const int N=2e5+5;
ll n,m,a[N],b[N];
int main(){
    cin.tie(0),cout.tie(0);
    cin>>n>>m;
    ll mma=1e9;
    for(int i=1;i<=n;++i)cin>>a[i];
    for(int i=1;i<=n;++i){
        cin>>b[i];
        mma=min(mma,a[i]+b[i]);
    }
    ll ans=0;

    sort(a+1,a+n+1);
    for(int i=1;i<=n;++i){
        if(i==n){
            ans+=m/n;
            break;
        }
        ll t=a[i+1]-a[i];
        if(m>=i&&t!=0){
            ans=a[i]+min(t,m/i);
            m=m-min(t*i,m/i*i);
        }
        if(m<i||ans>=mma)break;
    }
    cout<<min(ans,mma);
    return 0;
}
View Code

 

 

 Day3

SMU Winter 2023 Round #13 (Div.2)

B - BM 算日期

思路:求出范围内闰年个数

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
const int N=1e5+5,M=1e9+7;
int t,a,y;
int main(){
    cin.tie(0),cout.tie(0);
    cin>>t;
    while(t--){
        cin>>y>>a;
        int b=y+a;
        if(b>9999)b=9999-(b-9999);
        if(b<y)swap(y,b);
        int ans=0;
        for(int i=y;i<=b;++i)
            if(i%4==0&&i%100!=0||i%400==0)ans++;
        cout<<ans<<'\n';
    }
    return 0;
}
View Code

 

C - BBpigeon Counting Trees

思路:计算一层的节点分配给上一层节点的种类,包括不分,将每层的种类相乘即为答案。

 

 

 

 

 

D - Palindrome Hard Problem

思路:所有字符串长度和即为答案

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
const int N=1e3+5,M=1e9+7;
int n;
int main(){
    cin.tie(0),cout.tie(0);
    string a;
    cin>>n;
    int s=0;
    for(int i=1;i<=n;++i){
        cin>>a;
        s+=a.size();
    }
    cout<<s;
    return 0;
}
View Code

 

E - BM 充饥

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
const int N=1e5+5,M=1e9+7;
string a;
int main(){
    cin.tie(0),cout.tie(0);
    cin>>a;
    cout<<" __      _____\n"
          "|  | ___/ ____\\____\n"
          "|  |/ /\\   __\\/ ___\\\n"
          "|    <  |  | \\  \\___\n"
          "|__|_ \\ |__|  \\___  >\n"
          "     \\/           \\/";
    return 0;
}
View Code

 

F - kita 买礼物

思路:多重背包用二进制优化为01背包

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
const int N=3e6+5,M=1e9+7;
int n,m,v[N],b[N],a[100005];
bool f[N];
int main(){
    cin.tie(0),cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;++i)cin>>a[i];
    int c=0;
    for(int i=1;i<=n;++i){
        int k,s=1;
        cin>>k;
        while(s<=k){
            c++;
            v[c]=a[i]*s;
            k-=s;
            s*=2;
        }
        if(k>0){
            c++;
            v[c]=a[i]*k;
        }
    }
    n=c;
    f[0]=true;
    for(int i=1;i<=n;++i){
        for(int j=m;j>=1;--j){
            if(j>=v[i])
                f[j]|=f[j-v[i]];
        }
    }

    int ans=0;
    for(int i=1;i<=m;++i){
        ans+=f[i];
    }
    cout<<ans;
    return 0;
}
View Code

 

G - New Game

思路:拓扑排序,编号小的尽可能在前,用小根堆

#include<bits/stdc++.h>
using namespace std;
const int maxn=2e3+100;
const int inf=0x3f3f3f3f;
inline int rd() {
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch>'9') {
        if (ch == '-')f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}
int t;
int n,m;
vector<int>ve[maxn],res;
int a,b,in[maxn];

signed main() {
    t=rd();
    while(t--) {
        for(int i=1; i<=n; i++)ve[i].clear();
        memset(in,0,sizeof in);
        n=rd();
        m=rd();
        for(int i=1; i<=m; i++) {
            a=rd();
            b=rd();
            ve[a].push_back(b);
            in[b]++;
        }
        priority_queue<int,vector<int>,greater<int> >q;
        for(int i=1; i<=n; i++) {
            if(!in[i]) {
                q.push(i);
            }
        }
        while(!q.empty()) {
            int u=q.top();
            q.pop();

            res.push_back(u);
            for(int i=0; i<ve[u].size(); i++) {
                int v=ve[u][i];
                in[v]--;
                if(!in[v]) {
                    q.push(v);
                }
            }
        }
        for(int i=0; i<res.size(); i++) {
            if(i!=0)printf(" ");
            printf("%lld",res[i]);
        }
        printf("\n");
        res.clear();
    }
    return 0;
}
View Code

 

H - Hsueh- Draw Progress

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
const int N=1e5+5,M=1e9+7;
int t,n,m;
int main(){
    cin.tie(0),cout.tie(0);
    cin>>t;
    while(t--){
        cin>>n>>m;cout<<'[';
        for(int i=1;i<=n;++i)
        {
            if(i<=m)cout<<'#';
            else cout<<'-';
        }cout<<']'<<' ';
        cout<<(m*100)/n<<'%'<<'\n';
    }
    return 0;
}
View Code

 

I - BM 旅游

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
const int N=1e5+5,M=1e9+7;

int main(){
    cin.tie(0),cout.tie(0);
    ll n;
    int ans=0;
    for(int i=1;i<=4;++i){
        cin>>n;
        int s=0;
        while(n){
            s+=(n%10);
            n/=10;
        }
        if(s>=16||s==6)ans++;
    }
    if(ans==1)cout<<"Oh dear!!";
    else if(ans==2)cout<<"BaoBao is good!!";
    else if(ans==3)cout<<"Bao Bao is a SupEr man///!";
    else if(ans==4)cout<<"Oh my God!!!!!!!!!!!!!!!!!!!!!";
    else cout<<"Bao Bao is so Zhai......";
    return 0;
}
View Code

 

J - 大扫除

思路:不同行中的种类都不同

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
const int N=1e5+5,M=1e9+7;
map<char,int>ma;
int main(){
    cin.tie(0),cout.tie(0);
    int t,n;
    cin>>t;
    while(t--){
        cin>>n;
        int s=0;
        string a;
        for(int i=1;i<=n;++i){
            ma.clear();
            cin>>a;
            for(int j=0;j<a.size();++j)
                if(a[j]!='.'&&ma.count(a[j])==0){
                        s++;ma[a[j]]++;
                }
        }
        cout<<s<<'\n';
    }
    return 0;
}
View Code

 

K - Kwords Find Kth Element

 思路:将所有序列排列,二分答案,看二分求出的选取序列中小于等于答案的数的个数是否等于k

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>PII;
const int N=1e5+5;
typedef long long ll;

int read(){
    int x = 0 , ch = getchar();
    while( ch < '0' || ch > '9' ) ch = getchar();
    while( ch >= '0' && ch <= '9' ) x = ( x << 3 ) + ( x << 1 ) + ch - '0' , ch = getchar();
    return x;
}
int n,m,k;
int b[N];
bool check(int x,vector<int>c[]){
    int cnt=0,q=0;
    for(int i=0;i<m;++i){
        q= upper_bound(c[b[i]-1].begin(),c[b[i]-1].end(),x)-c[b[i]-1].begin();
        cnt+=q;
    }
    if(cnt>=k)return true;
    return false;
}
int main(){
    cin.tie(0),cout.tie(0);
    n=read();
    vector<int>a[n];
    for(int i=0;i<n;++i){
        m=read();
        int x;
        for(int j=0;j<m;++j){
            x=read();
            a[i].push_back(x);
        }
    }
    for(int i=0;i<n;++i)sort(a[i].begin(),a[i].end());
    int q;
    q=read();
    while(q--){
        m=read();
        for(int i=0;i<m;++i)cin>>b[i];
        k=read();
        int l=1,r=1e9;
        while(l<r){
            int mid=l+r>>1;
            if(check(mid,a))r=mid;
            else l=mid+1;
        }
        cout<<l<<'\n';
    }
    return 0;
}
View Code

 

 


 

 

 Day5

SMU Winter 2023 Round #14 (Div.1+2)

 https://www.cnblogs.com/bible-/p/17056812.html 中 → SMU Winter 2023 Round #7 (Div.2)

 

 

 

posted @ 2023-02-13 21:07  bible_w  阅读(68)  评论(0编辑  收藏  举报