ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

牛客小白月赛56 ABCDEF

2022-08-29 23:32:16  阅读:225  来源: 互联网

标签:typedef int LL 56 cin long 牛客 ABCDEF 阿宁


https://ac.nowcoder.com/acm/contest/39100
A-阿宁的柠檬

题目描述 
阿宁喜欢吃柠檬。已知每个柠檬酸度可能是 1到 a,甜度可能是 0 到 b。

现在阿宁有 n 个柠檬,她要全部吃掉,会获得一定的快乐值。快乐值为每个柠檬的酸度和甜度总和。

阿宁最小的快乐值和最大的快乐值可能是多少?
示例1
输入
2 3 4
输出
4 20
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=200200,M=2002;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    //cin>>T;
    while(T--)
    {
        LL a,b,n;
        cin>>a>>b>>n;
        cout<<n<<" "<<(a+b)*n<<endl;
    }
    return 0;
}

B-阿宁与猫咪

题目描述 
阿宁对自己施展隔音膜法。该膜法需要构造一个正整数数组 a,需要满足 a 数组的所有数总和等于 m。

假设 a 数组的奇数位的数的乘积为 u,偶数位的数的乘积为 v,阿宁烦躁值为 u + v。

奇数位的数指第1,3,5 ...个数,偶数位的数指第2,4,6 ...个数。

如果不存在奇数位的数,u 视为 0,如果偶数位的数不存在,则 v 视为 0。

阿宁想施展膜法使得她的烦躁值最小,问构造的数组是什么?

如果有多解,输出任意一解即可。
示例1
输入
1
输出
1
1

示例2
输入
2
输出
1
2
输出其中一解即可。
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=200200,M=2002;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    //cin>>T;
    while(T--)
    {
        LL n;
        cin>>n;
        cout<<n<<endl;
        for(int i=1;i<=n;i++)
            cout<<"1 ";
        cout<<endl;
    }
    return 0;
}

C-阿宁吃粽子

题目描述 
阿宁的公司给阿宁发了各种口味的粽子。
一共有 n 条粽子,每条粽子有个美味值ai.
阿宁想立即吃下全部。吃下第 k 条粽子时,该粽子的美味值是 x,阿宁获得 2^(k mod10) *x 的愉悦值。(k从1开始)

如果有多解,请把美味值较大的粽子,安排到后面。(好吃的留到后面)
示例1
输入
3
3 1 2
输出
1 2 3

示例2
输入
12 
4 4 4 3 3 3 2 2 2 1 1 1
输出
1 2 2 3 3 3 4 4 4 1 1 2

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const LL N=2002002,M=2002;
LL a[N],b[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    //cin>>T;
    while(T--)
    {
        LL n;
        cin>>n;
        for(LL i=1;i<=n;i++)
            cin>>a[i];
        sort(a+1,a+1+n);
        LL be=10;
        if(n<10) be=1;
        for(LL i=1;i<=n;i++)
        {
            b[be]=a[i];
            if(be+10<=n) be+=10;
            else be=(be%10+1);
        }
        for(LL i=1;i<=n;i++)
            cout<<b[i]<<" ";
    }
    return 0;
}

D-阿宁的质数

题目描述 
阿宁有一个长度为 n 的正整数数组 a,她有q次询问,每次询问:在数组 a 的前 x 个数中,未出现的最小质数是多少?
示例1
输入
5 5
8 2 3 6 5
1
2
3
4
5
输出
2
3
5
5
7
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=2e7;
int a[N],res[N];
int primes[N],cnt=0;
bool st[N];
int vis[N];
void get_primes(int n)//线性筛法求素数
{
    for(int i=2;i<=n;i++)
    {
        if(!st[i]) primes[cnt++]=i;//素数进入primes数组
        for(int j=0;primes[j]<=n/i;j++)
        {
            st[primes[j]*i]=true;//非素数利用bool数组st标记true
            if(i%primes[j]==0) break;
        }
    }
}
int main()
{
    get_primes(3000000);//线性筛法求素数
    /*for(int i=0;i<=100;i++)
        cout<<primes[i]<<" ";
    cout<<endl;*/
    int n,q;
    cin>>n>>q;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    int idx=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]<=30000000)//删掉的话会出现段错误
            vis[a[i]]=1;
        while(vis[primes[idx]]>0&&idx<=cnt) idx++;
        res[i]=primes[idx];
    }
    while(q--)
    {
        int x;
        cin>>x;
        cout<<res[x]<<endl;
    }
    return 0;
}

E-阿宁睡大觉

题目描述 

她睡觉时会产生字符串 s,计算出她的睡觉质量为 ∑ [i=1到len(s)−1] w(si)× w(si+1)。
其中定义 w(z)=0,w(Z)=2。(前者小写后者大写)

为了睡一个好大觉,阿宁使用了预测膜法知道 s 串,然后她可以最多使用 k 次del膜法。使用一次del膜法可以删除 s 串的一个字符。

阿宁想知道睡觉质量的最大值是多少?
示例1
输入
3 2
ZzZ
输出
4

示例2
输入
3 2
zzz
输出
0
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=200200,M=2002;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    //cin>>T;
    while(T--)
    {
        LL n,k;
        cin>>n>>k;
        string s;
        cin>>s;
        int l=-1;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]=='Z')
            {
                l=i;
                break;
            }
        }
        vector<int> v;
        for(int i=l+1;i<s.size();i++)
        {
            if(s[i]=='Z')
            {
                v.push_back(i-l-1);
                l=i;
            }
        }
        /*cout<<v.size()<<endl;
        for(int i=0;i<v.size();i++)
            cout<<v[i]<<" ";
        cout<<endl;*/
        sort(v.begin(),v.end());//这里其实还隐藏了一个
        int sum=0;
        for(int i=0;i<v.size();i++)
        {
            if(k>=v[i])
            {
                k-=v[i];
                sum+=4;
            }
        }
        cout<<sum<<endl;
    }
    return 0;
}

F-阿宁去游玩

题目描述 
阿宁打算下次放假去游玩。一共有 n 个城市, 阿宁住在 1 号城市,去到 n 号城市游玩。

城市有两种属性,一种是炎热,另一种是酷寒,每个城市是其中一种。

从一个城市前往另一个城市,如果要前往的城市和当前城市的属性相同,则需要 x 时间,否则需要 y 时间。

阿宁可以使用倒转膜法,该膜法可以使所有城市(除了阿宁当前所在的城市)的属性变化(炎热变酷寒,酷寒变炎热),花费 z 时间。

倒转膜法可以使用任意次。

阿宁想尽快去到 n 号城市游玩,她想知道她最少需要多少时间到达目的地?

输出描述:
一个整数,表示阿宁从 11 号城市到达 nn 号城市所需要的最少时间。
示例1
输入
5 6
1 3 9
1 0 0 1 1
1 2
1 3
2 3
2 4
3 4
4 5
输出
7
说明
路径 1->3->4->5,花费时间为 3+3+1=7。

示例2
输入
3 3
1 10 2
0 1 1
1 2
1 3
2 3
输出
3
说明
在 1 号城市使用一次倒转膜法,路径 1->3,花费时间为 2+1=3。
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL N=200200,M=2002;
LL n,m,x,y,z;
LL nums[N*2],dist[N*2];
LL e[N*2],w[N*2],ne[N*2],h[N*2],idx;
bool st[N*2];
void add(int a,int b,int c)
{
    e[idx]=b,w[idx]=c,ne[idx]=h[a],h[a]=idx++;
}
LL dij()
{
    memset(dist,0x3f,sizeof dist);
    dist[1]=0;
    priority_queue<PII,vector<PII>,greater<PII>> heap;
    heap.push({0,1});
    while(heap.size())
    {
        auto t=heap.top();
        heap.pop();
        LL distance=t.first,ver=t.second;
        if(st[ver]) continue;
        st[ver]=true;
        for(LL i=h[ver];i!=-1;i=ne[i])
        {
            LL j=e[i];
            if(dist[j]>distance+w[i])
            {
                dist[j]=distance+w[i];
                heap.push({dist[j],j});
            }
        }
    }
    return dist[n];
}
int main()
{
    //cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    //cin>>T;
    while(T--)
    {
        memset(h,-1,sizeof h);
        cin>>n>>m;
        cin>>x>>y>>z;
        x=min(x,y+z);
        y=min(y,x+z);
        for(LL i=1;i<=n;i++)
            cin>>nums[i];
        for(LL i=1;i<=m;i++)
        {
            LL a,b;
            cin>>a>>b;
            if(nums[a]==nums[b])
            {
                add(a,b,x);
                add(b,a,x);
            }
            else
            {
                add(a,b,y);
                add(b,a,y);
            }
        }
        dij();
        cout<<dist[n]<<endl;
    }
    return 0;
}

标签:typedef,int,LL,56,cin,long,牛客,ABCDEF,阿宁
来源: https://www.cnblogs.com/Vivian-0918/p/16637799.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有