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. Golang调度器GMP原理与调度全分析(转 侵 删)

    该文章主要详细具体的介绍Goroutine调度器过程及原理,包括如下几个章节. 第一章 Golang调度器的由来 第二章 Goroutine调度器的GMP模型及设计思想 第三章 Goroutine调度 ...

  2. 异常记录-Dialog样式踩坑

    好久没记录文档了,拖了老半个月,终于空下来时间,为了避免以后踩坑,必须记录记录. 背景: 为activity设置样式为弹窗activity 异常一: activity设置style后,布局不能够正常显 ...

  3. CCF-201512-消除类游戏

    问题描述 试题编号: 201512-2 试题名称: 消除类游戏 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 消除类游戏是深受大众欢迎的一种游戏,游戏在一个包含有n行m列的游 ...

  4. 在线动态修改ulimit

    前言 系统中有些地方会进行资源的限制,其中的一个就是open file的限制,操作系统默认限制的是1024,这个值可以通过各种方式修改,本篇主要讲的是如何在线修改,生产上是不可能随便重启进程的 实践 ...

  5. ImportError: No module named 'chardet'

    1.使用requsets出现这个错误,ImportError: No module named 'chardet' 原因:requests依赖其他一些模块 解决:依次使用pip安装即可 pip ins ...

  6. [LeetCode题解]23. 合并K个升序链表 | 分治 + 递归

    方法一:分治 + 递归 解题思路 在21. 合并两个有序链表,我们知道如何合并两个有序链表.而本题是合并 k 个有序链表,可以通过大问题拆分成小问题解决,即把 k 个链表,拆分成 k/2 个链表组,俩 ...

  7. 深入理解r2dbc-mysql

    目录 简介 r2dbc-mysql的maven依赖 创建connectionFactory 使用MySqlConnectionFactory创建connection 执行statement 执行事务 ...

  8. NPOT纹理与平铺模式OpenGL规范

    OpenGL规范从2.0开始支持显示边长为非2次幂的Texture,但限制条件是需要环绕模式为CLAMP_TO_EDGE并且过滤模式为NEAREST或者LINEAR. 解除限制的条件是硬件支持OES_ ...

  9. Qt QPainter画个球啊

    Qt QPainter画个球啊 目录 Qt QPainter画个球啊 看效果 方法 代码 看效果 方法 使用绘图事件,绘制一个图形 使用定时事件,不停更新图形位置 代码 .h #pragma once ...

  10. CTF-流量分析笔记

    ---恢复内容开始--- 前言 做流量分析很长时间了但是一直没有系统的去总结过这类题目的做法和思路以及wireshark的使用方法,这次做题的时候突然发现了一个总结的特别好的博客,因此想趁机做个笔记总 ...