宁波工程学院2020新生校赛(重现赛)(未完)

Powered by:AB_IN 局外人

只会这些题了。。

A 恭喜小梁成为了宝可梦训练家~

#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
typedef unsigned long long ull;
typedef long long ll;
ll a[1001],t,n;
using namespace std;
namespace IO{
    char ibuf[1<<21],*ip=ibuf,*ip_=ibuf;
    char obuf[1<<21],*op=obuf,*op_=obuf+(1<<21);
    inline char gc(){
        if(ip!=ip_)return *ip++;
        ip=ibuf;ip_=ip+fread(ibuf,1,1<<21,stdin);
        return ip==ip_?EOF:*ip++;
    }
    inline void pc(char c){
        if(op==op_)fwrite(obuf,1,1<<21,stdout),op=obuf;
        *op++=c;
    }
    inline ll read(){
        register ll x=0,ch=gc(),w=1;
        for(;ch<'0'||ch>'9';ch=gc())if(ch=='-')w=-1;
        for(;ch>='0'&&ch<='9';ch=gc())x=x*10+ch-48;
        return w*x;
    }
    template<class I>
    inline void write(I x){
        if(x<0)pc('-'),x=-x;
        if(x>9)write(x/10);pc(x%10+'0');
    }
    class flusher_{
    public:
        ~flusher_(){if(op!=obuf)fwrite(obuf,1,op-obuf,stdout);}
    }IO_flusher;
}
using namespace IO;
int main()
{
    t=read();
    while(t--){
        ll maxn=-0x3f3f3f;
        ll minn=0x3f3f3f;
        ll sum=0;
        n=read();
        for(int i=1;i<=n;i++)
        {
            a[i]=read();
            maxn=max(maxn,a[i]);
            minn=min(minn,a[i]);
            sum+=a[i];
        }
        printf("MAX:%lld\n",maxn);
        printf("MIN:%lld\n",minn);
        printf("AVG:%.2lf\n",1.0*sum/n);
    }
    return 0;
}

B 皮(A)卡©皮(M)~

t=int(input())
while t>0:
    t-=1
    s=input().upper()
    if 'A' not in s:
        print("A")
    elif 'C' not in s:
        print("C")
    elif 'M' not in s:
        print("M")
    else:
        print("-1")

C 杰尼杰尼

水题没人做系列。
斜率相同就不算,hash一下就行了。

#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
typedef unsigned long long ull;
typedef long long ll;
const ll maxn=1e3+10;
using namespace std;
namespace IO{
    char ibuf[1<<21],*ip=ibuf,*ip_=ibuf;
    char obuf[1<<21],*op=obuf,*op_=obuf+(1<<21);
    inline char gc(){
        if(ip!=ip_)return *ip++;
        ip=ibuf;ip_=ip+fread(ibuf,1,1<<21,stdin);
        return ip==ip_?EOF:*ip++;
    }
    inline void pc(char c){
        if(op==op_)fwrite(obuf,1,1<<21,stdout),op=obuf;
        *op++=c;
    }
    inline ll read(){
        register ll x=0,ch=gc(),w=1;
        for(;ch<'0'||ch>'9';ch=gc())if(ch=='-')w=-1;
        for(;ch>='0'&&ch<='9';ch=gc())x=x*10+ch-48;
        return w*x;
    }
    template<class I>
    inline void write(I x){
        if(x<0)pc('-'),x=-x;
        if(x>9)write(x/10);pc(x%10+'0');
    }
    class flusher_{
    public:
        ~flusher_(){if(op!=obuf)fwrite(obuf,1,op-obuf,stdout);}
    }IO_flusher;
}
using namespace IO;
map< pair<double,double>, int> vis;
ll n,a[maxn],b[maxn],cnt;
int main()
{
    n=read();
    for(int i=1;i<=n;i++)
        a[i]=read(),b[i]=read();
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if(a[i]!=a[j]){
                double x=(1.0*b[j]-1.0*b[i])/(1.0*a[i]-1.0*a[j]);
                double y=x*a[i]+b[i];
                if(!vis[{x,y}]){
                    cnt++;
                    vis[{x,y}]++;
               }
            }
        }
    }
    if(cnt==0) printf("No Fire Point.");
    else write(cnt);
}

G 遗迹逃亡

bfs板子题。

#include <bits/stdc++.h>
using namespace std;
int x2[4]={0,0,-1,1};
int y2[4]={1,-1,0,0};
struct sa
{
    int x;
    int y;
};
queue<sa>q;
char a[510][510];
int n,m,xt,yt,xg,yg;
int bfs(int x,int y)
{
    q.push({x,y});
    a[x][y]='#';
    while(!q.empty()){
        sa tmp;
        tmp=q.front();
        q.pop();
        int x3=tmp.x;
        int y3=tmp.y;
        if(x3==xt&&y3==yt)
            return 1;
        for(int i=0;i<4;i++){
            int x4=x3+x2[i];
            int y4=y3+y2[i];
            if(x4>=1&&x4<=n&&y4>=1&&y4<=m&&(a[x4][y4]=='.'||a[x4][y4]=='g')){
                q.push({x4,y4});
                a[x4][y4]='#';
            }
        }
    }
    return -1;
}
int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>a[i][j];
            if(a[i][j]=='s') xg=i,yg=j;
            if(a[i][j]=='g') xt=i,yt=j;
        }
    }
    int cnt=bfs(xg,yg);
    if(cnt==-1)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
    return 0;
}

L 小梁的道馆

赛后补题:并查集!
这里不搞快读什么的了,简单易懂 直接上代码。
会再写一篇简单说说菜鸡看代码想的并查集。

#include <bits/stdc++.h>
using namespace std;
int n, m, t, a, b, u, v;
int fa[1005];

int find(int x) {
    if(fa[x] == x) return x;
    return fa[x] = find(fa[x]);
}

int main() {
    scanf("%d %d %d", &n, &m, &t);
    for(int i = 1;i <= n; i++) fa[i] = i;
    for(int i = 1;i <= m; i++) {
        scanf("%d %d", &a, &b);
        u = find(a); v = find(b);
        fa[u] = v;
    }
    while(t--) {
        scanf("%d %d", &a, &b);
        u = find(a); v = find(b);
        if(u == v) puts("YES");
        else puts("NO");
    }
}

猜你喜欢

转载自blog.csdn.net/qq_45859188/article/details/106878570