【蘑菇街笔试】

1 校车

就跟生活中排队上车一样,班级顺序不能乱,同一个班级必须同一辆车,一辆车可以有不同的班级。

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

int arr[200];

int main(){
    int n, m, cnt=0, tmp;
    scanf("%d %d", &n, &m);
    tmp = m;
    for(int i=0; i<n; i++){
        int num;
        scanf("%d", &num);
        if(tmp-num < 0){
            cnt++;
            tmp = m;
        }
        tmp -= num;
    }
    if(tmp != m)
        cnt++;
    printf("%d", cnt);
    return 0;
}

2 最大间隙

去掉递增序列中a2,…,an-1中的某一个ai,求剩下的a1,…,ai-1,ai+1,…,an中的最大间隙中的最小值

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

int arr[200], n;

int calmax(int x)
{
    int rt = -0x3f3f3f3f;
    for(int i=2; i<=n; i++)
    {
        if(i == x)continue;
        if(i == x+1)
            rt = max(rt, arr[i]-arr[i-2]);
        else
            rt = max(rt, arr[i]-arr[i-1]);
    }
    return rt;
}

int main()
{
    scanf("%d", &n);
    for(int i=1; i<=n; i++)
        scanf("%d", &arr[i]);
    if(n==1)
    {
        printf("%d\n", arr[1]);
        return 0;
    }
    if(n == 2)
    {
        printf("%d\n", arr[2]-arr[1]]);
        return 0;
    }
    int ans = 0x3f3f3f3f;
    for(int i=2; i<=n-1; i++)
        ans = min(ans, calmax(i));
    printf("%d\n", ans);
}

3 搬圆桌

将一个半径为r的圆桌从(x, y)搬到(x1, y1)处,以圆桌边上一点为中心旋转一次称为搬一次,求最少需要搬几次。

#include <iostream>
#include <cmath>
using namespace std ;

int main(int argc, const char * argv[]) {
    int r, x, y, x1, y1;
    double length, lx, ly, s;
    while (cin>>r>>x>>y>>x1>>y1) {
        lx = (x1-x)>=0 ? (x1-x) : (x-x1);
        ly = (y1-y)>=0 ? (y1-y) : (y-y1);
        length = sqrt(lx*lx + ly*ly);
        s = length/(2*r);
        int t = (int)s;
        if (s - t > 0)
            cout << t+1 <<endl;
        else
            cout << t << endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值