Codefroces 849 A,B】的更多相关文章

A. Odds and Ends time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Where do odds begin, and where do they end? Where does hope emerge, and will they ever break? Given an integer sequence a1, …
AOJ.849 分数 (暴力) 题意分析 每次枚举分子,然后根据给出的分数值,推算出来分母,然后取分母上下几个数进行进一步计算,看看哪个更接近. 一开始想着直接枚举分子和分母,复杂度爆炸... 代码总览 #include <cstdio> #include <algorithm> #include <cmath> #define INF 0x3f3f3f3f using namespace std; int gcd(int a,int b){while(b^=a^=b^…
package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * @ClassName: IsOneBitCharacter * @Author: xiaof * @Description: TODO 717. 1-bit and 2-bit Characters * We have two special characters. The first charac…
problem 849. Maximize Distance to Closest Person solution1: class Solution { public: int maxDistToClosest(vector<int>& seats) { , n = seats.size(); vector<int> pos; ; i<n; ++i) { ) pos.push_back(i); } ; i<pos.size(); ++i) { ) res = m…
849. Maximize Distance to Closest Person 题目链接:https://leetcode.com/problems/maximize-distance-to-closest-person/description/ 思路:pre[i]存放i之前离最近的1的距离.post记录之后的. res = max(min(pre[i],[post[i])) 注意点:初始nst需要设计极大或极小值. 1 int maxDistToClosest(vector<int>&am…
Codefroces 1328E Tree Querie 题目 给出一棵1为根,n个节点的树,每次询问\(k_i\) 个节点,问是否存在这样一条路径: 从根出发,且每个节点在这条路径上或者距离路径的距离为1 题解 由于是从根出发的路径,所以 距离这条路径的距离为1=这个点的父亲在路径上 本身就在根出发的这条路径上,当然这个点的父亲也在路径上 这样我们就把两个条件统一了,转化问题为: 是否存在一条从根出发的路径,使所有点都在这条路径上 根据从根出发的路径的特点,我们根据深度,从小到大排序,每次看后…
AcWing 849 Dijkstra求最短路 I 题解 以此题为例介绍一下图论中的最短路算法.先让我们考虑以下问题: 给定一个 \(n\) 个点 \(m\) 条边的有向图(无向图),图中可能存在重边和自环,给定所有边的边权.请求出给定的一点到另一点的权值之和最小的一条路径. 上述问题即所谓的最短路问题.解决这类问题的常用最短路算法: \(Floyd\) 算法(多源最短路径) \(Dijkstra\) 算法(没有负权边的单源最短路径) \(Bellman\)-\(Ford\) 算法(含有负权边的…
http://codeforces.com/contest/750/problem/D 题意:烟花会绽放n次,每次会向前推进t[i]格,每次绽放会向左右45°绽放,问有烟花的格子数. 思路:n = 30, t = 5,所以最多推进150格.范围很小,开一个300*300的数组,初始位置在(150, 150),直接BFS. #include <cstdio> #include <algorithm> #include <iostream> #include <cst…
http://codeforces.com/contest/750/problem/C 题意:有n场比赛,每场比赛有一个c,代表比赛结束后分数的增长情况,有一个d,代表这场比赛在div1或者div2打.div1 >= 1900,div2 < 1900.求打完这n场比赛后可能得到的最大分数.如果无限大就输出"Inifinity",如果有矛盾就输出"Impossible". 思路:官方题解. For every contest we know that th…
time limit per testsecondsmemory limit per testmegabytesinputstandard inputoutputstandard outputPolycarp has quite recently learned about email aliases. Of course, he used to suspect that the case of the letters doesn't matter in email addresses. He…