首页 > 其他分享 >winter 2024 day1

winter 2024 day1

时间:2024-01-22 18:15:58浏览次数:30  
标签:typedef const winter int double long day1 2024 define

2024 蓝桥杯模拟赛 1 (div1)

 

 =.= ^-^

 

A[蓝桥杯 2021 国 BC] 大写

思路:小写转换大写
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
#define double long double
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=100+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353;
const double eps=1e-6;


void solve(){
    string s;
    cin>>s;
    for(int i=0;i<s.size();++i){
        if(s[i]>='a'&&s[i]<='z')s[i]-=32;
        cout<<s[i];
    }
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
View Code

 

 B[传智杯 #4 决赛] 小智的疑惑

思路:暴力判断
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
#define double long double
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=100+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353;
const double eps=1e-6;


void solve(){
    string s;
    string f="chuanzhi";
    cin>>s;
    int ans=0;
    for(int i=0;i+7<s.size();++i){
        if(s[i]=='c'){
//            cout<<i<<':'<<s[i]<<'\n';
            bool ok=true;
            for(int j=i,x=0;x<f.size();++x,++j){
                if(f[x]!=s[j]){
                    ok=false;
                    break;
                }
            }
            if(ok)ans++,i+=7;
        }
    }
    cout<<ans;
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
View Code

 

C[蓝桥杯 2017 省 B] 日期问题

思路:枚举所有情况勒,需判断日期是否合法,且日期不重复
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
#define double long double
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=100+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353;
const double eps=1e-6;


void solve(){
    map<string,string>mp;
    mp["01"]="31",mp["02"]="29",mp["03"]="31",mp["04"]="30",mp["05"]="31";
    mp["06"]="30",mp["07"]="31",mp["08"]="31",mp["09"]="30",mp["10"]="31";
    mp["11"]="30",mp["12"]="31";
    string s;
    cin>>s;
    string a=s.substr(0,2),b=s.substr(3,2),c=s.substr(6,2);
    string aa,bb,cc;
    vector<string>ss(3);
    if(a<="59")aa="20"+a;
    else aa="19"+a;
    bb=b,cc=c;
    ss[0]=aa+"-"+bb+"-"+cc;

    if(c<="59")cc="20"+c;
    else cc="19"+c;
    aa=a,bb=b;
    ss[1]=cc+"-"+aa+"-"+bb;
    ss[2]=cc+"-"+bb+"-"+aa;

    sort(ss.begin(),ss.end());
    map<string,string>st;
    for(int i=0;i<3;++i){
        a=ss[i].substr(5,2),b=ss[i].substr(8,2);
        c=ss[i].substr(0,4);
        if(!(a>="01"&&a<="12"))continue;
        int y=stoi(c);
        if((y%4==0&&y%100!=0)||y%400==0)mp["02"]="29";
        else mp["02"]="28";
        if(b>mp[a]||b=="00")continue;
        if(st.count(ss[i]))continue;
        cout<<ss[i]<<'\n';
        st[ss[i]]=1;
    }
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
View Code

 

D[蓝桥杯 2023 省 B] 冶炼金属

思路:转换率的最大值为a/b的最小值,最小值为a/(b+1)+1的最大值
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
#define double long double
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=100+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353;
const double eps=1e-6;


void solve(){
    int n;cin>>n;
    vector<PII>ve(n);
    for(int i=0;i<n;++i)cin>>ve[i].first>>ve[i].second;
    int ma=1e9,mi=0;
    for(int i=0;i<n;++i){
        ma=min(ma,ve[i].first/ve[i].second);
        mi=max(mi,ve[i].first/(ve[i].second+1)+1);
    }
    cout<<mi<<' '<<ma;
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
View Code

 

E[蓝桥杯 2015 省 A] 饮料换购

思路:记录每次换瓶子后的瓶盖数,统计换得的总瓶子数即可
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
#define double long double
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=100+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353;
const double eps=1e-6;


void solve(){
    int n;cin>>n;
    int ans=n,l=n,c;
    while(l>=3){
        c=l/3;
        l-=2*c;
        ans+=c;
    }
    cout<<ans;
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
View Code

 

F[蓝桥杯 2017 省 AB] 分巧克力

思路:二分边长a,一个矩形中正方形的个数为(h/a)*(w/a)
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
#define double long double
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=100+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353;
const double eps=1e-6;


void solve(){
    int n,k;cin>>n>>k;
    vector<int>h(n),w(n);
    int ma=0;
    for(int i=0;i<n;++i){
        cin>>h[i]>>w[i];
        ma=max(ma,min(h[i],w[i]));
    }
    int l=1,r=ma,x;
    auto check=[&](int a){
        int c=0;
        for(int i=0;i<n;++i){
            c+=(h[i]/a)*(w[i]/a);
        }
        return c>=k;
    };
    while(l<=r){
        int mid=l+r>>1;
        if(check(mid))l=mid+1,x=mid;
        else r=mid-1;
    }
    cout<<x;
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
View Code

 

G[蓝桥杯 2016 省 B] 交换瓶子

思路:预处理每个数对应的位置,若该位置上的数不是本身,找到目标数所在的位置进行交换,记录交换次数。 也可以用图解决...,参考https://blog.csdn.net/qq_29992017/article/details/129885881
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
#define double long double
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=1e4+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353;
const double eps=1e-6;


void solve(){
    int n;
    cin>>n;
    vector<int>ve(n+5),s(n+5);
    int ans=0;
    for(int i=1;i<=n;++i){
        cin>>ve[i];
        s[ve[i]]=i;
    }
    for(int i=1;i<=n;++i){
        if(i==ve[i])continue;
        int b=s[i];
        s[i]=i,s[ve[i]]=b;
        swap(ve[i],ve[b]);
        ans++;
    }
    cout<<ans;
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
View Code

 

H[蓝桥杯 2015 省 B] 生命之树

思路:树形dp一下子
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
#define double long double
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=1e5+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353;
const double eps=1e-6;

int n,w[N],ans,st[N],f[N];
vector<vector<int>>g;
int dfs(int u){
    for(auto v:g[u]){
        if(st[v])continue;
        st[v]=1;
        f[v]=w[v]+dfs(v);
        if(f[v]>0)f[u]+=f[v];
    }
    return f[u];
}
void solve(){
    cin>>n;
    g=vector<vector<int>>(n+1);
    for(int i=1;i<=n;++i){
        cin>>w[i];
    }
    for(int i=1;i<n;++i){
        int u,v;
        cin>>u>>v;
        g[u].push_back(v),g[v].push_back(u);
    }
    st[1]=1;
    f[1]=w[1]+dfs(1);
    for(int i=1;i<=n;++i)ans=max(ans,f[i]);
    cout<<ans;
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
View Code

 

I[蓝桥杯 2016 省 A] 密码脱落

思路:可以在任意位置添加,最坏的情况是每个字符都添加一个,如何尽可能的少添加,可以将原序列与置换后的序列求最长公共子序列,这些字符就不需要添加,答案即为n-lcs(最长公共子序列)  
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
#define double long double
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=100+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353;
const double eps=1e-6;

void solve(){
    string s,f;
    cin>>s;
    int n=s.size();
    f=s, std::reverse(s.begin(), s.end());
    s=' '+s;
    f=' '+f;
    vector<vector<int>>ve(n+5,vector<int>(n+5));
    for(int i=1;i<=n;++i){
        for(int j=1;j<=n;++j){
            ve[i][j]=max(ve[i-1][j],ve[i][j-1]);
            if(s[i]==f[j])ve[i][j]=max(ve[i][j],ve[i-1][j-1]+1);
        }
    }
    cout<<n-ve[n][n];
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
View Code

 

J[蓝桥杯 2022 省 A] 爬树的甲壳虫

思路:f[i]表示到达i的时间期望,那么f[i]=(1-p[i])*f[i-1]+1+p[i]*(f[i-1]+f[i]),解方程得f[i]=(f[i-1]+1)/(1-p[i])
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
#define double long double
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=100+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353;
const double eps=1e-6;

int ksm(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=ans*a%mod;
        b>>=1;
        a=a*a%mod;
    }
    return ans;
}
void solve(){
    int n;cin>>n;
    vector<int>p(n+1);
    for(int i=1;i<=n;++i){
        int x,y;
        cin>>x>>y;
        p[i]=y*ksm(y-x,mod-2)%mod;
    }
    vector<int>f(n+1);
    for(int i=1;i<=n;++i){
        f[i]=(f[i-1]+1)*p[i]%mod;
    }
    cout<<f[n];
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
View Code

 

标签:typedef,const,winter,int,double,long,day1,2024,define
From: https://www.cnblogs.com/bible-/p/17980600

相关文章

  • P10060 [SNOI2024] 树 V 图
    原题链接首先想到\(f\)值相同的点一定构成一个连通块,所以应当有\(k\)个连通块并且每个连通块\(f\)值互不相同。判断一下\([1,k]\)是否在\(f\)中都出现过,并且是否有\(k-1\)条边两个端点的\(f\)值不同,若有不符合的就是非法输入,直接输出\(0\)。考虑\(k=2\)的部分......
  • 云原生周刊:Meshery v0.70 发布 | 2024.1.22
    开源项目推荐flux-cluster-template该项目用于部署由Flux、SOPS、GitHubActions、Renovate、Cilium等支持的Kubernetes集群,专注于使用GitOps实践和基础设施自动化。Kine该项目可以在MySQL、Postgres、SQLite、Dqlite等数据库上运行Kubernetes,而不是使用etcd。Kube......
  • 2024年经济复苏:疫情后的挑战与机遇,如何破局迎来全面复苏
    洞元科技携您共谋未来的经济可持续发展2019年一场突如其来的疫情,让整个中国发生了翻天覆地的变化。由于物理限制和社交距离的要求,许多企业和组织开始加速数字化转型的进程。例如,远程办公、在线教育、数字医疗等领域得到了广泛的应用。甚至改变了很多行业之前的发展轨迹。疫情......
  • 2024年春节倒计时还有多少天?用手机便签设置倒计时天数方法
    进入每年的腊月中旬,相信很多学生已经无心学习了,而上班族也无心工作,大家只想赶快放假过年。不过在过年之前,有不少小伙伴都需要提前做好准备,例如为亲朋好友购买春节礼物、为家里购买年货、提前订购火车票等,这时候知晓每天距离春节的倒计时天数就非常有必要了。那么今天距离2024年春......
  • 2024.1.22日报
    今天继续spark实验,主要是完成5和6吸取了昨天的教训,先把文件传到hdfs再操作            实验六首先是配置好了flume avor测试 开启三个node1窗口分别用于创建文件,写入文件,显示文件内容 测试二 监听44444端口,并输出helloworld......
  • 2024-1-19事件冒泡
    目录事件冒泡什么是事件冒泡冒泡事件例子事件冒泡什么是事件冒泡事件冒泡是一个事件处理机制,在这个机制中,当一个元素上发生事件(比如点击),这个事件不仅在该元素上触发,还会向上通过父元素传播,依次触发每个父元素上的同类型事件,直到到达文档的根部。这个过程就像气泡从水底升到水面......
  • 每日一题 2024-1-22 最大交换
    1.题目(中等)原题链接给定一个非负整数,你至多可以交换一次数字中的任意两位。返回你能得到的最大值。示例1:输入:2736输出:7236解释:交换数字2和数字7。示例2:输入:9973输出:9973解释:不需要交换。注意:给定数字的范围是\([0,10^8]\)2.解题思路贪心,......
  • 2024最新版Xmind for Windows下载安装教程
    软件介绍:LifetimeXMindforWindows:一款全新的思维导图软件如果你是一个喜欢用思维导图来组织思路、管理项目、记录灵感的人,那么你一定不会陌生XMind这个品牌。XMind是一款在思维导图领域表现出色的软件,它拥有遍布全球的大量用户,不仅为用户提供创建思维导图的功能,而且还提供开源。......
  • Toyota Programming Contest 2024#1(AtCoder Beginner Contest 337)
    ToyotaProgrammingContest2024#1(AtCoderBeginnerContest337)A-Scoreboard代码:#include<bits/stdc++.h>usingnamespacestd;usingll=longlong;usingpii=pair<ll,ll>;#definefifirst#definesesecondusingi128=__int128_t;void......
  • 2024 礼品 Power Adapter and Connnect Specifications
    1.PowerAdapter30WChargeyourdevicesUSB-C,USB-A(Plugtypevariesbyregion,OnlyEU&UKplugareapprovedandsuitableforuseinSingapore.)Model:ILINC30WOutputpower:30WMax.Operatingtemperature:0-45°CAverageactiveefficiency:Min81.......