CF1199B Water Lily 题解】的更多相关文章

Content 有一朵长在水中的莲花,其茎秆部分露出水面的高度为 \(h\).有人将它往右边拽了 \(l\) 米,使得整个茎秆部分都浸在水中.求池水的深度. 数据范围:\(1\leqslant h<l\leqslant 10^6\). Solution 勾股定理好题,具体根据下面的图来讲讲(其实就是蒯的 CF 的). 我们设水的深度为 \(x\),那么整个茎秆部分的高度为 \(x+h\),又由于我们将它拽了 \(l\) 米之后的茎秆部分的高度不变,所以原来浸在水中的一段,拽的一段以及最后全部浸在…
题意 题目 思路 我一开始想的时候只考虑到一个结点周围的边界的情况,并没有考虑到边界的高度其实影响到所有的结点盛水的高度. 我们可以发现,中间是否能够盛水取决于边界是否足够高于里面的高度,所以这必然是一个从外到内,从小到大的一个过程.因为优先队列必然首先访问的是边界中最小的高度,如果周围小于这个高度那么必然是存在可以盛水的地方,就算是没有也没有任何的损失,只是更新了高度,但是队列依然会从高度小的结点开始访问: 实现 typedef struct node { int x, y; node(int…
题意 题目 思路 一开始想用双向广搜来做,找他们相碰的点,但是发现对其的理解还是不够完全,导致没写成功.不过,后来想清楚了,之前的错误可能在于从边界点进行BFS,其访问顺序应该是找到下一个比当前那个要大的点,但是我写反了..可以先对左边的队列进行BFS,保存其visited,再接着对右边的队列进行BFS,当访问到之前已经访问过的结点时,则加入到结果中. 实现 // // #include "../PreLoad.h" /* Given the following 5x5 matrix:…
比赛链接:https://codeforc.es/contest/1199 A. City Day 题意:给出一个数列,和俩个整数\(x,y\),要求找到序号最靠前的数字\(d\),使得\(d\)满足\(a_d<a_j\) (\(d-x\leq j<d\) && \(d<j\leq d+y\)). 分析:由于x和y都小于7,所以直接暴力即可. AC代码: #include <bits/stdc++.h> #define SIZE 200007 #define…
堆基础 堆(Heap)是具有这样性质的数据结构:1/完全二叉树 2/所有节点的值大于等于(或小于等于)子节点的值: 图片来源:这里 堆可以用数组存储,插入.删除会触发节点shift_down.shift_up操作,时间复杂度O(logn). 堆是优先级队列(Priority queue)的底层数据结构,较常使用优先级队列而非直接使用堆处理问题.利用堆的性质可以方便地获取极值,例如 LeetCode 题目 215. Kth Largest Element in an Array,时间复杂度O(nl…
第二次ak,纪念一下. 比赛链接:https://atcoder.jp/contests/abc183/tasks A - ReLU 题解 模拟. 代码 #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int x; cin >> x; cout << (x >= 0 ? x : 0) <<…
D.City Day 题意:就是给定n,x,y,以及这n天的下雨量ai,要求这一天的下雨量是这一天前x天到后y天的下雨量中最小的.输出最早的(下标最小的)d.保证答案一定存在 思路:直接遍历寻找就好了,做好标记 代码: 1 #include<iostream> 2 #include<algorithm> 3 #include<cstdio> 4 #include<cstring> 5 #include<cmath> 6 using namespa…
题目来源 https://leetcode.com/problems/trapping-rain-water/ Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. For example, Given [0,1,0,2,1,0,1,3,2,1,2,1…
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. For example, Given [0,1,0,2,1,0,1,3,2,1,2,1], return 6. The above elevation map is represented by a…
题目来源: https://leetcode.com/problems/container-with-most-water/ 题意分析: 给出一个n长度的非0数组,a1,a2,……,an,ai代表在坐标i上的高度为ai.以以ai,aj为高,i到j为底,可以构造出一个容器.那么求出这些容器中可以装的水的最大容积(容器不能倾斜).例如数组[2,1],一共可以构造1个容器,这个容器的四个端点坐标是(0,0),(0,2),(1,1),(1,1),那么他可以装的最大的水容积是(1-0)*1 = 1. 题目…
原题传送门:CF343D Water Tree 这道题要用树链剖分,我博客里有对树链剖分的详细介绍 这明显是弱智题 树剖套珂朵莉树多简单啊 前置芝士:珂朵莉树 窝博客里对珂朵莉树的介绍 没什么好说的自己看看吧 先树剖一下 第一种操作,把一个点的子树全部变成1 因为做了树剖,所以珂朵莉树区间赋值就可以了 第二种操作就重链往上跳,重链全变成0,珂朵莉树也能完成 第三种操作直接split一下就行 这道题真的很简单,细节看代码(珂朵莉树实际就是一种暴力) 因为数据随机,所以有可能会有点慢 #pragma…
我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.gitbooks.io/leetbook/ 011. Container With Most Water[M] 问题 Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai).…
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a containe…
problem: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a…
https://leetcode.com/problems/container-with-most-water/ 题目: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0)…
题目: x轴上有一些点,每个点上有一条与x轴垂直的线(线的下端就是这个点,不超出x轴),给出每条线的高度,求这些线与x轴组成的最大面积. 解法: 贪心策略,维持两个指针,分别指向第一个和最后一个元素,对于其中小的一个,它所能围成的最大面积就是到另一个元素之间,所以小的一个要往中间走一步. 代码: class Solution { public: int maxArea(vector<int> &height) { //O(n) , cap; //cap是当前所围成的面积 , end =…
题目链接:https://leetcode.com/problems/trapping-rain-water/description/ 思路: 1.先找到最左侧第一个高度不为0的柱子i. 2.从i+1开始向右侧找另一个柱子max.条件:要么a[max] > a[i],要么a[max] > 右侧所有. 1) 向右侧遍历,当遇到第一个比a[i]高的柱子,相当于遇到一座山,这个柱子会把左右两侧的池子给隔开. 所以,如果遇到第一个比a[i]高的柱子,就停下来.这时候就产生了一个和右侧隔开的池子. 2)…
1.题目描述 2.题目分析 首先,这个题可以使用暴力解法,时间复杂度是O(n^2),这个显然是最容易的做法,但是效率不够高,题目提供了一种解法,使用两个指针,一个从头向尾部,另外一个从尾部向头部,每一步寻找最大的面积,然后较小的一边向前移动. 3.代码实现 int maxArea(vector<int>& height) { ; ; pb < pe ; ) { max_area = max( max_area ,min(*pb , *pe)*(int)(pe -pb)); if(…
class Solution { public: string longestPalindrome(string s) { int length = s.length(); ) return s; ; ; int **pS = new int *[length];//palindromic state ;i < length; i++) pS[i] = ]; ; i < length;i++) { pS[i][] = ; pS[i][] = ; } ; i <= length; i++)…
class Solution { public: int maxArea(vector<int>& height) { ; ; ; while(l < r) { int h = min(height[l], height[r]); int area = h * (r-l); if (area > max) max = area; while (height[l] <= h && l < r) l++; while (height[r] <=…
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我没看,看不懂. 基本思路:我不会. 参考代码:找Oyk老师和Czj老师去. B. The background of water problem 题目大意(大写加粗的水题):给定$N$个学生和他们$K$个科目的成绩$S_i$,再给出各科目$K_i$的权重顺序$Q_i$,求排名之后,拥有id为$X$的…
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-size: 10.5000pt } h1 { margin-top: 5.0000pt; margin-bottom: 5.0000pt; text-align: center; font-family: 宋体; color: rgb(26,92,200); font-weight: bold; fo…
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0,那么这个点就是水龙头点. 如果这个点的出度为0,那么这个点就是储存点. 现在让你把所有水龙头到储存点的路径都输出出来,且输出这条路径的边权最小值 题解 显然是个仙人掌图,所以直接XJB暴力就好了 代码 #include<bits/stdc++.h> using namespace std; co…
博客搬至blog.csgrandeur.com,cnblogs不再更新. 新的题解会更新在新博客:http://blog.csgrandeur.com/2014/01/15/LeetCode-OJ-Solution/ ———————————————————————————————————————— ———————————————————————————————————————— LeetCode OJ 题解 LeetCode OJ is a platform for preparing tech…
Water problem 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5867 Description If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3+3+5+4+4=19 letters used in total.If all the numbers from 1 to n (up to…
A water problem 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5832 Description Two planets named Haha and Xixi in the universe and they were created with the universe beginning. There is 73 days in Xixi a year and 137 days in Haha a year. Now you k…
Problem A: Small change 题解:http://www.cnblogs.com/crazyapple/p/3349469.html Problem B: Scoop water 题解:http://www.cnblogs.com/crazyapple/p/3349478.html Problem D: CX and girls 题解:http://www.cnblogs.com/crazyapple/p/3349480.html Problem F: ZZY and his…
D. Water Tree Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343/problem/D Description Mad scientist Mike has constructed a rooted tree, which consists of n vertices. Each vertex is a reservoir which can be either empty or…
The Water Problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5443 Description In Land waterless, water is a very limited resource. People always fight for the biggest source of water. Given a sequence of wat…
Pahom on Water Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 772    Accepted Submission(s): 355 Problem Description Pahom on Water is an interactive computer game inspired by a short story of…