• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

牛客小白月赛63

武飞扬头像
skyang.
帮助1

比赛链接:牛客小白月赛63_ACM/NOI/CSP/CCPC/ICPC算法编程高难度练习赛_牛客竞赛OJ

A题

签到题,把所有数按位与一遍就行。

  1.  
    #include<iostream>
  2.  
    using namespace std;
  3.  
     
  4.  
    int main()
  5.  
    {
  6.  
    int n,a,ans;
  7.  
    cin>>n;
  8.  
    cin>>a;
  9.  
    ans=a;
  10.  
    for(int i=2;i<=n; i)
  11.  
    {
  12.  
    cin>>a;
  13.  
    ans=a&ans;
  14.  
    }
  15.  
     
  16.  
    cout<<ans<<endl;
  17.  
     
  18.  
    return 0;
  19.  
    }
学新通

B题:

阅读理解题,暴力,遍历每次攻击,判断是否击杀随从,击杀则attack ,在每次循环最后计算boss伤害的增量。

  1.  
    #include<iostream>
  2.  
    using namespace std;
  3.  
     
  4.  
    int main()
  5.  
    {
  6.  
    int n,m;
  7.  
    int attack=2;
  8.  
    int a[1005];
  9.  
    int ans=0;
  10.  
    cin>>n>>m;
  11.  
     
  12.  
    for(int i=1;i<=n; i)
  13.  
    {
  14.  
    cin>>a[i];
  15.  
    }
  16.  
     
  17.  
    for(int i=1;i<=m; i)
  18.  
    {
  19.  
    for(int j=1;j<=n; j)
  20.  
    {
  21.  
    if(attack==a[j])
  22.  
    {
  23.  
    attack ;
  24.  
    a[j]=-1;
  25.  
    }
  26.  
    else
  27.  
    {
  28.  
    a[j]-=attack;
  29.  
    }
  30.  
    }
  31.  
    ans =attack;
  32.  
    }
  33.  
     
  34.  
    cout<<ans<<endl;
  35.  
     
  36.  
    return 0;
  37.  
    }
学新通

c题

核心在于如何求n个数的全排列,这里我用了一个dfs,x为当前处理的位数,i为该位放置的数字。当x==n时,根据双方对应的大爹个数,计算是谁赢了还是平局,给对应计数器加1.

  1.  
    #include<iostream>
  2.  
    using namespace std;
  3.  
     
  4.  
    typedef long long ll;
  5.  
     
  6.  
    int n;
  7.  
    int a[15],b[15];
  8.  
    ll victory=0,equ=0,defeat=0;
  9.  
    bool vis[15]={false};
  10.  
    ll va=0,vb=0;
  11.  
     
  12.  
    void dfs(int x)
  13.  
    {
  14.  
    for(int i=1;i<=n; i)
  15.  
    {
  16.  
    if(vis[i]==false)
  17.  
    {
  18.  
    vis[i]=true;
  19.  
    if(a[x]>b[i]) va ;
  20.  
    else if(a[x]<b[i]) vb ;
  21.  
     
  22.  
    if(x==n)
  23.  
    {
  24.  
    if(va>vb) victory ;
  25.  
    else if(va<vb) defeat ;
  26.  
    else if(va==vb) equ ;
  27.  
    }
  28.  
    else dfs(x 1);
  29.  
     
  30.  
    vis[i]=false;
  31.  
    if(a[x]>b[i]) va--;
  32.  
    else if(a[x]<b[i]) vb--;
  33.  
    }
  34.  
    }
  35.  
    }
  36.  
     
  37.  
    int main()
  38.  
    {
  39.  
    cin>>n;
  40.  
    for(int i=1;i<=n; i) cin>>a[i];
  41.  
    for(int i=1;i<=n; i) cin>>b[i];
  42.  
     
  43.  
    dfs(1);
  44.  
     
  45.  
    cout<<victory<<" "<<defeat<<" "<<equ<<endl;
  46.  
     
  47.  
    return 0;
  48.  
    }
学新通

D题

我觉得这个题的难度配不上D这个编号,贪心,每次选最便宜那个颜色,到第三个时,换第二便宜的颜色,然后继续用最便宜的。最后,首尾相接,所以最后那朵花用第二便宜颜色染,防止与最开始两朵花颜色连续。

  1.  
    #include<iostream>
  2.  
    #include<algorithm>
  3.  
    using namespace std;
  4.  
     
  5.  
    typedef long long ll;
  6.  
     
  7.  
    int main()
  8.  
    {
  9.  
    ll n,m;
  10.  
    ll a[5];
  11.  
    ll ans=0;
  12.  
    int two=0;
  13.  
    cin>>n>>m;
  14.  
    for(int i=1;i<=m; i)
  15.  
    {
  16.  
    cin>>a[i];
  17.  
    }
  18.  
     
  19.  
    sort(a 1,a m 1);
  20.  
     
  21.  
    for(int i=1;i<n; i)
  22.  
    {
  23.  
    if(two!=2)
  24.  
    {
  25.  
    ans =a[1];
  26.  
    two ;
  27.  
    }
  28.  
    else
  29.  
    {
  30.  
    ans =a[2];
  31.  
    two=0;
  32.  
    }
  33.  
    }
  34.  
     
  35.  
    ans =a[2];
  36.  
     
  37.  
    if(m==1&&n>=3) cout<<"Ginger666"<<endl;
  38.  
    else cout<<ans<<endl;
  39.  
     
  40.  
    return 0;
  41.  
    }
学新通

E题

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgfcifi
系列文章
更多 icon
同类精品
更多 icon
继续加载