当前位置:网站首页>Educational Codeforces Round 122 (Rated for Div. 2)
Educational Codeforces Round 122 (Rated for Div. 2)
2022-04-22 06:16:00 【INGg__】
A - Div. 7
题意
更改更少的数字使其原本的数字变为7的倍数
题解
因为7小于10,所以说,10个以内一定会有至少有一个7的倍数
所以说只需要更改最后一位就行了
题目要求如果已经是7的倍数就直接输出,这里要注意一下
Code
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#include <unordered_map>
#define ll long long
#define ull unsigned long long
#define re return
#define pb push_back
#define Endl "\n"
#define endl "\n"
#define x first
#define y second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int, int> PII;
const int N = 1e5 + 10;
const int M = 1e5 + 10;
const int mod = 1000000007;
const int INF = 0x3f3f3f3f;
int dx[4] = {
-1,0,1,0};
int dy[4] = {
0,1,0,-1};
int T;
int n;
void solve(){
cin >> n;
if(n % 7 == 0){
cout << n << endl;
return;
}
for (int i = 0; i < 10; i++){
int x = n / 10 * 10 + i;
if(x % 7 == 0){
cout << x << endl;
return;
}
}
}
int main(){
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
T = 1;
cin >> T;
while(T--){
solve();
}
}
B - Minority
题意
给定一个字符串,让你找到一个子串,可以删除数量最少的0或者1,问最多删除多少个最少的字符
题解
假设存在一个子串,使得某一个位数的值在子串扩大后不会变多,也就是一定会是最终答案了,那么这时候我们扩大子串长度也不会改变其答案,那么我们就不如不去找那个子串,直接就去弄成整个字符串
这样我们直接判断也就行了
Code
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#include <unordered_map>
#define ll long long
#define ull unsigned long long
#define re return
#define pb push_back
#define Endl "\n"
#define endl "\n"
#define x first
#define y second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int, int> PII;
const int N = 1e5 + 10;
const int M = 1e5 + 10;
const int mod = 1000000007;
const int INF = 0x3f3f3f3f;
int dx[4] = {
-1,0,1,0};
int dy[4] = {
0,1,0,-1};
int T;
string s;
void solve(){
cin >> s;
int x = 0;
int y = 0;
for(auto i : s){
if(i == '1')
x++;
else
y++;
}
if(x != y){
cout << min(x, y) << endl;
}
else{
cout << x - 1 << endl;
}
}
int main(){
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
T = 1;
cin >> T;
while(T--){
solve();
}
}
C - Kill the Monster
题意
给定角色的血量和攻击力,还有怪物的血量和攻击力,每次可以花费1金币选择升级血量或者伤害
每次角色先攻击
问在给定的已知双方血量和攻击力,和能花费的最多金币,能不能杀掉怪物
题解
当然我们知道,肯定金币全都用掉好
这时候就要注意题目中给定的k的范围了
k最大到2e5,那么我们可以直接枚举多少钱加血,多少钱加攻击
然后回合制的经典类型,看看谁能撑的更久
Code
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#include <unordered_map>
#define ll long long
#define ull unsigned long long
#define re return
#define pb push_back
#define Endl "\n"
#define endl "\n"
#define x first
#define y second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int, int> PII;
const int N = 1e5 + 10;
const int M = 1e5 + 10;
const int mod = 1000000007;
const int INF = 0x3f3f3f3f;
int dx[4] = {
-1,0,1,0};
int dy[4] = {
0,1,0,-1};
int T;
ll hc;
int dc;
ll hm;
int dm;
int k, w, a;
void solve(){
cin >> hc >> dc;
cin >> hm >> dm;
cin >> k >> w >> a;
// 先加生命
for (int i = 0; i <= k; i++){
ll h = hc + a * i;
ll d = dc + w * (k - i);
// cout << h << ' ' << d << endl;
ll tc = h / dm + (h % dm != 0);
ll tm = hm / d + (hm % d != 0);
if(tc >= tm){
cout << "YES" << endl;
return;
}
}
cout << "NO" << endl;
}
int main(){
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
T = 1;
cin >> T;
while(T--){
solve();
}
}
D - Make Them Equal
题意
原始数组a全为1,每一次可进行操作 a [ i ] = a [ i ] + ⌊ a [ i ] x ⌋ , x < 0 a[i]=a[i] + \lfloor \frac{a[i]}{x} \rfloor,x<0 a[i]=a[i]+⌊xa[i]⌋,x<0,每个数如果达到了与 b [ i ] b[i] b[i]相同的值,就可以获得对应价值 c [ i ] c[i] c[i],问在不超过k次操作下,获得的最大收益是多少
题解
首先我们上来知道第一件事肯定是模拟样例
4 4
1 7 5 2
2 6 5 2
9
第一个样例给的答案是9,那么能凑出来9这个答案的肯定是选择第1、3、4来进行变换的
a[1]=1=b[1],那么得到了c[1]的贡献
如果我们要是将a[2]变成b[2]应该花掉几步呢?
0 1 2 3 4 5
1 2 3/4 5/6 7 ...
经过我们的计算最少应当花掉4步
不知你有没有看懂这个算法,就是将当前的数,加上他除以他前面所有的数的下取整所花的步数再加一
那么花掉4步得到的价值是7,花掉3步得到的价值是5,花掉1步得到夹着2,这是什么
这不就是01背包吗
步数是花费,c是价值,我们预处理出来1e3中的所有的步数,然后跑一下01背包就可以了
Code
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#include <unordered_map>
#define ll long long
#define ull unsigned long long
#define re return
#define pb push_back
#define Endl '\n'
#define endl '\n'
#define x first
#define y second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int, int> PII;
const int N = 1e5 + 10;
const int M = 1e5 + 10;
const int mod = 1000000007;
const int INF = 0x3f3f3f3f;
int dx[4] = {
-1,0,1,0};
int dy[4] = {
0,1,0,-1};
int T;
int n, k;
int b[N];
int c[N];
int f[N * 10];
int base[N];
void get_divisors(int x){
for (int i = 1; i <= x; i++){
base[x + x / i] = min(base[x + x / i], base[x] + 1);
}
}
void solve(){
cin >> n >> k;
for (int i = 1; i <= n; i++){
cin >> b[i];
// cout << b[i] << ' ' << base[b[i]] << endl;
b[i] = base[b[i]];
}
// cout << endl;
for (int i = 1; i <= n; i++){
cin >> c[i];
}
for (int i = 1; i <= n; i++){
for (int j = k; j >= b[i]; j--){
f[j] = max(f[j], f[j - b[i]] + c[i]);
}
}
cout << f[k] << Endl;
memset(f, 0, sizeof(f));
}
int main(){
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
memset(base, 0x3f, sizeof(base));
base[1] = 0;
// base[2] = 1;
for (int i = 1; i <= 1e3; i++){
get_divisors(i);
}
// for (int i = 1; i <= 15; i++){
// cout << i << ' ' << base[i] << endl;
// }
// cout << endl;
T = 1;
cin >> T;
while(T--){
solve();
}
}
版权声明
本文为[INGg__]所创,转载请带上原文链接,感谢
https://blog.csdn.net/INGg__/article/details/123342774
边栏推荐
- Error: [HSI 55-1545], unable to generate fsbl normally, unable to read in MSS file, failed to close system mss
- [Opt 31-67] Problem axi_ Interconnect RTL error
- 小题记录——
- 1. Compile the following three modules of student information management system: and detect the implementation. 1. Add student information 4. Query student information 5. Query all student information
- Anaconda installation and use
- Host cannot Ping virtual machine in bridging mode
- 我们常说的栈帧的内部结构是什么样的呢?
- (1) Download and installation of SQL Server
- (2) Basic configuration of SQL server and connection to SQL server using Navicat
- Redis Advanced
猜你喜欢

Complete a student information management system and systematically practice object-oriented, function, string and other knowledge. Realize the comprehensive application of knowledge. Use classes, fun

(2) Basic configuration of SQL server and connection to SQL server using Navicat

双向循环链表(详)

idea 不显示Run Dashboard视图窗口的问题

带环链表详解

LeetCode - 5 - (重复的子字符串<kmp>、最长回文子串、转置矩阵、二叉树的(左右)视图)

Points for attention in Modelsim simulation acceleration

L2-004 这是二叉搜索树吗?(先序输入&判断搜索二叉树&后序输出)

Define a student class 1 to get the student's name: get_ Name() return type: STR 2 get student's age: get_ Age() return type: int 3 returns the highest score among the three subjects. get_ course()

SQL复习语法笔记整理,新鲜出炉
随机推荐
The only storage area in the JVM where GC and oom will not occur
(六) Sql Server的DCL丶DML语法
SQL review, grammar notes, fresh out
[number theory] congruence (7): fast power, fast power of matrix
SQL复习语法笔记整理,新鲜出炉
L2-004 这是二叉搜索树吗?(先序输入&判断搜索二叉树&后序输出)
LeetCode - 4 - (接雨水、无重复字符的最长子串、分发糖果、二叉树的<前中后层>序遍历)
内部类使用说明(静态、实例、局部)
Quartus II prevents signals from being integrated
Relationship between A5 transceiver signal VOD and pre emphasis adjustment
【数论】素数(四):数的分解(Pollard-rho)
[number theory] congruence (III): univariate linear congruence equation
【数论】素数(一):基本概念、性质、猜想、定理
Win10 Anaconda install cocotb
字节暑期实习一面——20220304
C language | quick sorting
[DRC RTSTAT-1] Unrouted nets: 1 net(s) are unrouted
Redis進階
437. 路径总和 III
[Opt 31-67] Problem axi_ Interconnect RTL error