天天看點

2017北郵計算機學院機試

Problem A

題目沒有打,直接搬的大佬的圖:

原博:

https://blog.csdn.net/cqhblg/article/details/88062923

2017北郵計算機學院機試

暴力循環

#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        int max;
        scanf("%d",&max);
        int count=0;
        for(int i=1;pow(i,3)<=max;i++){
            int flag=sqrt(max)+1;
            for(int j=1;j<=flag;j++){
                if(pow(j,2)==i)
                    count++;
            }

        }
        printf("%d\n",count);
    }
    return 0;
}

           

Problem B

2017北郵計算機學院機試

分别定義5個操作就好。

#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
int buf[100];
int op1(int l,int r){
        int len=r-l+1;
        int a[len];
        for(int i=0;i<len;i++)
            a[i]=buf[r-i];
        for(int i=l;i<=r;i++)
            buf[i]=a[i-l];
}
int op2(int l,int r,int n){
    for(int i=0;i<n;i++){
        int ans=buf[l+i];
        buf[l+i]=buf[r-i];
        buf[r-i]=ans;
    }
}
int op3(int l,int r,int x){
    for(int i=l;i<=r;i++)
        buf[i]=x;
}
int op4(int l,int r){
    sort(buf+l,buf+r);
}
int op5(int l,int r){
    int ans=0;
    for(int i=l;i<=r;i++)
        ans+=buf[i];
    printf("%d\n",ans);
}
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
        scanf("%d",&buf[i]);
    while(m--){
        int op,l,r;
        scanf("%d%d%d",&op,&l,&r);
        switch(op){
        case 1:
                op1(l-1,r-1);
                break;
        case 2: int len;
                scanf("%d",&len);
                op2(l-1,r-1,len);
                break;
        case 3: int x;
                scanf("%d",&x);
                op3(l-1,r-1,x);
                break;
        case 4: op4(l-1,r-1);
                break;
        case 5: op5(l-1,r-1);
                break;
        }
    }
    return 0;
}
           

Problem C

2017北郵計算機學院機試

跟九度oj32題一樣,都不用改。。。直接搬過來就能用

#include<stdio.h>
#include<string.h>
struct Node{
    Node *lchild;
    Node *rchild;
    char c;
}Tree[50];
int loc;
Node *creat(){
    Tree[loc].lchild=Tree[loc].rchild=NULL;
    return &Tree[loc++];
}
char str1[30],str2[30];
void postOrder(Node *T){
    if(T->lchild!=NULL){
        postOrder(T->lchild);
    }
    if(T->rchild!=NULL){
        postOrder(T->rchild);
    }
    printf("%c",T->c);
}
Node *build(int s1,int e1,int s2,int e2){
    Node* ret=creat();
    ret->c=str1[s1];
    int rootIdx;
    for(int i=s2;i<=e2;i++){
        if(str2[i]==str1[s1]){
            rootIdx=i;
            break;
        }
    }
    if(rootIdx!=s2){
        ret->lchild=build(s1+1,s1+(rootIdx-s2),s2,rootIdx-1);
    }
    if(rootIdx!=e2){
        ret->rchild=build(s1+(rootIdx-s2)+1,e1,rootIdx+1,e2);
    }
    return ret;
}
int main(){
    while(scanf("%s",str1)!=EOF){
        scanf("%s",str2);
        loc=0;
        int L1=strlen(str1);
        int L2=strlen(str2);
        Node *T=build(0,L1-1,0,L2-1);
        postOrder(T);
        printf("\n");
    }
    return 0;
}
           

Problem D

2017北郵計算機學院機試
2017北郵計算機學院機試

emmm這題感覺沒想出怎麼做。。。。。。。。