C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from t…
感觉很简单,就是讨论一下 #include <stdio.h> #include <string.h> #include <algorithm> #include <math.h> using namespace std; typedef pair<double,int>pii; ; double x[N],y[N]; pii a[N],b[N]; double dis(double x1,double y1,double x2,double y…
题目链接: C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles…
C. Recycling Bottles   It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin. We can think Central Perk as coordinate plane. There are n bott…
C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from t…
C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from t…
CF 628C 题目大意:给定一个长度为n(n < 10^5)的只含小写字母的字符串,以及一个数d,定义字符的dis--dis(ch1, ch2)为两个字符之差, 两个串的dis为各个位置上字符的dis之和,求和给定的字符串的dis为d的字符串,若含有多个则输出任意一个,不存在输出-1 解题思路:简单贪心,按顺序往后,对每一个字符,将其变为与它dis最大的字符(a或者z),d再减去相应的dis, 一直减到d为0,剩余的字母则不变直接输出.若一直到最后一位d仍然大于0,则说明不存在,输出-1. /…
C. Recycling Bottles time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input output: standard output It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles fr…
A. Recycling Bottles 题目连接: http://www.codeforces.com/contest/671/problem/A Description It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin.…
 Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the…
  C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from…
题目链接: http://codeforces.com/contest/672/problem/C 题意: 公园里有两个人一个垃圾桶和n个瓶子,现在这两个人需要把所有的瓶子扔进垃圾桶,给出人,垃圾桶,瓶子的坐标,问两个人需要走的最短距离和. 题解: 首先必须要有一个人先去检一个瓶子,然后走到垃圾桶,这个可以枚举,接下来就是考虑另一个人是也捡一个瓶子然后走到垃圾桶(这个可以预处理出最优的,和次优的,因为如果最优的那个刚好被第一个人拿走了,那就拿次优的)还是在原地不动,接下去就是固定的了,求剩下的所…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them in…
题目链接:http://codeforces.com/problemset/problem/671/A 题目大意:给你两个人的位置和一个箱子的位置,然后给出n个瓶子的位置,要求让至少一个人去捡瓶子放到箱子里面去,一次只能拿一个瓶子,求把全部瓶子捡完之后的距离总和最小.解题思路:开始有两个起点A,B.除了从A或B出发拿瓶子并回到箱子距离不确定,其他时候肯定要从箱子到瓶子再回到箱子,距离就是dis(箱子到瓶子)*2.关于从A,B出发拿瓶子,分三种情况:①只有A拿②只有B拿③A拿一个瓶子,B拿一个瓶子…
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin. We can think Central Perk as coordinate plane. There are n bottles on the ground, the…
d.有一串数字,要把这些数字分成若干连续的段,每段必须至少包含2个相同的数字,怎么分才能分的段数最多? 比如 是1 2 1 3 1 2 1 那么 答案是 21 34 7 即最多分在2段,第一段是1~3,第二段是4~7. 即分成这2段:1 2 1,3 1 2 1 s.很不错的一道贪心的题.当时没怎么细想,后来看了tourist的代码后得知. 可以证明,满足贪心选择性质和最优子结构性质. 贪心策略是:从前向后遍历,每次选择最小长度的符合条件的段. c. #include<iostream> #in…
B. Clique Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The clique problem is one of the most well-known NP-complete problems. Under some simplification it can be formulated as f…
New Year is coming, and Jaehyun decided to read many books during 2015, unlike this year. He has n books numbered by integers from 1 to n. The weight of the i-th (1 ≤ i ≤ n) book is wi. As Jaehyun's house is not large enough to have a bookshelf, he k…
cf 786 B 链接 CF 思路 n个点,3种建边方式,规模\(O(n^2)\) 线段树优化建图 注意 读入的数据好坑啊,说好的v,u变成了u,v. 两棵树,一棵出,一棵入.线段树的作用只不过是按照那个形状建边而已,并没啥用. 初始父亲儿子连边,两棵树的叶子结点一一连边,边权为0.(实际中可以直接共用叶子结点) 大佬的图很不错,引用一下 然后在把其他关系引用到上面就行了 代码 #include <bits/stdc++.h> #define ll long long using namesp…
LINK:Phoenix and Memory 这场比赛标题好评 都是以凤凰这个单词开头的 有凤来仪吧. 其实和Hall定理关系不大. 不过这个定理有的时候会由于 先简述一下. 对于一张二分图 左边集合为S 右边集合为T 那么有完备匹配时 最大匹配数为 min(|S|,|T|). 这里不妨假设|S|<=|T|. 若存在完备匹配那么对于任意集合\(s\in S\)都有s连出的边>=|s|. 这个定理是一张二分图具有完备匹配的充分必要条件. 先证明必要性:如果不存在 那么一定有点无法匹配到. 再证…
Name Quest time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A Martian boy is named s — he has got this name quite recently from his parents for his coming of age birthday. Now he enjoys loo…
题目链接: http://codeforces.com/problemset/problem/671/A 题目大意: A和B在一张二维平面上,平面上有N个垃圾,垃圾桶只有一个在T,问把所有垃圾全扔进垃圾桶最少走多远.一次只能拿一个垃圾.允许一个人走另一个人停下来. (1 ≤ n ≤ 100 000)  (0 ≤ xi, yi ≤ 109) 题目思路: [模拟] 因为每次只能携带一个垃圾,大部分垃圾都是人扔完上一个垃圾后,从垃圾桶出发去捡的. 而最多有两个垃圾不是被人从垃圾桶出发完再扔到垃圾桶.…
暴力. 每个人找到一个入口,也就是从回收站到这个入口走的路程由人的位置到入口的路程来替代. 因此,只要找两个人分别从哪里入口就可以了.注意:有可能只要一个人走,另一人不走. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #includ…
首先考虑一个集合的最大优美值怎么求出 考虑新增一个数,假设我们现在的优美值已经达到了$V$,那么只需要一个$[1, V + 1]$的数就可以使$V$达到更大 为了保证能添加尽可能多的数进来,我们这么构造: 对集合$S$排序,从小到大选择,直到选到$\sum\limits_{i = 1}^{j}v[j] + 1 < v[j]$的$v[j]$,退出 为什么这么做正确呢? 如果不正确,只可能存在一个数$S$可以被大于一个数的和表示,并且满足$v[S] > V + 1$ 其中$v[S]$表示构成$S$…
原题链接:http://codeforces.com/problemset/problem/546/B 原题描述: Soldier and Badges Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has a coolness factor, which shows how much it's owner reached. Coolness factor can b…
J. Bottles time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Nick has n bottles of soda left after his birthday. Each bottle is described by two values: remaining amount of soda ai and bottl…
Description Farmer John 有太多的工作要做啊!!!!!!!!为了让农场高效运转,他必须靠他的工作赚钱,每项工作花一个单位时间. 他的工作日从0时刻开始,有1000000000个单位时间(!).在任一时刻,他都可以选择编号1~N的N(1 <= N <= 100000)项工作中的任意一项工作来完成. 因为他在每个单位时间里只能做一个工作,而每项工作又有一个截止日期,所以他很难有时间完成所有N个工作,虽然还是有可能. 对于第i个工作,有一个截止时间D_i(1 <= D_i…
原文链接https://www.cnblogs.com/zhouzhendong/p/AGC026E.html 题目传送门 - AGC026E 题意 给定一个长度为 $2n$ 的字符串,包含 $n$ 个 $'a'$ 和 $n$ 个 $'b'$ . 现在,让你按照原顺序取出一些字符,按照原顺序组成新的字符串,输出所有满足条件的字符串中字典序最大的?(字典序: $'b'>'a'>'\ '$) 条件限制:当且仅当取了原序列的第 $i$ 个 $'a'$ 时,原序列的第 $i$ 个 $'b'$ 也被取了…
贪心方法:总是对当前的问题作最好的选择,也就是局部寻优.最后得到整体最优. 应用:1:该问题可以通过“局部寻优”逐步过渡到“整体最优”.贪心选择性质与“动态规划”的主要差别. 2:最优子结构性质:某个问题的整体最优解包含了“子”问题的最优解. 程序1 #include <iostream.h> struct goodinfo { float p; //物品效益 float w; //物品重量 float X; //物品该放的数量 int flag; //物品编号 };//物品信息结构体 voi…
题目传送门:https://ac.nowcoder.com/acm/contest/551/G 链接:https://ac.nowcoder.com/acm/contest/551/G来源:牛客网 题目描述 众所周知,CSL 是一个负责的集训队队长.为了让集训队的学弟们训练更加饱和,他根据每个人的能力,提出了 m 个题数要求.假如 CSL 认为 yiyi 比 xixi 强,那么如果 xixi 做了 a 题,那 CSL 会要求 yiyi 需要做至少 a+ri×ka+ri×k,其中 riri 是已知…