Codeforces Round 969 (Div. 2) A~F

A. Dora’s Set (思维)

题意:

DoraDoraDora有一个包含整数的集合 sss。一开始,她会将 KaTeX parse error: Undefined control sequence: \[ at position 1: \̲[̲l, r\]中的所有整数放入集合 sss。也就是说,整数 xxx最初会在集合中,当且仅当 l≤x≤rl \leq x \leq rlxr时。然后执行以下操作:

  • 从集合 sss中选择三个不同的整数 aaabbbccc,使得 gcd⁡(a,b)=gcd⁡(b,c)=gcd⁡(a,c)=1\gcd(a, b) = \gcd(b, c) = \gcd(a, c) = 1gcd(a,b)=gcd(b,c)=gcd(a,c)=1

  • 从集合 sss中删除这三个整数。

请问可以执行的最大操作数是多少?

分析:

我们考虑倒偶数彼此之间不互质。相邻的奇数是互质的,那么我们只需要统计出区间中奇数个数,两个一对凑对数,除以222即可。

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define endl '\n'
#define PII pair<LL, LL>
const int N = 3e5 + 10;
const int InF = 2e9 + 5;
const int mod = 998244353;
int main()
{
   
   
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
   
   
        int l, r;
        cin >> l >> r;
        int ans;
        if (l & 1)
        {
   
   
            ans = (r - l + 1 + 1) / 2;
        }
        else
        {
   
   
            ans = (r - l + 1) / 2;
        }
        ans /= 2;
        cout << ans << endl;
    }
    return 0;
}

B. Index and Maximum Value (思维)

题意:

给出一个整数数组 a_1,a_2,…,a_na\_1, a\_2, \ldots, a\_na_1,a_2,,a_n按顺序执行 mmm个操作。每个操作都属于以下两种类型之一:

  • + l r\texttt{+ l r}+ l r。给定两个整数 lllrrr,对于所有 1≤i≤n1 \leq i \leq n1inl≤a_i≤rl \leq a\_i \leq rla_ira_i:=a_i+1a\_i := a\_i + 1a_i:=a_i+1

  • - l r\texttt{- l r}- l r。给定两个整数 lllrrr,对于所有 1≤i≤n1 \leq i \leq n1inl≤a_i≤rl \leq a\_i \leq rla_ira_i:=a_i−1a\_i := a\_i - 1a_i:=a_i1

例如,如果初始数组为 KaTeX parse error: Undefined control sequence: \[ at position 5: a = \̲[̲7, 1, 3, 4, 3\],执行操作 + 2 4\texttt{+} \space 2 \space 4+ 2 4后,数组变为 KaTeX parse error: Undefined control sequence: \[ at position 5: a = \̲[̲7, 1, 4, 5, 4\]。然后,执行操作 - 1 10\texttt{-} \space 1 \space 10- </

### Codeforces Round 1005 Div. 2 A-F Problem Solutions #### A. Money Change 为了处理货币转换问题,可以将所有的金额都转化为分的形式来简化计算。通过遍历输入数据并累加各个部分的金额,最后求得剩余的钱数并对100取模得到最终结果[^2]。 ```cpp #include <iostream> using namespace std; int main() { int s, xi, yi; cin >> s; int total_cents = 0; for (int i = 0; i < s; ++i) { cin >> xi >> yi; total_cents += xi * 100 + yi; } cout << (s * 100 - total_cents) % 100 << endl; } ``` #### B. Odd and Even Pairs 此题目要求找到至少一对满足条件的索引:要么是一个偶数值的位置,或者是两个奇数值位置。程序会读入测试次数`t`以及每次测试中的数组长度`n`及其元素,并尝试找出符合条件的一对索引输出;如果没有这样的组合则返回-1[^3]。 ```cpp #include <cstdio> int main() { int t, n, num; scanf("%d", &t); while (t--) { int evenIndex = 0, oddIndex1 = 0, oddIndex2 = 0; scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", &num); if (num % 2 == 0 && !evenIndex) evenIndex = i; else if (num % 2 != 0) { if (!oddIndex1) oddIndex1 = i; else if (!oddIndex2) oddIndex2 = i; } if ((evenIndex || (oddIndex1 && oddIndex2))) break; } if (evenIndex) printf("1\n%d\n", evenIndex); else if (oddIndex1 && oddIndex2) printf("2\n%d %d\n", oddIndex1, oddIndex2); else printf("-1\n"); } return 0; } ``` 由于仅提供了前两道题的具体描述和解决方案,在这里无法继续给出完整的C至F题解答。通常情况下,每一道竞赛编程题都有其独特的挑战性和解决方法,建议查阅官方题解或社区讨论获取更多帮助。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值