A. Function Height

由于只能提升\(x\)为奇数的点,每个三角形的底一定为\(2\), 则要求我们求:

\(2 * (h_1 + h_2 + … + h_n) / 2 = k\),使\(max(h_1, h_2…h_n)\)最小。

则应使每个\(h\)平摊重量,答案即为\(\lceil n/k \rceil\)。

#include <cstdio>
#include <iostream>
#include <cmath>
typedef long long LL;
using namespace std;
LL n, k;
int main(){
cin >> n >> k;
cout << ((k % n) ? k / n + 1 : k / n );
return 0;
}

B. Diagonal Walking v.2

设\(a = min(n, m), b = max(n, m)\)

\(b > k\),即使每次最大移动,也不能到达终点。

首先使点移动到\((a, a)\),剩下移动\(b - a\) 次即可到目标,可以考虑交叉移动的方式,但交叉移动必须符合偶数次才行,所以如果不能偶数次,就令\(k\) 少两次机会,让\(b - a\) 与 \(k - a\) 的奇偶性一致。

最后如果\(b - a\) 为奇数,则会少交叉移动一次,最终答案会$ - 1$。

#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
int q;
int main(){
scanf("%d", &q);
while(q--){
LL n, m, k, ans; cin >> n >> m >> k;
if(max(n, m) > k) puts("-1");
else{
if((abs(n - m) & 1) == 0 && (k - min(n, m)) & 1)
n--, m--, k-=2;
ans = min(n, m); k -= min(m, n);
if(abs(m - n) & 1) ans += k - 1;
else ans += k;
cout << ans << endl;
}
}
return 0;
}

C. Classy Numbers

不会数位\(dp\),看了dalao的题解理解了一些

设计一个\(dfs(pos, st, limit)\)

表示处理\(pos\)位数,已经有\(st\)个非\(0\)位(最多3位),有\(limit\)限制代表在求最高限度是\(a[pos]\)下多少个,无限制则最高可填到\(9\)。

  1. 依次从高到低考虑每一位可以填哪些数(\(0 - 9\))

  2. 若为\(0\),则已经\(st\)不变

  3. 若为其他数字,必须保证当前\(st < 3\)才可选择

  4. 若选择与\(a[pos]\)相同的数字,则下一次也需限制选择数字的大小

由于多组数据,若没有限制,可以记忆化搜索,极大增加效率。

#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
int a[20];
LL dp[20][5];
LL dfs(int pos, int st, bool limit){
if(pos == -1) return 1;
if((!limit) && dp[pos][st]) return dp[pos][st];
int up = limit ? a[pos] : 9;
LL res = 0;
for(int i = 0; i <= up; i++){
if(!i) res += dfs(pos - 1, st, limit && i == a[pos]);
else if(st != 3) res += dfs(pos - 1, st + 1, limit && a[pos] == i);
} if(!limit) dp[pos][st] = res;
return res;
}
LL work(LL x){
int tot = 0;
while(x) a[tot++] = x % 10, x /= 10;
return dfs(tot - 1, 0, true);
}
int main(){
int T; scanf("%d", &T);
while(T--){
LL l, r; cin >> l >> r;
cout << work(r) - work(l - 1) << endl;
}
return 0;
}

D. Vasya and Arrays

\(Two-Pointer\)算法,尝试前几项能否堆起来。

#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
const int N = 300010;
int n, m, ans = 0;
LL a[N], b[N];
int main(){
scanf("%d", &n);
for(int i = 1; i <= n; i++) scanf("%lld", a + i), a[i] += a[i - 1];
scanf("%d", &m);
for(int i = 1; i <= m; i++) scanf("%lld", b + i), b[i] += b[i - 1];
if(a[n] != b[m]) puts("-1");
else{
int i = 1, j = 1;
while(true){
if(i > n || j > m) { puts("-1"); break; }
while(a[i] < b[j]){
if(i + 1 > n) { puts("-1"); return 0; }
i++;
}
while(a[i] > b[j]){
if(j + 1 > m){ puts("-1"); return 0; }
j++;
}
if(a[i] == b[j]){
i++, j++, ans++;
if(i == n + 1 && j == m + 1) { printf("%d\n", ans); break; }
}
}
}
return 0;
}

Codeforces Edu Round 50 A-D的更多相关文章

  1. Codeforces Beta Round 84 (Div. 2 Only)

    layout: post title: Codeforces Beta Round 84 (Div. 2 Only) author: "luowentaoaa" catalog: ...

  2. Codeforces Educational Round 92 赛后解题报告(A-G)

    Codeforces Educational Round 92 赛后解题报告 惨 huayucaiji 惨 A. LCM Problem 赛前:A题嘛,总归简单的咯 赛后:A题这种**题居然想了20m ...

  3. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  4. Codeforces Beta Round #62 题解【ABCD】

    Codeforces Beta Round #62 A Irrational problem 题意 f(x) = x mod p1 mod p2 mod p3 mod p4 问你[a,b]中有多少个数 ...

  5. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  6. Codeforces Beta Round #13 C. Sequence (DP)

    题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...

  7. CodeForces Global Round 1

    CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...

  8. Codeforces Global Round 1 - D. Jongmah(动态规划)

    Problem   Codeforces Global Round 1 - D. Jongmah Time Limit: 3000 mSec Problem Description Input Out ...

  9. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

随机推荐

  1. CPU相关的学习

    我理解的CPU 目前对cpu的了解停留在这个水平 查看CPU型号: cat /proc/cpuinfo |grep model |tail -n 1 model name : Intel(R) Xeo ...

  2. SQL IsNull函数详解

    IsNull,计算机语言函数,意思是返回 Boolean 值,指明表达式是否不包含任何有效数据 (Null). ISNULL 使用指定的替换值替换 NULL. IS NULL经常用于组成一个逻辑表达式 ...

  3. IDEA常用插件汇总

    actiBPM idea的Activiti插件,不知道Activiti的可以百度下,用到了再来安装这个插件. Alibaba Java Coding Guidelines Alibaba开发的Java ...

  4. bWAPP----Server-Side Includes (SSI) Injection

    Server-Side Includes (SSI) Injection 什么是SSI和SSI注入 SSI是英文Server Side Includes的缩写,翻译成中文就是服务器端包含的意思.从技术 ...

  5. RSA脚本环境配置-攻防世界-OldDriver

    [Crypto] 题目链接 [RSA算法解密] 审题分析 首先拿到一个压缩包,解压得到文件enc.txt. 先不用去管其他,第一眼enc马上联想到 RSA解密.接着往下看 [{"c" ...

  6. 【C++】归并排序

    性能分析: 时间复杂度:O(n*log(n)) 空间复杂度:O(n) 归并排序算法来自于分而治之思想,"归"是"递归"的意思,"并"是&qu ...

  7. RayFire的下载与安装方法

    RayFire的下载与安装方法 发布时间:2020/10/12 近几年,电影中融入了越来越多的动画元素,其中的爆炸场景更是十分吸引眼球.小编不禁好奇,什么样的插件能做出来如此好玩的特效,上网搜索一番发 ...

  8. nginx介绍及常用功能

    什么是nginx nginx跟Apache一样,是一个web服务器(网站服务器),通过HTTP协议提供各种网络服务. Apache:重量级的,不支持高并发的服务器.在Apache上运行数以万计的并发访 ...

  9. 【CF375D】Trees and Queries——树上启发式合并

    (题面不是来自Luogu) 题目描述 有一个大小为n且以1为根的树,树上每个点都有对应的颜色ci.现给出m次询问v, k,问以v为根的子树中有多少种颜色至少出现了k次. 输入格式 第一行两个数n,m表 ...

  10. LeetCode周赛#209

    1609. 奇偶树 #广搜 #二叉树的层次遍历 题目链接 题意 如果一棵二叉树满足下述几个条件,则可以称为奇偶树 : 二叉树根节点所在层下标为 0 ,根的子节点所在层下标为 1 ,根的孙节点所在层下标 ...