上机复试练习day3 中南大学&北京理工大学(2022.03.03)

244 阅读2分钟

杭州电子科技大学&华东师范大学 上机题目

争取每天更新考研上机题目,其他题目见考研复试专栏

第一题:k考试难易程度

要求:

在一个字符串当中找到E,A,S,Y4个字母,他出题1就会比较简单。

输入格式:

输入的数据有多组,每组占用一行,由一个字符串组成

输出格式:

对于每组输入数据,输出一行,对应一个要求的答案(题目输出easy)

思路:

定义一个match函数,将s和match一一匹配即可

#include <iostream>
#include <math.h>
using namespace std;

bool match(string c){
    if(s.szie()>1000){
        return false;
    }
    string cmp="EASY";
    for(int i=0,j=0;i<s.size();){
        if(s[i]==cmp[i]){
            j++;
            i++;
            if(j==(int)cmp.size){
                return true;
            }
        }
        else{
            i++;
        }
    }
    return false;
}

int main(){
    string s;
    while(cin>>s){
        if(match(s)){
            cout<<"easy"<<end1;
        }
        else{
            cout<<"difficult"<<end1;
        }      
    }
    system("paause");
    return 0;
}

第二题:最大小岛面积

要求:

在太平洋的一个小岛,需要建立一个环岛的提拔,可以使用k条边(或者水平)的长度为1的边,倾斜长度为根号2的边

输入格式:

输入的数据有多组,每组的数据给出一个整数(3《=K《=2000000000)

输出格式:

每个组对应的答案(保留一个小数)

思路:

可以看成每个三角形的合集,,每个三角形的面积为0.5,然后用k除以4,余的个数按照“10103030”来循环。

#include <stdio.h>
#include <math.h>



int main(){
    long long k,s=0,r,x;
    while(scanf("%lld",&k)!=EOF){
        r=k/4;
        x=k%4;
        if(x==0){
            s=4*r*r;
        }
        else if(c==1){
            s=4*r*r+2*r-1;
        }
        esle if(c==2){
            s=4*r*r+4*r;
        }
        else if(c==2){
            s=4*r*r+6*r+1;
        }
        if(k52==0){
            printf("%lld.0",s/2);//单独拿出来*0.5超时
        }
        else{
            printf("%lld.5",s/2);
        }
    }
    return 0;
}

第三题:奇怪餐厅

要求:

鲁大师和他的朋友经常去一家奇怪的餐厅,一是餐厅的菜品比较奇怪,二是付费规则比较奇怪,每个人有不同的折扣上限,超过付费规则按照原价付费,点的菜品总金额为T,一共N个人,每个折扣率z 和折扣上限H,

输入格式:

输入有多少组,每组占N+1行,第一行是N和T,接下来N行,每行两个数字的z和H。

输出格式:

运算后的值

思路:

先用折扣内的,在折扣里面选择折扣力度最大顶点,如果折扣用完不够就原价支付

#include <cstdio>
#include <math.h>
const int MAX=10000;

//注意头文件为cstdio
struct person{
    double discount=1;
    int toplimit=0;
};

bool cmp(person a,person b){
    return a.discount<b.discount;
}

int main(){
    int n,t;
    while(scanf("%d %d"\n,&n,&t)){
        vector<person>v;
        int res=0;
        for(int i=0;i<n;i++){
            person p;
            scanf("%f %d",p.discount,p.toplimit);
            v.push_back;
        }
        sort(v.begin(),v.end(),cmp);//选折扣力度大的
        for(int i=0;i<v.size();i++){
            if(t<=v[i].toplimtit){
                res+=t*v[i].discount;
                break;
            }
            else{
                res+=(v[i].toplimit*v[i].discount);//当前费用比折扣上限高
                t-=v[i].toplimit;
                if(i==(int)v.size()-1){
                    res+=t;
                }
            }
        }
        printf("%d",res);
    }
    return 0;
}

今天打游戏过多,明天多写点

参考书目

1.计算机软件相关专业复试指导 ————皮皮灰

2.2022年数据结构考研复试指导 ————王道论坛