# Codeforces Round #756 (Div. 3)

A. Make Even
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Polycarp has an integer

• Reverse the prefix of length

Note that for different operations, the values of

Polycarp loves even numbers. Therefore, he wants to make his number even. At the same time, Polycarp is very impatient. He wants to do as few operations as possible.

Help Polycarp. Determine the minimum number of operations he needs to perform with the number

Input

The first line contains the number

Each of the following

Output

Print

Note

In the first test case,

In the second test case,

1. Select
2. Select

It can be shown that

In the third test case,

In the fourth test case,

#include <iostream>
using namespace std;

int main()
{
int t;
cin >> t;
while (t--)
{
string str;
cin >> str;
int temp = -1;
int n;
for (int i = 0; i < str.size(); i++)
{
n = str[i] - '0';
if (n % 2 == 0)
{
temp = 2;
break;
}
}
n = str[0] - '0';
if (n % 2 == 0)
{
temp = 1;
}
n = str[str.size() - 1] - '0';
if (n % 2 == 0)
{
temp = 0;
}
cout << temp << endl;
}
return 0;
}
B. Team Composition: Programmers and Mathematicians
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The All-Berland Team Programming Contest will take place very soon. This year, teams of four are allowed to participate.

There are

• each team must consist of exactly
• teams of

Thus, each team must have at least one programmer and at least one mathematician.

Print the required maximum number of teams. Each person can be a member of no more than one team.

Input

The first line contains an integer

This is followed by descriptions of

Output

Print

Note

In the first test case of the example, two teams can be composed. One way to compose two teams is to compose two teams of

In the second test case of the example, only one team can be composed:

输入两个数代表科学家和数学家的数量，他们要四个人一组去旅游，这四个人中间必须要有一个数学家一个科学家才行，问一共能组成几个队。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
int t;
cin>>t;
int a,b;
int temp;
while(t--)
{
cin>>a>>b;
temp=(a+b)/4;
if(a>b)swap(a,b);
if(temp>=a)cout<<a;
else cout<<temp;
cout<<endl;
}
}
C. Polycarp Recovers the Permutation
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Polycarp wrote on a whiteboard an array

He also prepared a resulting array

After that, he did exactly

• Look at the leftmost and rightmost elements of
• If you picked the leftmost element of
• The picked element is erased from

Note that on the last step,

Let's look at an example. Let

• During the first step, the minimum is on the right (with a value of
• During the second step, the minimum is on the left (with a value of
• During the third step, the minimum is on the left (with a value of
• During the fourth step, the minimum is both left and right (this value is

Thus, a possible value of

You are given the final value of the resulting array

Input

The first line of the input contains an integer

Each test case consists of two lines. The first of them contains an integer

It is guaranteed that the sum of the values

Output

Print

#include <iostream>
using namespace std;

int num1[200000];

int main()
{
int t;
cin >> t;
while (t--)
{
int b; cin >> b;

for (int i = 0; i < b; i++)
{
cin >> num1[i];
}
if (num1[b - 1] != b && num1[0] != b)
{
cout << -1 << endl; continue;
}
if (b == 1 && num1[0] == b) cout << b;
else if (num1[0] == b) {
cout << num1[0] << " ";
for (int i = 0; i < b - 1; i++)
{
cout << num1[b - 1 - i] << " ";
}
cout << endl;
}
else if (num1[b - 1] == b) {
for (int i = 0; i < b - 1; i++)
{
cout << num1[b - 2 - i] << " ";
}
cout << num1[b - 1];
}
cout << endl;
}
return 0;
}

posted @ 2021-11-30 00:15  Sheep灬  阅读(126)  评论(0编辑  收藏  举报