第七次CCF计算机软件能力认证

第一题:

#include<bits/stdc++.h>
using namespace std;
int a[100010];
int main(){
    int n;scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    int res=0;
    for(int i=2;i<=n-1;i++){
        if(a[i]<a[i-1]&&a[i]<a[i+1]||a[i]>a[i-1]&&a[i]>a[i+1]) res++;
    }
    printf("%d\n",res);
    return 0;
}

第二题:

#include<bits/stdc++.h>
using namespace std;
const int N=20;
int g[N][N],s[N][N];
int p[5][5];
int x;
bool solve(int r,int c){
    memcpy(s,g,sizeof s);
    for(int i=0;i<4;i++){
        for(int j=0;j<4;j++){
            int x=r+i,y=c+j;
            if(p[i][j]){
                if(x>=15) return true;
                s[x][y]++;
                if(s[x][y]==2) return true;
            }
        }
    }
    return false;
}
int main(){
    for(int i=0;i<15;i++)
        for(int j=0;j<10;j++) 
            scanf("%d",&g[i][j]);
    for(int i=0;i<4;i++)
        for(int j=0;j<4;j++)
            scanf("%d",&p[i][j]);
    scanf("%d",&x);
    x--;
    int i=0;
    while(1){
        if(solve(i,x)){
            solve(i-1,x);
            break;
        }
        i++;
    }
    for(int i=0;i<15;i++){
        for(int j=0;j<10;j++)
            printf("%d ",s[i][j]);
        puts("");
    }
    return 0;
}

第三题:

#include<bits/stdc++.h>
using namespace std;
vector<string> get(string s){
    vector<string> res;
    for(int i=0;i<s.size();i++){
        if(s[i]=='/') continue;
        int j=i+1;
        while(j<s.size()&&s[j]!='/') j++;
        res.push_back(s.substr(i,j-i));
        i=j;
    }
    return res;
}
void solve(vector<string> cur,vector<string> path){
    for(auto p:path){
        if(p==".") continue;
        if(p==".."){
            if(cur.size()) cur.pop_back();
        }
        else cur.push_back(p);
    }
    if(cur.empty()){
        puts("/");
        return ;
    }
    for(auto p:cur)
        cout<<"/"<<p;
    puts("");
}
int main(){
    int n;
    string str;
    cin>>n>>str;
    vector<string> cnt=get(str),ab;
    getchar();
    while(n--){
        getline(cin,str);
        auto path=get(str);
        if(str.size()&&str[0]=='/') solve(ab,path);
        else solve(cnt,path);
    }
    return 0;
}

第四题:

#include<bits/stdc++.h>
using namespace std;
const int N=110,M=310;
int g[N][N][M];
int d[N][N][M];
int n,m,t;
int r,c,a,b;
struct P{
    int x,y,t;
};
int dx[]={0,1,-1,0};
int dy[]={1,0,0,-1};
int bfs(){
    memset(d,0x3f,sizeof d);
    queue<P> q;
    q.push({1,1,0});
    while(q.size()){
        auto fs=q.front();
        q.pop();
        for(int i=0;i<4;i++){
            int x=fs.x+dx[i];
            int y=fs.y+dy[i];
            if(x<=0||x>n||y<=0||y>m) continue;
            if(g[x][y][fs.t+1]) continue;
            if(d[x][y][fs.t+1]>fs.t+1){
                if(x==n&&y==m) return fs.t+1;
                d[x][y][fs.t+1]=fs.t+1;
                q.push({x,y,fs.t+1});
            }
        }
    }
    return 0;
}
int main(){
    scanf("%d%d%d",&n,&m,&t);
    for(int i=0;i<t;i++){
        scanf("%d%d%d%d",&r,&c,&a,&b);
        for(int j=a;j<=b;j++) g[r][c][j]=true;
    }
    cout<<bfs()<<endl;
    return 0;
}

第五题:

待补充

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值