2018网易内推笔试

//第一题修改

#include<iostream>
#include<vector>
#include <deque> 
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> a;
    int temp;
    for (int i = 0; i < n; i++)
    {
        cin >> temp;
        a.push_back(temp);
    }
    deque<int>b;
    deque<int>b1;
    int index = 1;
    int index1 =2;
    b1.push_front(a[0]);
    b1.push_back(a[1]);
    b.push_front(a[0]);
    if (n % 2 == 0) {
        while (index1 < n) {
            b1.push_back(a[index1++]);
            b1.push_front(a[index1++]);
        }
        deque<int>::iterator iv;
        int num = 0;
        for (iv = b1.begin(); iv != b1.end(); iv++)
        {
            if (num == n - 1)
                cout << *iv;
            else
                cout << *iv << " ";
            num++;
        }
    }
    else
    {
        while (index < n) {
            b.push_back(a[index++]);
            b.push_front(a[index++]);
        }
        deque<int>::iterator iv;
        int num = 0;
        for (iv = b.begin(); iv != b.end(); iv++)
        {
            if (num == n - 1)
                cout << *iv;
            else
                cout << *iv << " ";
            num++;
        }
    }

    return 0;
}
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    long long x, f, d, p;
    cin >> x >> f >> d >> p;
    long long day = 0;
    day = min(d / x, (d + f*p) / (x + p));
    cout << day;
    return 0;
}




#include<iostream>
#include<vector>
#include <deque> 
#include<algorithm>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int>person;
    int temp = 0;
    for (int i = 0; i < n; i++) {
        cin >> temp;
        person.push_back(temp);
    }
    sort(person.begin(), person.end());
    deque<int> newperson;
    int low = 0;
    int high = n - 1;
    bool flag = true;//true表示上次的大元素加在队列头部,否则表示加在队列尾部
    while (low<=high) {
        if (low == high)//原来元素个数是奇数
        {
            if (abs(newperson.front() - person[low])>abs(newperson.back() - person[low]))
                newperson.push_front(person[low]);
            else
                newperson.push_back(person[low]);
            break;
        }
        if (flag)
        {
            newperson.push_front(person[low]);
            newperson.push_back(person[high]);
            flag = false;
        }
        else
        {
            newperson.push_back(person[low]);
            newperson.push_front(person[high]);
            flag = true;
        }
        low++;
        high--;
    }
    deque<int>::iterator iv;
    int Sum = 0;
    int Pre = *(newperson.begin());
    if (n == 1)
        return 0;
    for (iv = newperson.begin()+1; iv != newperson.end(); iv++)
    {
        Sum = Sum + abs(*iv - Pre);
        Pre = *iv;
    }
    cout << Sum;
    return 0;

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值