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. vscode remote wsl 的NoPermissions permission denied问题

    在 wsl这个目录  code-insiders . 之后会报这个错 无法打开"wsl": Unable to read file (NoPermissions (FileSyst ...

  2. Spring源码之IOC容器创建、BeanDefinition加载和注册和IOC容器依赖注入

    总结 在SpringApplication#createApplicationContext()执行时创建IOC容器,默认DefaultListableBeanFactory 在AbstractApp ...

  3. Docker与Ceph的分与合

    前言 docker是一个管理工具,在操作系统之上提供了一个新的独立轻环境,好处是本地提供了一个基础镜像,然后基于镜像再运行环境,也可以把环境重新打包为镜像,管理起来类似于git,感觉非常的方便,并且能 ...

  4. Python _PyQt5 【总】

    http://www.cnblogs.com/archisama/p/5442071.html QtCore QtGui QtWidgets QtMultimedia QtBluetooth QtNe ...

  5. Canvas实现放大镜效果完整案例

    本文主要记录 canvas 在图像.文字处理.离屏技术和放大镜特效的实现过程中使用到的API.先看下效果吧: 一张模糊的图片: 鼠标点击任意位置,产生放大效果: 哇塞~ 一个帅哥,哈哈哈哈~ 1.显示 ...

  6. Spring Cloud Gateway原理

    1.使用 compile 'org.springframework.cloud:spring-cloud-starter-gateway' 2.包结构 actuate中定义了一个叫GatewayCon ...

  7. RedisUtils工具类

    package test.util; import org.springframework.beans.factory.annotation.Autowired; import org.springf ...

  8. scrapy学习之爬虫练习平台35

    前言 上一篇文章中爬取了爬虫练习平台的所有 ssr 网站,都是比较简单的,没有反爬措施,这次来爬一下后面的 spa 系列. 环境准备 这里沿用了上篇文章的环境和设置,就不重新搭建环境了. 开始爬取 s ...

  9. 如何在FL Studio中使用自动剪辑(下)

    在上集中我想大家介绍了FL Stduio Automation Clip的创建.播放列表操作及包络线类型介绍,在这篇文章中我将会给大家介绍如何在播放列表中使用Automation,剪辑通道的操作及使用 ...

  10. H5系列之新input

    虽说H5 新填了几个很方便的input 类型,但是吧,想法是美好的,但是现实很残酷,兼容性不太好.基本只有google浏览器能用.但是既然出了,那么就要了解他,知道有这么一个东西就好. input类型 ...