Codeforces Round #756 (Div. 3)题解A-F

Codeforces Round #756 (Div. 3)

A. Make Even

分析:

三种情况

  1. 本身是偶数, 答案为0
  2. 十进制最高位是偶数, 答案为1
  3. 十进制非最高位存在偶数, 答案为2

代码:

#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize(2)
#define close(); 	ios::sync_with_stdio(false);
#define endl '\n'
#define rep(i, l, r) for(int i = l; i <= r; i++)
#define dwn(i, r, l) for(int i = r; i >= l; i--)
typedef long long LL;
const int N = 3e5+100;
int a[N];
void solve()
{
   
    LL n; cin >> n;
    if(n % 2 == 0) cout << 0 << endl;
    else 
    {
   
        int cnt = 0;
        int x = 0;
        while(n) 
        {
   
            a[++cnt] = n%10;
            if(a[cnt] % 2 == 0) x = cnt;
            n/=10;
        }
        if(x == 0) cout << "-1" << endl;
        else 
        {
   
            if(x == cnt) cout << 1 << endl;
            else cout << 2 << endl;
        }
    }
}

int main()
{
   
    int T; cin >> T;
    while(T--) solve();
    // system("pause");
}

B. Team Composition: Programmers and Mathematicians

分析:

显然答案是 min ⁡ ( ⌊ a + b 4 ⌋ , a , b ) \min(\lfloor\frac{a+b}{4}\rfloor, a, b) min(4a+b,a,b)

代码:

#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize(2)
#define close(); 	ios::sync_with_stdio(false);
#define endl '\n'
#define rep(i, l, r) for(int i = l; i <= r; i++)
#define dwn(i, r, l) for(int i = r; i >= l; i--)
typedef long long LL;
const int N = 3e5+100;
void solve()
{
   
    LL a, b; cin >> a >> b;
    cout << min( (a+b)/4, min(a, b) ) << endl;
}

int main()
{
   
    int T; cin >> T;
    while(T--) solve();
    // system("pause");
}

C. Polycarp Recovers the Permutation

分析:

容易发现数组a的最大值n, 一定出现在p数组的两端.

也就是说如果如果数组p的两端不存在n, 那么就是不合法的.

然后我们发现了一种构造做法:

在构造数组a的时候, 把n放在一端, 那么每次拿去构造数组p的元素都是在非n端的元素.

于是只需要把数组p翻转即可得到一种可行的数组a.

代码:

#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize(2)
#define close(); 	ios::sync_with_stdio(false);
#define endl '\n'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值