【蘑菇街笔试】

来源:互联网 发布:lol账号解封软件 编辑:程序博客网 时间:2024/04/28 19:51

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;}
0 0