
贪心
文章平均质量分 81
RJ28
小学生
展开
-
2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 D. Hack Portals(区间DP)
We all have much to be proud of.As a player of the game Ingress, IloveMATH is proud of these portals on the road in front of his campus.Here is a brief introduction of this mobile game. Ingress, a原创 2017-09-21 20:31:42 · 549 阅读 · 0 评论 -
UVALive-3683 A Scheduling Problem(treedp)
题意: 有n(nB表示A必须在B之前完成,A-B表示A和B不能在同一天晚上。输入保证约束图是将一颗树的一些边定向之后得到的。分析: 这题好神,我一开始根据题目的提示想了个错误的贪心,然后疯狂WA了一天。 我一开始错误的贪心是认为对于原图最长链k大于2的情况,答案为k+1当且仅当只有一个无向边定向后参与入了新的最长链的构造,于是我一开始的做法就是特判k = 2的情况原创 2016-11-29 10:30:37 · 774 阅读 · 1 评论 -
Canada Cup 2016 E. Too Much Money(贪心)
Alfred wants to buy a toy moose that costs c dollars. The store doesn’t give change, so he must give the store exactlyc dollars, no more and no less. He has n coins. To make c dollars from his coi原创 2016-10-30 17:55:57 · 377 阅读 · 0 评论 -
CodeForces - 17C Balance(DP)
DescriptionNick likes strings very much, he likes to rotate them, sort them, rearrange characters within a string... Once he wrote a random string of characters a, b, c on a piece of paper and b原创 2016-11-06 20:35:52 · 879 阅读 · 0 评论 -
Codeforces Beta Round #10 E. Greedy Change(贪心)
Billy investigates the question of applying greedy algorithm to different spheres of life. At the moment he is studying the application of greedy algorithm to the problem about change. There is an amo原创 2016-10-23 16:33:57 · 836 阅读 · 0 评论 -
Codeforces Round #371 (Div. 1) C. Sonya and Problem Wihtout a Legend(贪心+DP)
Sonya was unable to think of a story for this problem, so here comes the formal description.You are given the array containing n positive integers. At one turn you can pick any element and increase原创 2016-09-14 17:30:59 · 428 阅读 · 0 评论 -
Hdu-5821 Ball(贪心)
Problem DescriptionZZX has a sequence of boxes numbered 1,2,...,n. Each box can contain at most one ball.You are given the initial configuration of the balls. For 1≤i≤n, if the i-th bo原创 2016-08-11 21:36:17 · 471 阅读 · 0 评论 -
LA 7339 Owllen(贪心)
题意:给定一个长度为n的字符串(26个小写字母),让你再构造一个长度为n的字符串,使得两串的LCS最小。分析:选原串中出现次数最少的字母构造就可以了,可以证明这样一定是LCS最小。#include#include#include#include#include#include#include#include#include#include#include原创 2016-08-22 14:24:03 · 368 阅读 · 0 评论 -
Codeforces Round #370 (Div. 2) C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side lengthx, and he wishes to perform operations to obtain an equilateral原创 2016-09-11 23:20:08 · 216 阅读 · 0 评论 -
Codeforces Round #364 (Div. 1) B. Connecting Universities(图论)
Treeland is a country in which there are n towns connected byn - 1 two-way road such that it's possible to get from any town to any other town.In Treeland there are 2k universities which are loc原创 2016-09-10 01:22:49 · 303 阅读 · 0 评论 -
Gym 100886J Sockets(二分+贪心)
Valera has only one electrical socket in his flat. He also has m devices which require electricity to work. He's got n plug multipliers to plug the devices, the i-th plug multiplier has ai socke原创 2016-08-29 21:18:58 · 573 阅读 · 0 评论 -
Ural 2045 Richness of words(构造)
045. Richness of wordsTime limit: 0.5 secondMemory limit: 64 MBFor each integer i from 1 to n, you must print a stringsi of length n consisting of lowercase Latin letters.The stringsi原创 2016-08-07 20:56:32 · 532 阅读 · 2 评论 -
LA 7464 Robots(贪心)
题意:有X和Y两类机器人各n m个,现在要将所有机器人上的信息传送到基点Base.同一时刻每个机器人(包括Base)只能发给一个对象,也只能接受一个对象的信息.X类的机器人发送数据的时间是x,Y类的是y. (x 分析:f(n,m) = f(n,(m-n)/2) + y (m >= n) f(n,m) = f((n-m)/(pow(2,y/x)) + m,0原创 2016-08-17 21:39:16 · 394 阅读 · 0 评论 -
Hdu-5573 Binary Tree(贪心构造)
The Old Frog King lives on the root of an infinite tree. According to the law, each node should connect to exactly two nodes on the next level, forming a full binary tree.Since the king is profess原创 2016-08-02 21:49:00 · 672 阅读 · 0 评论 -
Ural 2041 Nanomatryoshkas(贪心)
Matryoshka is a traditional Russian recursive doll. But everything changes, and even matryoshka needs a little innovation.Due to the use of new materials, it became possible to make a matryoshka arbit原创 2016-08-12 16:39:52 · 380 阅读 · 0 评论 -
Hdu-5915 The Fastest Runner Ms. Zhang(环套树DP)
Problem DescriptionMs. Zhang is a journalist from Hong Kong, and she runs very very fast, so every one calls her “The fastest runner”. There are n cities (numbered from 1 to n) and n roads in the co原创 2016-11-01 21:58:00 · 901 阅读 · 0 评论 -
Codeforces Round #380 Div. 1 C. Subordinates(贪心)
There are n workers in a company, each of them has a unique id from1 to n. Exaclty one of them is a chief, his id is s. Each worker except the chief has exactly one immediate superior.There was原创 2016-11-30 09:47:47 · 317 阅读 · 0 评论 -
2017 ACM-ICPC 亚洲区(西安赛区)网络赛 E. Maximum Flow
Given a directed graph with nnn nodes, labeled 0,1,⋯,n−10,1, \cdots, n-10,1,⋯,n−1.For each i,j> satisfies 0≤i0≤ijn, there exists an edge from the i-th node to the j-th node, the capacity of wh原创 2017-09-16 21:56:39 · 342 阅读 · 0 评论 -
Uva-1632 Alibaba(贪心)
题意:直线上有n(n 分析:因为没有内存限制所以可以直接上n^2dp,但是我用了贪心的做法,优先访问di小的点,好像也没有什么不对(按di排序后每次选最小的去走).#include #define N 100005using namespace std;typedef pair pii;int n,vis[10005],p[10005],d[10005];pii原创 2017-04-08 12:10:42 · 460 阅读 · 2 评论 -
2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 Colored Graph(贪心构造)
In graph theory, graph colouring is a special case of graph labelling.It is an assignment of labels traditionally called colours to edges of a graph.Here we consider the simplest form.Given an u原创 2017-09-14 00:02:30 · 323 阅读 · 0 评论 -
Hdu-6049 Sdjpx Is Happy(贪心)
Sdjpx is a powful man,he controls a big country.There are n soldiers numbered 1~n(11.He can divides soldiers into K disjoint non-empty subarrays. 2.He can sort a subarray many times untill a subar原创 2017-07-28 23:07:28 · 1299 阅读 · 11 评论 -
Codeforces Round #410 (Div. 2) D. Mike and distribution(贪心)
Mike has always been thinking about the harshness of social inequality. He's so obsessed with it that sometimes it even affects him while solving problems. At the moment, Mike has two sequences of pos原创 2017-04-24 15:34:59 · 525 阅读 · 0 评论 -
Codeforces Round #407 (Div. 1) B. Weird journey
Little boy Igor wants to become a traveller. At first, he decided to visit all the cities of his motherland — Uzhlyandia.It is widely known that Uzhlyandia has n cities connected with m bidirectio原创 2017-04-02 23:23:17 · 518 阅读 · 0 评论 -
Uva-1228 Integer Transmission(贪心+DP)
题意:你要在一个仿真网络中传输一个n比特的非负整数k。各比特从左到右传输,第i个比特的发送时间个i。每个比特的网络延迟总是0~d之间的实数。若同时有多个比特到达,实际收到的顺序任意。求实际收到的整数有多少种,以及它们的最小值和最大值。分析:最大值就是把所有的0都设置d延迟所有1设置0延迟,最小相反。对于一个数p现在我们想判断它能不能通过对k设置一定延迟来得到,很容易发现这个问题可以直接原创 2017-03-29 15:45:34 · 934 阅读 · 0 评论 -
Codeforces Round #403 C. Underground Lab(脑洞)
The evil Bumbershoot corporation produces clones for gruesome experiments in a vast underground lab. On one occasion, the corp cloned a boy Andryusha who was smarter than his comrades. Immediately And原创 2017-03-06 16:19:05 · 573 阅读 · 0 评论 -
Codeforces Round #403 B. Innokenty and a Football League(二分图匹配)
Innokenty is a president of a new football league in Byteland. The first task he should do is to assign short names to all clubs to be shown on TV next to the score. Of course, the short names should原创 2017-03-06 14:20:33 · 468 阅读 · 0 评论 -
Codeforces Round #402 (Div. 1) D. Parquet Re-laying(脑洞)
Peter decided to lay a parquet in the room of size n × m, the parquet consists of tiles of size 1 × 2. When the workers laid the parquet, it became clear that the tiles pattern looks not like Peter原创 2017-03-09 11:20:46 · 447 阅读 · 0 评论 -
Codeforces Round #397 E. Tree Folding(脑洞)
Vanya wants to minimize a tree. He can perform the following operation multiple times: choose a vertex v, and two disjoint (except for v) paths of equal length a0 = v, a1, ..., ak, and b0 = v, b原创 2017-03-08 10:12:34 · 290 阅读 · 0 评论 -
ICPCCamp 2017 Day 6: U of Tokyo Selection 1 - Problem A. Spanning Trees
题意:给一个N个点的完全图,让你输出k个边不重复的生成树。分析:如果k > n/2直接无解,否则我们用类似数学归纳法的方法构造;可以发现从2开始才有解,而且n每增加2其构造方案数才能+1,当n为奇数时,我们可以让第n个点直接向前边的点连边来继承n-1的所有方案;当n为偶数时,我们可以直接继承n-2的所有方案,并且让[1,(n-2)/2]的边连向n-1,[(n-2)/2+1,n-原创 2017-02-20 09:05:37 · 543 阅读 · 0 评论 -
Codeforces Round #383 (Div. 1) C. Arpa’s overnight party and Mehrdad’s silent entering(贪心,二分图)
Note that girls in Arpa’s land are really attractive.Arpa loves overnight parties. In the middle of one of these parties Mehrdad suddenly appeared. He saw n pairs of friends sitting around a tab原创 2016-12-07 12:07:12 · 445 阅读 · 0 评论 -
Codeforces Round #380 Div. 1 B. Sea Battle(贪心)
Galya is playing one-dimensional(肤浅的) Sea Battle on a1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive(连贯的) cells. No cell can be part of two s原创 2016-11-30 10:02:52 · 292 阅读 · 0 评论 -
Uva 11054 Wine trading in Gergovia(贪心模拟)
题意:直线上有n个等距的村庄,每个村庄要么买酒要么卖酒,把k个单位的酒从一个村庄运送到另一个村庄需要k个单位的劳动力,问最少需要多少劳动力。分析:考虑最左边的村庄,它的需求是a[i],那么它需要向第二个村庄转移abs(a[i])个需求,第二个村子现在需求为a[1]+a[2],再转移abs(a[1]+a[2])...以此类推累加答案即可。#include#include#原创 2016-07-31 21:31:15 · 498 阅读 · 0 评论 -
LA 4850 Installations (贪心)
Description In the morning, service engineers in a telecom company receive a list of jobs which they must serve today. They install telephones, internet, ipTVs, etc and repair troubles with establ原创 2016-04-29 20:17:51 · 2130 阅读 · 0 评论 -
Codeforces Round #283 (Div. 2) D. Tennis Game
Petya and Gena love playing table tennis. A single match is played according to the following rules: a match consists of multiple sets, each set consists of multiple serves. Each serve is won by one o原创 2016-05-10 23:59:10 · 839 阅读 · 0 评论 -
Codeforces Round #298 (Div. 2) D. Handshakes
On February, 30th n students came in the Center for Training Olympiad Programmers (CTOP) of the Berland State University. They came one by one, one after another. Each of them went in, and before sitt原创 2016-05-24 10:19:51 · 393 阅读 · 0 评论 -
Uva 11100 The Trip
题目大意: 给n个正整数,把它们划分成尽量少的严格递增序列(前一个数必须小于后一个数)。问序列的最小个数和这些序列。分析:很容易想到最小次数就是数列中重复出现最多的数的出现次数,然后这道题输出方案上有些技巧,每次输出序列下标膜ans同余的子序列,这样肯定可以完全按升序分割掉整个序列。#include #include #include #define MAXN 1000原创 2016-04-28 16:51:31 · 346 阅读 · 0 评论 -
Codeforces 526C - Om Nom and Candies
A sweet little monster Om Nom loves candies very much. One day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. Would you succeed with原创 2016-05-10 19:37:14 · 1241 阅读 · 0 评论 -
VK Cup 2015 - Qualification Round 2 C. Name Quest
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 looking for his name everywhere. If he sees that he can obtain his name fr原创 2016-05-10 11:16:13 · 451 阅读 · 0 评论 -
VK Cup 2016 - Round 3 B. Counting Rhombi
Bearland has n cities, numbered 1 through n. Cities are connected via bidirectional roads. Each road connects two distinct cities. No two roads connect the same pair of cities.Bear Limak was once原创 2016-05-10 14:23:35 · 524 阅读 · 0 评论 -
Uva 11134 Fabled Rooks
链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2075题目大意:在一个n*n的棋盘上放置n个车,使得它们之间都不能互相攻击(任意两个车都不能同行或同列),并且,对于第i个车,限制它只能放在一个矩形区域内,(xl原创 2016-04-28 00:33:46 · 373 阅读 · 0 评论