AtCoder Beginner Contest 233
考完期末的第一场AtCoder
A_10yen_Stamp
题目大意
输入两个数,一个是现在的金钱,一个是要达到的金钱,每次最小加10,这里我们直接特判就行
代码实现
/*
* @Description: 电影和人生不一样,电影太仁慈了,人生太辛苦了
* @CSDN: https://blog.csdn.net/godhandsjoker?spm=1000.2115.3001.5343
* @Github: https://github.com/godhandsjoker
* @QQ: 3124406837
* @Author: godhands
* @LastEditTime: 2021-12-25 20:01:00
*/
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define int long long
#define endl '\n'
void solve() {
int x, y;
cin >> x >> y;
if (x >= y) {
cout << "0\n";
} else {
int tmp = y - x;
if (tmp % 10 == 0) {
cout << tmp / 10 << endl;
} else {
cout << tmp / 10 + 1 << endl;
}
}
}
signed main()
{
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
solve();
return 0;
}
B_A_Reverse
题目大意
给定两个正整数,一个是左端点,一个是右端点,再给定一个字符串,然后把左端点到右端点这段的字符串颠倒,
其他的不动,然后输出最后变化过后的一个字符串
代码实现
/*
* @Description: 电影和人生不一样,电影太仁慈了,人生太辛苦了
* @CSDN: https://blog.csdn.net/godhandsjoker?spm=1000.2115.3001.5343
* @Github: https://github.com/godhandsjoker
* @QQ: 3124406837
* @Author: godhands
* @LastEditTime: 2021-12-25 20:06:21
*/
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define int long long
#define endl '\n'
void solve() {
int l, r;
string s, s1 = "", s2 = "", s3 = "";
cin >> l >> r >> s;
l--, r--;
for (int i = 0; i < l; i++) s1 += s[i];
for (int i = l; i <= r; i++) s2 += s[i];
reverse(s2.begin(), s2.end());
for (int i = r + 1; i < s.size(); i++) s3 += s[i];
cout << s1 + s2 + s3 << endl;
}
signed main()
{
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
solve();
return 0;
}
C_Product
题目大意
其实就是给你n个袋子,然后要每一个袋子取一个球,问有多少种可能使得乘积为我们输入的值
然后先输入一个n(代表n个袋子),在输入一个x(代表要到达的值)
然后接下来n行每行一个l(代表这个袋子里面有多少个球),然后输入l个数字,代表每一个球的值
然后实现起来,直接爆搜就可以了
代码实现
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define int long long
#define endl '\n'
const int N = 1e5 + 10;
map<int, int> mp[N];
int n, l, tmp, x, ans;
void dfs(int u, int res, int cnt) {
if (res > x) return;
if (u == n + 1) {
if (res == x) ans += cnt;
return;
}
for (auto &[a, b] : mp[u]) {
dfs(u + 1, res * a, cnt * b);
}
}
void solve() {
cin >> n >> x;
for (int i = 1; i <= n; i++) {
cin >> l;
for (int j = 1; j <= l; j++) {
cin >> tmp;
mp[i][tmp]++;
}
}
dfs(1, 1, 1);
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
solve();
return 0;
}
D_Count_Interval
题目大意
首先给定一个n和x,n代表有n个数字,x代表我们最后要找到的一个连续的区间的和为x
然后输入n个数字,求有多少个连续的区间的和为x
这个题目其实就是一个裸题,只要预先处理一个前缀和,就完全是一个一模一样的板子题目了
直接存一个map,每次看是否出现即可
代码实现
/*
* @Description: 电影和人生不一样,电影太仁慈了,人生太辛苦了
* @CSDN: https://blog.csdn.net/godhandsjoker?spm=1000.2115.3001.5343
* @Github: https://github.com/godhandsjoker
* @QQ: 3124406837
* @Author: godhands
* @LastEditTime: 2021-12-25 21:54:01
*/
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <unordered_map>
using namespace std;
#define int long long
#define endl '\n'
void solve() {
int n, x, res = 0;
cin >> n >> x;
vector<int> a(n), sum(n);
for (auto& it : a) cin >> it;
sum[0] = a[0];
for (int i = 1; i < n; i++) sum[i] = a[i] + sum[i - 1];
map<int, int> mp;
for (int i = 0; i < n; i++) {
if (sum[i] == x) res++;
auto it = mp.find(sum[i] - x);
if (it != mp.end()) res += it->second;
mp[sum[i]]++;
}
cout << res << endl;
}
signed main()
{
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
solve();
return 0;
}