首页 > 其他分享 >牛客小白月赛61 ABCE*

牛客小白月赛61 ABCE*

时间:2023-04-05 19:46:49浏览次数:45  
标签:ABCE typedef const 61 int LL cin long 牛客

https://ac.nowcoder.com/acm/contest/46597

A-超市里扫货

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=2e6+10,M=3023;
const LL mod=100000007;
const double PI=3.1415926535;
#define endl '\n'
LL a[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    //cin>>T;
    while(T--)
    {
        LL sum=0,ans=1;
        LL n,m;
        cin>>n>>m;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            if(sum+a[i]<=m) sum+=a[i];
            else ans++,sum=a[i];
        }
        cout<<ans<<endl;
    }
    return 0;
}

B-柜台结账

输入 
1 4
输出 
Happy birthday to YXGG
 
输入 
1 5
输出 
Happy birthday to MFGG
 
输入 
1 6
输出 
Happy birthday to MFGG
 
输入 
0 0
输出 
PLMM

看清楚题目的数据范围

数据范围这么大,那说明正常的整数肯定是解决不了的,必须使用上string或者char

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=2e6+10,M=3023;
const LL mod=100000007;
const double PI=3.1415926535;
#define endl '\n'
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    //cin>>T;
    while(T--)
    {
        string a,b;
        cin>>a>>b;
        LL zero=0;
        for(int i=0;i<b.size();i++)
        {
            if(b[i]=='0') zero++;
        }
        if(zero==b.size()) cout<<"PLMM"<<endl;
        else
        {
            LL zero5=0;
            for(int i=1;i<b.size();i++)
            {
                if(b[i]=='0') zero5++;
            }
            if(b[0]=='5'&&zero5+1==b.size())
            {
                if((a[a.size()-1]-'0')%2==1) cout<<"Happy birthday to MFGG"<<endl;
                else cout<<"Happy birthday to YXGG"<<endl;
            }
            else if(b[0]-'0'<5) cout<<"Happy birthday to YXGG"<<endl;
            else cout<<"Happy birthday to MFGG"<<endl;
        }
    }
    return 0;
}

C-小喵觅食

输入
5 3
2 1
...
.M.
...
...
.P.
输出 
3

输入 
5 3
1 2
**.
*M.
**.
*..
*P.
输出 
5


输入 
5 3
2 1
**.
*M.
**.
*..
*P.
输出 
-1

这个题目我们主要是要知道猫猫是可以移动的,人是不动的。
只有在一开始的时候,猫猫能够在范围内闻到味道,它才会慢慢移动过来,
但是如果一开始猫猫就没有闻到味道,说明它不会过来,所以其实我们只要抓住一个能够闻到味道的点,然后就可以输出最短路了。

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=2e6+10,M=3023;
const LL mod=100000007;
const double PI=3.1415926535;
#define endl '\n'
LL n,m,r1,r2;
LL pi,pj,mi,mj;
LL d[M][M];
char a[M][M];
LL dx[]={-1,0,0,1},dy[]={0,1,-1,0};
bool st[M][M];
int bfs()
{
    memset(d,-1,sizeof d);
    d[pi][pj]=0;
    queue<PII> q;
    q.push({pi,pj});
    while(q.size())
    {
        auto t=q.front();
        q.pop();
        for(int i=0;i<4;i++)
        {
            LL xx=dx[i]+t.first,yy=dy[i]+t.second;
            if(xx>=1&&xx<=n&&yy>=1&&yy<=m&&d[xx][yy]==-1&&a[xx][yy]!='*')
            {
                d[xx][yy]=d[t.first][t.second]+1;
                q.push({xx,yy});
            }
        }
    }
    return d[mi][mj];
}
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    //cin>>T;
    while(T--)
    {
        cin>>n>>m>>r1>>r2;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                cin>>a[i][j];
                if(a[i][j]=='P') pi=i,pj=j;//plmm的位置
                else if(a[i][j]=='M') mi=i,mj=j;//喵喵的位置
            }
        }
        bool flag=false;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                if(a[i][j]=='.')
                {
                    LL pto=abs(pi-i)+abs(pj-j);
                    LL mto=abs(mi-i)+abs(mj-j);
                    if(pto<=r1&&mto<=r2)
                    {
                        cout<<bfs()<<endl;
                        flag=true;
                        break;
                    }
                }
            }
            if(flag==true) break;
        }
        if(flag==false) cout<<"-1"<<endl;
    }
    return 0;
}

E-排队

题目大意:

给定数组a,求a中的所有元素的全部排列方式的逆序对的总数。
输入 
3
1 2 3
输出
9
 
输入 
7
2 4 4 3 1 1 2
输出
45360
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=2e7+10,M=2023;
const LL mod=1e9+7;
const double PI=3.1415926535;
#define endl '\n'
int cnt[100007];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    //cin>>T;
    while(T--)
    {
    	int n,a;
        long long ans=0;
        cin>>n;
        for(int i=1;i<=n;i++)
	{
	    cin>>a;
            (ans+=i- ++cnt[a])%mod; 
        }
        for(int i=3;i<=n;i++)
	{
	    ans=ans*i%mod;
        }
        cout<<ans;
    }
    return 0;
}

标签:ABCE,typedef,const,61,int,LL,cin,long,牛客
From: https://www.cnblogs.com/Vivian-0918/p/17289989.html

相关文章

  • Codeforces Round 861 (Div. 2)
    Preface这场感觉都是一个礼拜前补题打的了,但由于上周末事情比较多都没来得及写题解因此可能题意都记得不是很清楚了,就简略地谈一谈吧A.LuckyNumbers不难想到直接暴力从左端点枚举到右端点并对每个数进行暴力判断一个很naive的结论就是当答案为\(9\)时直接输出即可,然后我们......
  • 力扣615(MySQL)-平均工资:部门与公司比较(困难)
    题目:给如下两个表,写一个查询语句,求出在每一个工资发放日,每个部门的平均工资与公司的平均工资的比较结果(高/低/相同)。表:salary employee_id字段是表employee中employee_id字段的外键。 对于如上样例数据,结果为:解释在三月,公司的平均工资是(9000+6000+10000)/......
  • 力扣614(MySQL)-二级关注者(中等)
    题目:在facebook中,表follow会有2个字段:followee,follower,分别表示被关注者和关注者。请写一个sql查询语句,对每一个关注者,查询关注他的关注者的数目。比方说: 应该输出: 解释:B和D都在在follower字段中出现,作为被关注者,B被C和D关注,D被E关注。A不在......
  • 代码随想录Day20-Leetcode654.最大二叉树,617.合并二叉树,700.二叉搜索树中的搜索,98.验
    654.最大二叉树题目链接:https://leetcode.cn/problems/maximum-binary-tree/基本的模拟思路很快/***Definitionforabinarytreenode.*functionTreeNode(val,left,right){*this.val=(val===undefined?0:val)*this.left=(left===undefined......
  • 牛客,第二十届北京师范大学程序设计竞赛,签到题7题
    序题号标题已通过代码通过率团队的状态A小凯的疑惑点击查看434/745通过B幻象踩花点击查看121/434通过C跳刀抓人点击查看26/178通过D真正的卡尔点击查看115/714通过E刷新的艺术点击查看31/479通过F最后的战役点击查看1/39未通过G随机数生成器点击......
  • 2019牛客暑期多校训练营(第四场) K numbers
    链接:https://ac.nowcoder.com/acm/contest/884/K?&headNav=acm&headNav=acm来源:牛客网 题目描述300iqlovesnumberswhoaremultipleof300.Onedayhegotastringconsistedofnumbers.Hewantstoknowhowmanysubstringsinthestringaremultiplesof300whe......
  • CS61A_lab_07
    Problem2题目描述:代码:1definc_subseqs(s):2"""AssumingthatSisalist,returnanestedlistofallsubsequences3ofS(alistoflists)forwhichtheelementsofthesubsequence4arestrictlynondecreasing.Thesubseq......
  • 极路由HC5861B强开ROOT刷Bread刷第三方固件
    极路由折腾记录官网已经倒闭,如何ROOT设备?刷Bread刷固件参考资料:TOC极路由折腾记录"board":"HC5861B"官网已经倒闭,如何ROOT设备?极路由ROOTlocal-ssh利用工具http://192.168.199.1/local-ssh/得到local_tokenhttp://192.168.199.1/cgi-bin/turbo/proxy/router_in......
  • 力扣612(MySQL)-平面上的最近距离(中等)
    题目:表point_2d保存了所有点(多于2个点)的坐标(x,y),这些点在平面上两两不重合。写一个查询语句找到两点之间的最近距离,保留2位小数。 最近距离在点(-1,-1)和(-1,2)之间,距离为1.00。所以输出应该为: 解题思路:建表语句:1createtableifnotexistspoint_2d(x......
  • 牛客SQL-非技术快速入门
    01基础查询SQL1查询所有列select*fromuser_profileSQL2查询多列selectdevice_id,gender,age,universityfromuser_profileSQL3查询结果去重selectdistinct(university)fromuser_profileSQL4查询结果限制返回行数top不适用于所有的数据库语言。SQLSERVER......