牛客小白月赛61 ABCE*

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;
}
posted @ 2023-04-05 19:33  高尔赛凡尔娟  阅读(4)  评论(0编辑  收藏  举报