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. close与shutdown

    首先看一个例子,如下图所示: 当我们客户端发送ABCD再close套接字的时候,服务器端的接收通道也被关闭了,将无法接收ABCD的数据.如果想要仅仅关闭发送通道,保留接收通道,可以使用shutdown ...

  2. Nacos 多环境配置

    本文探讨Nacos作为配置中心,如何实现不同环境(开发.测试.灰度.正式)的配置管理问题 就像Maven用groupId.artifactId.version三者来定位jar包在仓库中的位置一样,Na ...

  3. 2018.1.15复习_ css+js

    [1]几个常见的css标签:--------------------------------------------------background-color; 设置背景颜色background-p ...

  4. git key生成

    1.打开git ssh 2.检查home目录的ssh目录是否存在,没有创建一个,mkdir ~/.ssh 3.运行命名:ssh-keygen -t rsa -C "你的邮箱", 如 ...

  5. 讲一讲Java的字符串常量池,看完你的思路就清晰了

    前言 很多朋友Java的字符串常量池的概念困扰了很长一段时间,最近研究了一下jvm指令码,终于对它有了大概的了解. 在展示案例前,我们需要先搞清楚一个概念,众所周知,jvm的内存模型由程序计数器.虚拟 ...

  6. MindManager导出Word文档功能介绍

    Mindmanager思维导图软件作为一款能与Microsoft office软件无缝集成的思维导图软件,支持Word文档的快速导入与导出,并支持Word文档的目录生成.模板套用等,极大地方便了用户完 ...

  7. 粉丝少的UP主如何赚大钱

    常逛B站的小伙伴应该知道,B站官方经常会推出各类征稿活动,奖金池也非常高,少则几万,多则上百万,可以说非常受UP主们的欢迎. 图1:B站各类活动 要知道,除了少数头部UP主可能因为没(有)有(钱)看( ...

  8. 通过PHPExcel将Excel表文件中数据导入数据库

    1 <?php 2 header("Content-Type:text/html;charset=utf-8"); 3 include_once 'PHPExcel.php' ...

  9. java运算符与程序逻辑控制

    一.运算符 java中的运算符大致分为四种:数学运算符,关系运算符.逻辑运算符.位运算 1.数学运算符:即咱们平常说的加减乘除运算,这种运算是分先后顺序的,如果想要优先进行运算,建议加上小括号,使其运 ...

  10. python接口测试4-数据库获取参数

    首先确定需要传递的参数和接口,使用接口测试工具验证一下,接口和参数没有问题. 编写python接口脚本 import requests import unittest import json impo ...