//第一题修改#include<iostream>#include<vector>#include <deque> usingnamespacestd;
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;
elsecout << *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;
elsecout << *iv << " ";
num++;
}
}
return0;
}
#include<iostream>#include<algorithm>usingnamespacestd;
int main()
{
longlong x, f, d, p;
cin >> x >> f >> d >> p;
longlong day = 0;
day = min(d / x, (d + f*p) / (x + p));
cout << day;
return0;
}
#include<iostream>#include<vector>#include <deque> #include<algorithm>usingnamespacestd;
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)
return0;
for (iv = newperson.begin()+1; iv != newperson.end(); iv++)
{
Sum = Sum + abs(*iv - Pre);
Pre = *iv;
}
cout << Sum;
return0;
}