HackerRank - candies 【贪心】】的更多相关文章

HackerRank - candies [贪心] Description Alice is a kindergarten teacher. She wants to give some candies to the children in her class. All the children sit in a line (their positions are fixed), and each of them has a rating score according to his or he…
Boxes and Candies Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement There are N boxes arranged in a row. Initially, the i-th box from the left contains ai candies. Snuke can perform the following operation any number of ti…
原题地址 LeetCode上也有这道题,直接扫一遍就行了,连数组都不用开,感觉像是蕴含了某种动归的思想在里面,要不怎么是个动归题呢 代码: #include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; int main() { /* Enter your code here. Re…
Choosing Points 数学 Integers on a Tree 构造 Leftmost Ball 计数dp+组合数学 Painting Graphs with AtCoDeer tarjan+polya Building Cubes with AtCoDeer 枚举 AtCoDeer and Election Report 贪心 Snuke's Coloring 思维题 Snuke's Coloring 2 线段树+单调栈 Make Them Even 贪心 1D Reversi 模…
[题目链接] A. Charm Is Not Always Enough 模拟一下就可以了. #include <bits/stdc++.h> using namespace std; int T; int main() { scanf("%d", &T); while(T --) { int n, m; long long ans = 0; scanf("%d%d", &n, &m); while(n --) { int x;…
HackerRank - greedy-florist [贪心] 题意 有N个人 要去买K朵花.老板为了最大化新顾客的数量.就压榨回头客.每一朵花都有一个基本价格.一个顾客买下这朵花的价格是他来这里买的次数 * 基本价格 打个比方 如果一个顾客第一次来买 它来买的次数就是1,然后求这N个人买下这K朵花最少需要花多少钱.K朵花必须全部买下来,而且每种价格的花只有一种. 思路 如果 N >= K 那么 就直接对K多花的基本价格求和就可以了. 如果 N < K, 那么我们要充分利用每个客户的购买次数…
传送门 一道挺有意思的贪心. 从1到n依次满足条件. 注意要特判第一个数已经大于x的情况. 但是如何贪心吃呢? 如果靠左的数没有越界,我们吃靠右的数. 原因是下一次靠右的数就会成为靠左的数,相当于多贡献了一次. 然后貌似要开long long 代码: #include<bits/stdc++.h> #define N 100005 #define ll long long using namespace std; ll a[N],x,ans=0; int n; inline ll read()…
https://www.hackerrank.com/contests/illuminati/challenges/tree-covering 这道题先是在上次交流讨论了一下,然后两位百度的朋友先写完代码share出来了,觉得是道很好的题,就做了一下.https://gist.github.com/coder32167/6964331 https://gist.github.com/snakeDling/6965299基本思想是贪心.根据题意,所选的点必然是叶子节点,那么首先找出树的直径,直径上…
Hackerrank 2020 February 2014 解题报告 比赛链接 Sherlock and Watson (20分) 题意:给定一个数组,向右平移K次,然后有Q个询问,问第x位置上是几 做法:直接模拟即可 #include <iostream> using namespace std; int n,k,q; ],b[]; int main(){ ios::sync_with_stdio(); cin>>n>>k>>q; ;i<n;i++)…
[题目] There are N children standing in a line. Each child is assigned a rating value. You are giving candies to these children subjected to the following requirements: Each child must have at least one candy. Children with a higher rating get more can…