CF580B Kefa and Company 尺取法】的更多相关文章

Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company. Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friend…
题目链接:http://codeforces.com/problemset/problem/580/B 某人有n个朋友,这n个朋友有钱数m和关系s两个属性.问如何选择朋友,使得这些朋友之间s最大差距小于d并且钱数是最多. 可以用滑动窗口,将m从小到大,s从大到小排列,这时在一个队列里维护队首和队尾,假如队首和队尾的s差距≥d时,就把队尾扔掉队首入队否则就仅队首入队.此时更新一下当前最大值. #include <cstdio> #include <iostream> #include…
B. Kefa and Company Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/problem/B Description Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company. Kefa has n friends, each friend wi…
Kefa and Company 题意:Kefa这个人要去吃饭,他要邀请一些朋友一起去,他的每个朋友有两个属性金钱和关系度,要求邀请的人里边任意两个人之间的金钱差的绝对值不大于d:求被邀请的所有朋友的关系度的和的最大值. 思路:将朋友按金钱从小到大排序,然后对关系度用尺取法求得最大值 ,这里要用前缀和来求区间内的关系度的和,不然会TLE. 代码: #include <iostream> #include <cstdio> #include <cmath> #includ…
Emily the entrepreneur has a cool business idea: packaging and selling snowflakes. She has devised a machine that captures snowflakes as they fall, and serializes them into a stream of snowflakes that flow, one by one, into a package. Once the packag…
传送门 NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/131072 K (Java/Others)Total Submission(s): 1585    Accepted Submission(s): 688 Description NanoApe, the Retired Dog, has returned back to prepare for for the…
题目大意:从给定序列里找出区间和大于等于S的最小区间的长度. 前阵子在zzuli OJ上见过类似的题,还好当时补题了.尺取法O(n) 的复杂度过掉的.尺取法:从头遍历,如果不满足条件,则将尺子尾 部增加,若满足条件,则逐渐减少尺子头部直到不满足条件为止,保存 尺子长度的最小值(尾部-头部+1)即可. 理论上累计区间和+二分查找的暴力也能过. 代码如下: #include <stdio.h> #include <algorithm> #include <string.h>…
题目链接: 传送门 Sum of Consecutive Prime Numbers Time Limit: 1000MS     Memory Limit: 65536K Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive intege…
题目链接: 传送门 They Are Everywhere time limit per test:2 second     memory limit per test:256 megabytes Description Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possib…
题目链接: 传送门 Kefa and Company time limit per test:2 second     memory limit per test:256 megabytes Description Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company. Kefa has n friends, each friend will agree to…