Educational Codeforces Round 74 #div2 ABCD

A. Prime Subtraction

Description

给两个数$x,y,x \gt y$,判断$x-y$是否为一个素数的整数倍

Solution

由唯一分解可得每个大于1的数都可以唯一分解为素数幂次之积,显然只需要判断x-y是否大于1即可

 1 #include <algorithm>
 2 #include <cctype>
 3 #include <cmath>
 4 #include <cstdio>
 5 #include <cstdlib>
 6 #include <cstring>
 7 #include <iostream>
 8 #include <map>
 9 #include <numeric>
10 #include <queue>
11 #include <set>
12 #include <stack>
13 #if __cplusplus >= 201103L
14 #include <unordered_map>
15 #include <unordered_set>
16 #endif
17 #include <vector>
18 #define lson rt << 1, l, mid
19 #define rson rt << 1 | 1, mid + 1, r
20 #define LONG_LONG_MAX 9223372036854775807LL
21 #define pblank putchar(‘ ‘)
22 #define ll LL
23 #define fastIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
24 using namespace std;
25 typedef long long ll;
26 typedef long double ld;
27 typedef unsigned long long ull;
28 typedef pair<int, int> P;
29 int n, m, k;
30 const int maxn = 1e5 + 10;
31 template <class T>
32 inline T read()
33 {
34     int f = 1;
35     T ret = 0;
36     char ch = getchar();
37     while (!isdigit(ch))
38     {
39         if (ch == ‘-‘)
40             f = -1;
41         ch = getchar();
42     }
43     while (isdigit(ch))
44     {
45         ret = (ret << 1) + (ret << 3) + ch - ‘0‘;
46         ch = getchar();
47     }
48     ret *= f;
49     return ret;
50 }
51 template <class T>
52 inline void write(T n)
53 {
54     if (n < 0)
55     {
56         putchar(‘-‘);
57         n = -n;
58     }
59     if (n >= 10)
60     {
61         write(n / 10);
62     }
63     putchar(n % 10 + ‘0‘);
64 }
65 template <class T>
66 inline void writeln(const T &n)
67 {
68     write(n);
69     puts("");
70 }
71 int main(int argc, char const *argv[])
72 {
73 #ifndef ONLINE_JUDGE
74     freopen("in.txt", "r", stdin);
75     // freopen("out.txt", "w", stdout);
76 #endif
77     int t = read<int>();
78     while (t--)
79     {
80
81         ll x = read<ll>(), y = read<ll>();
82         if (x - y == 1)
83             puts("NO");
84         else
85             puts("YES");
86     }
87
88     return 0;
89 }

B. Kill ‘Em All

Description

小明想要消灭一群在x正半轴的怪兽。

给出一个怪兽x坐标序列,导弹作用半径r。

小明每次可以选择一个坐标抛一个炸弹,处于炸弹中心的怪兽直接被消灭,处于炸弹右边的怪兽被推移到x+r的位置,同理左边被推到x-r,x为怪兽坐标。

同样被移到原点或者负半轴也会死亡。

求最少能消灭所有怪兽的炸弹数。

Solution

对于炸弹右边的怪兽,由于右边没有限制,可以被推送到无穷远处,而之后还是需要一颗炸弹来消灭,所以往右推移是不可取的。

那么贪心思路就是从最右开始扔炸弹,知道全部被消灭或者移到非正半轴

  1 #include <algorithm>
  2 #include <cctype>
  3 #include <cmath>
  4 #include <cstdio>
  5 #include <cstdlib>
  6 #include <cstring>
  7 #include <iostream>
  8 #include <map>
  9 #include <numeric>
 10 #include <queue>
 11 #include <set>
 12 #include <stack>
 13 #if __cplusplus >= 201103L
 14 #include <unordered_map>
 15 #include <unordered_set>
 16 #endif
 17 #include <vector>
 18 #define lson rt << 1, l, mid
 19 #define rson rt << 1 | 1, mid + 1, r
 20 #define LONG_LONG_MAX 9223372036854775807LL
 21 #define pblank putchar(‘ ‘)
 22 #define ll LL
 23 #define fastIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
 24 using namespace std;
 25 typedef long long ll;
 26 typedef long double ld;
 27 typedef unsigned long long ull;
 28 typedef pair<int, int> P;
 29 int n, m, k;
 30 const int maxn = 1e5 + 10;
 31 template <class T>
 32 inline T read()
 33 {
 34     int f = 1;
 35     T ret = 0;
 36     char ch = getchar();
 37     while (!isdigit(ch))
 38     {
 39         if (ch == ‘-‘)
 40             f = -1;
 41         ch = getchar();
 42     }
 43     while (isdigit(ch))
 44     {
 45         ret = (ret << 1) + (ret << 3) + ch - ‘0‘;
 46         ch = getchar();
 47     }
 48     ret *= f;
 49     return ret;
 50 }
 51 template <class T>
 52 inline void write(T n)
 53 {
 54     if (n < 0)
 55     {
 56         putchar(‘-‘);
 57         n = -n;
 58     }
 59     if (n >= 10)
 60     {
 61         write(n / 10);
 62     }
 63     putchar(n % 10 + ‘0‘);
 64 }
 65 template <class T>
 66 inline void writeln(const T &n)
 67 {
 68     write(n);
 69     puts("");
 70 }
 71 vector<ll> vec;
 72 int main(int argc, char const *argv[])
 73 {
 74 #ifndef ONLINE_JUDGE
 75     freopen("in.txt", "r", stdin);
 76     // freopen("out.txt", "w", stdout);
 77 #endif
 78     int t = read<int>();
 79     while (t--)
 80     {
 81         n = read<int>();
 82         ll r = read<int>();
 83         vec.clear();
 84         for (int i = 0; i < n; i++)
 85         {
 86             ll x = read<ll>();
 87             vec.emplace_back(x);
 88         }
 89         sort(vec.begin(), vec.end());
 90         auto curend = unique(vec.begin(), vec.end());
 91         int sz = (int)(curend - vec.begin());
 92         int q = 0;
 93         for (int i = sz - 1; i >= 0; i--)
 94         {
 95             if (vec[i] - q * r <= 0)
 96                 break;
 97             ++q;
 98         }
 99         writeln(q);
100     }
101     return 0;
102 }

C. Standard Free2play

Description

Solution

找规律可以发现对于连续的一个1状态,如果其长度为奇数,那么这一段1可以无需消耗钻石安稳降落。

而如果长度为偶数,那么它一定得降到最后一个1之上,到最后一个1的时候由于开关触碰,会掉到x-1位置,这时候需要消耗一个钻石保证认为无伤。

模拟即可。注意特判最后一段1序列

  1 #include <algorithm>
  2 #include <cctype>
  3 #include <cmath>
  4 #include <cstdio>
  5 #include <cstdlib>
  6 #include <cstring>
  7 #include <iostream>
  8 #include <map>
  9 #include <numeric>
 10 #include <queue>
 11 #include <set>
 12 #include <stack>
 13 #if __cplusplus >= 201103L
 14 #include <unordered_map>
 15 #include <unordered_set>
 16 #endif
 17 #include <vector>
 18 #define lson rt << 1, l, mid
 19 #define rson rt << 1 | 1, mid + 1, r
 20 #define LONG_LONG_MAX 9223372036854775807LL
 21 #define pblank putchar(‘ ‘)
 22 #define ll LL
 23 #define fastIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
 24 using namespace std;
 25 typedef long long ll;
 26 typedef long double ld;
 27 typedef unsigned long long ull;
 28 typedef pair<int, int> P;
 29 int n, m, k;
 30 const int maxn = 2e5 + 10;
 31 template <class T>
 32 inline T read()
 33 {
 34     int f = 1;
 35     T ret = 0;
 36     char ch = getchar();
 37     while (!isdigit(ch))
 38     {
 39         if (ch == ‘-‘)
 40             f = -1;
 41         ch = getchar();
 42     }
 43     while (isdigit(ch))
 44     {
 45         ret = (ret << 1) + (ret << 3) + ch - ‘0‘;
 46         ch = getchar();
 47     }
 48     ret *= f;
 49     return ret;
 50 }
 51 template <class T>
 52 inline void write(T n)
 53 {
 54     if (n < 0)
 55     {
 56         putchar(‘-‘);
 57         n = -n;
 58     }
 59     if (n >= 10)
 60     {
 61         write(n / 10);
 62     }
 63     putchar(n % 10 + ‘0‘);
 64 }
 65 template <class T>
 66 inline void writeln(const T &n)
 67 {
 68     write(n);
 69     puts("");
 70 }
 71 unordered_map<int, int> mp;
 72 int a[maxn];
 73 int main(int argc, char const *argv[])
 74 {
 75 #ifndef ONLINE_JUDGE
 76     freopen("in.txt", "r", stdin);
 77     // freopen("out.txt", "w", stdout);
 78 #endif
 79     int t = read<int>();
 80     while (t--)
 81     {
 82         int h = read<int>();
 83         n = read<int>();
 84         for (int i = 0; i < n; i++)
 85             a[i] = read<int>();
 86         int res = 0;
 87         int cnt = 1;
 88         for (int i = 1; i < n; i++)
 89         {
 90             if (a[i] == a[i - 1] - 1)
 91                 ++cnt;
 92             else
 93             {
 94                 if (!(cnt & 1))
 95                     ++res;
 96                 cnt = 0;
 97             }
 98         }
 99         if (!(cnt & 1) && a[n - 1] > 1)
100             ++res;
101         writeln(res);
102     }
103     return 0;
104 }

D. AB-string

Description

Solution

题解也太妙了8,正着想了好久没想到怎么做。

题解思路,最终good=all-bad

对于bad串,只会出现四种情况。

ABBBBB,BBBBBA

AAAAAB,BAAAAA

那么前后各扫一遍即可,前后可能有长度为2的bad串重复计算,需要减去重复贡献。

 1 #include <algorithm>
 2 #include <cctype>
 3 #include <cmath>
 4 #include <cstdio>
 5 #include <cstdlib>
 6 #include <cstring>
 7 #include <iostream>
 8 #include <map>
 9 #include <numeric>
10 #include <queue>
11 #include <set>
12 #include <stack>
13 #if __cplusplus >= 201103L
14 #include <unordered_map>
15 #include <unordered_set>
16 #endif
17 #include <vector>
18 #define lson rt << 1, l, mid
19 #define rson rt << 1 | 1, mid + 1, r
20 #define LONG_LONG_MAX 9223372036854775807LL
21 #define pblank putchar(‘ ‘)
22 #define ll LL
23 #define fastIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
24 using namespace std;
25 typedef long long ll;
26 typedef long double ld;
27 typedef unsigned long long ull;
28 typedef pair<int, int> P;
29 int n, m, k;
30 const int maxn = 3e5 + 10;
31 template <class T>
32 inline T read()
33 {
34     int f = 1;
35     T ret = 0;
36     char ch = getchar();
37     while (!isdigit(ch))
38     {
39         if (ch == ‘-‘)
40             f = -1;
41         ch = getchar();
42     }
43     while (isdigit(ch))
44     {
45         ret = (ret << 1) + (ret << 3) + ch - ‘0‘;
46         ch = getchar();
47     }
48     ret *= f;
49     return ret;
50 }
51 template <class T>
52 inline void write(T n)
53 {
54     if (n < 0)
55     {
56         putchar(‘-‘);
57         n = -n;
58     }
59     if (n >= 10)
60     {
61         write(n / 10);
62     }
63     putchar(n % 10 + ‘0‘);
64 }
65 template <class T>
66 inline void writeln(const T &n)
67 {
68     write(n);
69     puts("");
70 }
71 char s[maxn];
72 int main(int argc, char const *argv[])
73 {
74 #ifndef ONLINE_JUDGE
75     freopen("in.txt", "r", stdin);
76     // freopen("out.txt", "w", stdout);
77 #endif
78     n = read<int>();
79     scanf("%s", s);
80     ll res = 1LL * (n - 1) * n / 2;
81     int pre = 0;
82     for (int i = 1; i < n; i++)
83         if (s[i] != s[i - 1])
84             res -= i - pre - 1, pre = i;
85     pre = n - 1;
86     for (int i = n - 2; i >= 0; i--)
87         if (s[i] != s[i + 1])
88         {
89             res -= pre - i;
90             pre = i;
91         }
92     writeln(res);
93     return 0;
94 }

原文地址:https://www.cnblogs.com/mooleetzi/p/11754165.html

时间: 2024-07-28 23:35:41

Educational Codeforces Round 74 #div2 ABCD的相关文章

Educational Codeforces Round 74 (Rated for Div. 2)补题

慢慢来. 题目册 题目 A B C D E F G 状态 √ √ √ √ × ? ? //√,×,? 想法 A. Prime Subtraction res tp A 题意:给定\(x,y(x>y)\),问能否将\(x-y\)拆成任意多个质数之和 1.任意大于\(1\)的整数\(k\)都可以用\(2\)与\(3\)的线性表示 证: 若\(k\)是偶数,显然: 若\(k\)是奇数,则\(k\)可以表示成\(k = 3 + 2*k'\),显然: 毕. #include<bits/stdc++.h&

educational codeforces round 58 (div2) D. GCD Counting

这道题每个节点都由子节点的不同状态转移过来,只要子节点可以整除这个节点的的某个质因子,就可以转移.为了遍历找到本节点的质因子对应于这个节点子节点的哪些状态,需要开个map<pair<int,int> ,int>来存储 #include<bits/stdc++.h> using namespace std; typedef pair<int,int> P; vector<int> G[200001]; vector<int> vec[2

A. Prime Subtraction ( Educational Codeforces Round 74 (Rated for Div. 2) )

You are given two integers xx and yy (it is guaranteed that x>yx>y). You may choose any prime integer pp and subtract it any number of times from xx. Is it possible to make xx equal to yy? Recall that a prime number is a positive integer that has ex

codeforces Round #250 (div2)

a题,就不说了吧 b题,直接从大到小排序1-limit的所有数的lowbit,再从大到小贪心组成sum就行了 1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #define N 200000 6 using namespace std; 7 int pos[N],a[N],s[N],f[N],la[N],b[N],i,j,k,ans,n,p

Educational Codeforces Round 23 F. MEX Queries(线段树)

题目链接:Educational Codeforces Round 23 F. MEX Queries 题意: 一共有n个操作. 1.  将[l,r]区间的数标记为1. 2.  将[l,r]区间的数标记为0. 3.  将[l,r]区间取反. 对每个操作,输出标记为0的最小正整数. 题解: hash后,用线段树xjb标记一下就行了. 1 #include<bits/stdc++.h> 2 #define ls l,m,rt<<1 3 #define rs m+1,r,rt<&l

Educational Codeforces Round 21 F. Card Game(网络流之最大点权独立集)

题目链接:Educational Codeforces Round 21 F. Card Game 题意: 有n个卡片,每个卡片有三个值:p,c,l; 现在让你找一个最小的L,使得满足选出来的卡片l<=L,并且所有卡片的p的和不小于k. 选择卡片时有限制,任意两张卡片的c之和不能为质数. 题解: 和hdu 1565 方格取数(2)一样,都是求最大点权独立集. 不难看出来,这题再多一个二分. 注意的是在构造二部图的时候,按照c值的奇偶性构造. 当c==1时要单独处理,因为如果有多个c==1的卡片,

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars There are n pillars aligned in a row and numbered from 1 to n. Initially each pillar contains exactly one disk. The i-th pillar contains a disk having radius ai. You can move these disks

Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations

原文链接:https://www.cnblogs.com/xwl3109377858/p/11405773.html Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations You are given a sequence of n pairs of integers: (a1,b1),(a2,b2),…,(an,bn). This sequence is called bad if it is

Educational Codeforces Round 21 G. Anthem of Berland(dp+kmp)

题目链接:Educational Codeforces Round 21 G. Anthem of Berland 题意: 给你两个字符串,第一个字符串包含问号,问号可以变成任意字符串. 问你第一个字符串最多包含多少个第二个字符串. 题解: 考虑dp[i][j],表示当前考虑到第一个串的第i位,已经匹配到第二个字符串的第j位. 这样的话复杂度为26*n*m*O(fail). fail可以用kmp进行预处理,将26个字母全部处理出来,这样复杂度就变成了26*n*m. 状态转移看代码(就是一个kmp