当前位置:网站首页>Atcoder beginer contest 233 (a~d) solution
Atcoder beginer contest 233 (a~d) solution
2022-07-06 02:38:00 【Time is the most testing person】
AtCoder Beginner Contest 233 Answer key
List of articles
A - 10yen Stamp
【 Topic link 】A - 10yen Stamp (atcoder.jp)
The question : The current number can be added each time 10, Ask at least several times before sending a letter
- x > y: The instructions are enough to send
- x < y: Can't send , Then add 10, know x > y until , Count .
【 Code implementation 】
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <map>
#include <queue>
#include <deque>
#include <vector>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
int main()
{
int x, y;
cin >> x >> y;
if(x >= y) cout << 0;
else
{
int ans = 0;
while(x < y)
{
x += 10;
ans ++;
}
cout << ans;
}
return 0;
}
B - A Revers
【 Topic link 】B - A Reverse (atcoder.jp)
The question : The string s stay [l,r] After the string of is flipped , Output s
Knowledge point : String emulation
【 Code implementation 】
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
#include <deque>
#include <vector>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 1e5 + 10;
char s[N];
int main()
{
int l, r;
scanf("%d%d", &l, &r);
scanf("%s", s + 1);
int len = strlen(s + 1);
// Double pointer to flip
int i = l, j = r;
while(i < j) swap(s[i ++], s[j --]);
printf("%s", s + 1);
return 0;
}
C - Product
【 Topic link 】C - Product (atcoder.jp)
The question : Yes n A package , There are several balls with numbers in each bag , Let you choose a ball in each bag so that the number product is x, Finally, let you be satisfied equal to x Number of alternatives .
notes :
- The range of data
- prune
Knowledge point :DFS
【 Code implementation 】
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
#include <deque>
#include <vector>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 1e5 + 10;
int n, res = 0;
LL target;
vector<LL> a[N];// Two dimensional array
void dfs(int u, LL val)// Choose the number of backpacks What is the weight of the backpack now
{
if(u == n)
{
if(val == target) res ++;
return ;
}
for(int j = 0; j < a[u].size(); j ++)// use vector Make a two-dimensional array , Each layer calls .size(), You can get the number of backpacks in the current layer
{
if(a[u][j] * val > target) continue;// prune
dfs(u + 1, val * a[u][j]);
}
}
int main()
{
scanf("%d%lld", &n, &target);
for(int i = 0; i < n; i ++)
{
int cnt;
scanf("%d", &cnt);
for(int j = 0; j < cnt; j ++)
{
LL value;
scanf("%lld", &value);
a[i].push_back(value);
}
}
dfs(0, 1);
printf("%d", res);
return 0;
}
D - Count Interval
【 Topic link 】D - Count Interval (atcoder.jp)
The question : Statistics s[r]-s[l - 1] == k Number of occurrences
Ideas : If enumerating intervals , Time complexity will explode , Statistics s[r]-s[l - 1] == k Equivalent to statistics s[r]-k == s[l - 1]. And then for each r Just ask s[r]-k The number of , That is to say s[l-1] The number of .s[l-1] It's also a prefix and , Therefore, the number of prefixes and the number of prefixes are increased by the way when looping .( Enumerate the right endpoint to find s[r]-k == s[l - 1] The number of times , It's just that we preprocessed it when counting prefixes and s[l-1] Value , Because it is also the value of prefix and !)
Knowledge point : The prefix and + Hashtable
【 Code implementation 】
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
#include <deque>
#include <vector>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 2e5 + 10;
LL s[N];
int main()
{
LL n, k, res = 0;
scanf("%lld%lld", &n, &k);
unordered_map<LL, LL> hasp;
for(int i = 1; i <= n; i ++)
{
scanf("%lld", &s[i]);
s[i] = s[i] + s[i - 1];
hasp[s[i - 1]] ++;
res += hasp[s[i] - k];
}
printf("%lld", res);
return 0;
}
边栏推荐
- Template_ Find the reverse pair of permutations_ Sort based on merge
- Universal crud interface
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 9
- SSM assembly
- [matlab] access of variables and files
- Accident index statistics
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 22
- DDoS attacks - are we really at war?
- 好用的 JS 脚本
- QT release exe software and modify exe application icon
猜你喜欢

Zero foundation self-study STM32 - Review 2 - encapsulating GPIO registers with structures

Initial understanding of pointer variables

微软语音合成助手 v1.3 文本转语音工具,真实语音AI生成器
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 8](/img/16/33f5623625ba817e6e022b5cb7ff5d.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 8
![[postgraduate entrance examination English] prepare for 2023, learn list5 words](/img/6d/47b853e76d1757fb6e42c2ebba38af.jpg)
[postgraduate entrance examination English] prepare for 2023, learn list5 words

Yyds dry inventory comparison of several database storage engines

一个复制也能玩出花来

2022 eye health exhibition, vision rehabilitation exhibition, optometry equipment exhibition, eye care products exhibition, eye mask Exhibition

Looking at the trend of sequence modeling of recommended systems in 2022 from the top paper
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 10](/img/89/1c2f98973b79e8d181c10d7796fbb5.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 10
随机推荐
Template_ Find the reverse pair of permutations_ Sort based on merge
Force buckle 146 LRU cache
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 18
After changing the GCC version, make[1] appears in the compilation: cc: command not found
[untitled] a query SQL execution process in the database
How to generate rich text online
RobotFramework入门(三)WebUI自动化之百度搜索
Formatting occurs twice when vs code is saved
主数据管理(MDM)的成熟度
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 17
Advanced technology management - what is the physical, mental and mental strength of managers
会员积分营销系统操作的时候怎样提升消费者的积极性?
深度解析链动2+1模式,颠覆传统卖货思维?
Redis installation
I changed the driver to 5.1.35, but it is still the same error. I can succeed even now, but I will report this every time I do an SQL operation
A doctor's 22 years in Huawei
Minecraft 1.18.1, 1.18.2 module development 22 Sniper rifle
Is there a case where sqlcdc monitors multiple tables and then associates them to sink to another table? All operations in MySQL
Solution: attributeerror: 'STR' object has no attribute 'decode‘
How to improve the enthusiasm of consumers when the member points marketing system is operated?