To 洛谷.1432 倒水问题 题目背景 In the movie "Die Hard 3", Bruce Willis and Samuel L. Jackson were confronted with the following puzzle. They were given a 3-gallon jug and a 5-gallon jug and were asked to fill the 5-gallon jug with exactly 4 gallons. This…
洛谷 SP9722 CODESPTB - Insertion Sort 洛谷传送门 题目描述 Insertion Sort is a classical sorting technique. One variant of insertion sort works as follows when sorting an array a[1..N] in non-descending order: for i <- 2 to N j <- i while j > 1 and a[j] <…
题目地址:https://www.luogu.org/problemnew/show/P1032 洛谷训练场BFS的训练题呀. “BFS不就是用队列的思想去遍历一切情况嘛.我已经不是小孩子了,我肯定能做出来!” A FEW MINUTES LATER “QAQ我错了,这题怎么用BFS的思想呀.” 毫无头绪的我选择向题解求助. /学习从来就不是一件容易的事情,但这可以做成一件让自己快乐的事情/ 耐下心来,仔细阅读以及翻资料,终于看明白了ShawnZhou大牛的代码(以下粘贴的代码均是ShawnZh…
[P3817 小A的糖果 小A有N个糖果盒,第i个盒中有a[i]颗糖果. 小A每次可以从其中一盒糖果中吃掉一颗,他想知道,要让任意两个相邻的盒子中加起来都只有x颗或以下的糖果,至少得吃掉几颗糖. [贪心策略]: 因为吃后面的可以影响后面的情况.所以一旦不满足就吃后面的即可. #include<bits/stdc++.h> using namespace std; typedef long long ll; ; ll a[N] , n , x ; int main() { ios_base ::…