SGU 296.Sasha vs. Kate(贪心)】的更多相关文章

上题目: 296. Sasha vs. Kate Time limit per test: 1 second(s)Memory limit: 65536 kilobytes input: standardoutput: standard During the regular Mars's World Finals Subregional Programming Contest a boy Sasha lost N "Mars" bars of chocolate to a girl K…
题意: 给出长度为n(<=1000)的一个数.输出删掉k个数字后的最大值. Solution: 简单贪心. s[i]代表数字s的第i位. 从前往后第一个满足s[i]>s[i-1]的位置,最优一定是删除s[i-1]的.累计次数t. 同时对新得到的数同样处理,这里可以只用一个循环.如果用c++ string的话更加方便. 一直处理到t==k,或者没有满足条件的位置. 如果最后删除的次数t<k,只要从最后删掉k-t个数字. 时间复杂度O(n) #include <iostream>…
题目   SGU 171 相当好的贪心的题目!!!!! 题目意思就是说有K个赛区招收参赛队员,每个地区招收N[i]个,然后每个地区都有一个Q值,而N[i]的和就是N,表示总有N个参赛队员,每个队员都有他自己的P值,和他的权值W,只有当一个队员的P大于某一个地区的Q值时,权值W才能被记录在内,问怎样让着N个参赛队员选择地区才能让权值和最大. 贪心的思路就是按照权值W贪心 1.先按W的降序排序,优先考虑权值交大的. 2.歪了不影响后面的参赛队员,W较大的而且满足P>Q的,让其参加p>Q时Q最大的那…
SGU 280.Trade centers 解题报告 题意: n(<=30000)个城市,(n-1)条道路,求最少需要选择多少个城市建造市场,使得所有城市到任意一个市场的距离不大于k. Solution: 比较好的贪心题.实现起来也有一定技巧. 先以任意点为根,构造出一颗有根树. 首先比较容易想到的是从叶子节点向上寻找,如果只有一个距离为k的点,就把它选上.但是有多个呢? 于是思考更一般的做法,由于是树形结构,先考虑以x节点为根的子树.我们先假设f[x]代表离x节点向下的市场点的距离,这个值可以…
186. The Chain time limit per test: 0.25 sec. memory limit per test: 4096 KB input: standard input output: standard output Smith has N chains. Each chain is the sequence of successively connected links. The length of each chain is known: the first ch…
题意:有n个星球,每个星球有Ai个人,每次有两种选择,第一是从每个星球上去掉1个人,第二个选择是选择一个星球放置一个科学家,将该星球的人数加倍,问最少多少次能够将所有星球上的人数同时变为0,并且如果步数<=1000,还要输出操作顺序. 解法:找出人数最多的那个星球,设最大人数为maxi,那么跑一个循环,每次该星球如果人数<maxi,那么能加倍就加倍到离maxi最近的位置,然后计算他们的差,比如2 1035,加倍后为1024 1035,差为11,那么到时候1024减到11的时候,1035变成了2…
SGU 296 题意:给你一个最多1000位的数,让你删除k位使得剩下的数最大 收获:贪心 #include<bits/stdc++.h> #define de(x) cout<<#x<<"="<<x<<endl; #define dd(x) cout<<#x<<"="<<x<<" "; #define rep(i,a,b) for(int…
Codeforces Round #270 1002 B. Design Tutorial: Learn from Life time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output One way to create a task is to learn from life. You can choose some experience…
链接: http://acm.sgu.ru/problem.php?contest=0&problem=195 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26733#problem/E 195. New Year Bonus Grant time limit per test: 1.5 sec. memory limit per test: 65536 KB input: standard output: standard All…
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…