ZOJ-2362 Beloved Sons 贪心 | KM】的更多相关文章

题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2361 来源:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26760#problem/B Beloved Sons Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge Once upon a time there liv…
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2362 裸的匹配问题,直接KM,就算是O(n^4)的KM也不会超.当然注意到题目中左边的点到右点所连的边的权值是一样的,所以完全可以贪心拍个序,然后找增广路... //STATUS:C++_AC_250MS_848KB #include <functional> #include <algorithm> #include <iostream&g…
题目链接:点击打开链接 题意: 给定n个人 每一个人的点权 以下n行i行表示第i个人能够获得哪些数(数字从1-n.且不能反复分配) 若这个人获得了数字则你能够获得他的权值. 要你能获得的权值和最大. 问: 输出每一个人应该获得哪个数字.若没有获得到数字则输出0. 思路: KM,每一个人给每一个数字连一条边,边权是这个人的权值. 对于这个人不能获得的数字连一条边权为0的边. #include <stdio.h> #include <string.h> #define M 410 #d…
Arctic Network The Department of National Defence (DND) wishes to connect several northern outposts by a wireless network. Two different communication technologies are to be used in establishing the network: every outpost will have a radio transceive…
题意:国王有N个儿子,现在每个儿子结婚都能够获得一定的喜悦值,王子编号为1-N,有N个女孩的编号同样为1-N,每个王子心中都有心仪的女孩,现在问如果安排,能够使得题中给定的式子和最大. 分析:其实题目中那个开根号是个烟雾弹,只要关心喜悦值的平方即可.那么对王子和女孩之间构边,边权为喜悦值的平方,对于每一个王子虚拟出一个女孩边权为0,这样是为了所有的王子都能够有女孩可以配对,以便算法能够正确的执行. #include <cstdlib> #include <cstdio> #incl…
题目链接: PKU:http://poj.org/problem?id=1862 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=543 Description Our chemical biologists have invented a new very useful form of life called stripies (in fact, they were first called in Russian -…
Numbers Time Limit: 2 Seconds      Memory Limit: 65536 KB DreamGrid has a nonnegative integer n . He would like to divide n into m nonnegative integers a1,a2,...am and minimizes their bitwise or (i.e.a1+a2+...+am=n  and a1 OR a2 OR a3...OR am should…
贪心.能凑成一组就算一组 Unrhymable Rhymes Time Limit: 10 Seconds      Memory Limit: 32768 KB      Special Judge An amateur poet Willy is going to write his first abstract poem. Since abstract art does not give much care to the meaning of the poem, Willy is plan…
题目链接: http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=3946 题解: 用dijkstra跑单元最短路径,如果对于顶点v,存在一系列边(ui,v)使得dis[v]最小(dis[v]表示0到v的距离).这些边能且只能选一条,那么我们自然应该选cost最小的那个边了. #include<iostream> #include<cstdio> #include<cstring> #include<…
Optiver sponsored problem. After years of hard work Optiver has developed a mathematical model that allows them to predict wether or not a company will be succesful. This obviously gives them a great advantage on the stock market. In the past, Optive…
Pass-Muraille Time Limit: 2 Seconds      Memory Limit: 65536 KB In modern day magic shows, passing through walls is very popular in which a magician performer passes through several walls in a predesigned stage show. The wall-passer (Pass-Muraille) h…
                                                B - Team Formation Description For an upcoming programming contest, Edward, the headmaster of Marjar University, is forming a two-man team from N students of his university. Edward knows the skill level…
Digging Time Limit: 2 Seconds      Memory Limit: 65536 KB When it comes to the Maya Civilization, we can quickly remind of a term called the end of the world. It's not difficult to understand why we choose to believe the prophecy (or we just assume i…
题意:给出一个字符串,有两种操作: 1.插入一个数字  2.交换两个字符   问最少多少步可以把该字符串变为一个后缀表达式(操作符只有*). 解法:仔细观察,发现如果数字够的话根本不用插入,数字够的最低标准为'*'的个数+1,因为最优是 '12*3*..' 这种形式,所以先判断够不够,不够就补,然后从左往右扫一遍,如果某个时刻Star+1>Num,那么从开始到这一段是不合法的,要把那个'*'与后面的一个数字交换,此时Star--,Num++.然后步数++.这样得出的结果就是最后的最小步数. 脑子…
Known Notation Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 Description Do you know reverse Polish notation (RPN)? It is a known notation in the area of mathematics and computer science…
这个题比上个题简单得多,也是超过W时间会睡着,睡着就再也不会卖了,顾客按时间顺序来的,但是可能有顾客同时到(同时到如果醒着就全卖了),并且每个人只买一块面包,也是求最大的W,使得卖出面包的平均价格最高. 同理最大的W一定是某两个相邻人的时间差.因为睡着了就不会醒了,所以枚举的时间差必须越来越大.如果某个时间差比前面枚举过的小也没啥意义(因为在前面就会睡着).因此,直接枚举第i个人和第(i-1)个人的那个时间差(在此之前的时间差都比这个小),然后从第(i+1)个人开始连续一段人的时间差都不超过这个…
大意:给定后缀表达式, 每次操作可以添加一个字符, 可以交换两个字符的位置, 相邻数字可以看做一个整体也可以分开看, 求合法所需最少操作数. 数字个数一定为星号个数+1, 添加星号一定不会更优. 先判断若星号过多, 直接在最左边添上数字, 遍历过程中若星号还多的话把星号与右侧数字交换. #include <iostream> #include <algorithm> #include <cstdio> #include <math.h> #include &…
Known Notation Time Limit: 2 Seconds      Memory Limit: 65536 KB Do you know reverse Polish notation (RPN)? It is a known notation in the area of mathematics and computer science. It is also known as postfix notation since every operator in an expres…
Chiaki has n intervals and the i-th of them is [li, ri]. She wants to delete some intervals so that there does not exist three intervals a, b and c such that aintersects with b, b intersects with c and c intersects with a. Chiaki is interested in the…
题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3862 思路 因为交换次数达到 n + 10 其实我们可以先将他们都重新排序一下 在xoy 坐标系上 从左下角到右上角排序 然后 第2k 和 第 2k+1 之间连一条线 之后只需要交换顺序 来使得原序列变成现在的序列即可 其实在交换的时候 我们就需要交换 新点和旧点 比如这个样例当中 0 0 1 0 1 2 1 1 3 1 0 4 原来的 连接顺序是 1 3 2…
题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3953 题意 给出N个区间,求去掉某些区间,使得剩下的区间中,任何的三个区间都不两两相交. 思路 将所有区间 以左端点为键值从小到大排序 然后三个三个一组 进行判断 如果 这三个中有两两相交的 那么就删去右端点最大的 因为这个区间对答案的贡献最小 然后三个区间当中没有两两相交的,那么下一次进来的区间就替换掉右端点最小的. AC代码 #include <cstdio…
解题思路:给出n件物品,每买三件,折扣为这三件里面最便宜的那一件即将n件物品的价值按降序排序,依次选择a[3],a[6],a[9]----a[3*k] Shopaholic Time Limit: 2 Seconds      Memory Limit: 65536 KB Lindsay is a shopaholic. Whenever there is a discount of the kind where you can buy three items and only pay for…
2013-7-19 shu 新生训练赛:母函数[转换成了背包做的] shuacm 题目:http://acm.hdu.edu.cn/diy/contest_show.php?cid=20083总结:http://blog.csdn.net/cfreezhan/article/details/9385183 2013-7-20 上午 9 点 -- 下午 2 点 湖大第六次训练赛:[1题] HNU_训练赛6[来源zoj月赛] 总结:  A:zoj 3716 Ribbon Gymnastics[神奇的…
[热烈庆祝ZOJ回归] P1002:简单的DFS #include <cstdio> #include <cstring> #include <algorithm> ][]; int N; int input() { scanf("%d",&N); ;i<N;i++) scanf("%s",map[i]); return N; } ][]; ,sizeof(disable)); } int dfs(int cur)…
-----------------------------最优化问题------------------------------------- ----------------------常规动态规划  SOJ1162 I-Keyboard  SOJ1685 Chopsticks SOJ1679 Gangsters SOJ2096 Maximum Submatrix  SOJ2111 littleken bg SOJ2142 Cow Exhibition  SOJ2505 The County…
ZOJ Problem Set - 3829Known Notation(贪心) 题目链接 题目大意:给你一个后缀表达式(仅仅有数字和符号),可是这个后缀表达式的空格不幸丢失,如今给你一个这种后缀表达式,问最少须要多少操作能够把这个表达式变成合法的. 操作: 1.在这个表达式的不论什么位置插入''或者数字(一位数). 2.把这个表达式的不论什么两个位置的字符对换. 解题思路: 一開始想的好复杂,结果还是漏了某种情况,一直过不去:就是卡在了碰到''的时候,数字不够是插入好还是替换好. 事实上仅仅要…
ZOJ - 3963 贪心做一下就好了 反正别用memset #include <iostream> #include <cstdio> #include <sstream> #include <cstring> #include <map> #include <cctype> #include <set> #include <vector> #include <stack> #include &l…
题目传送门 /* 题意:一串字符串,问要最少操作数使得成为合法的后缀表达式 贪心+模拟:数字个数 >= *个数+1 所以若数字少了先补上在前面,然后把不合法的*和最后的数字交换,记录次数 岛娘的代码实在难懂啊~ */ /************************************************ * Author :Running_Time * Created Time :2015-8-16 14:29:49 * File Name :K.cpp **************…
ZOJ - 3715KindergartenElection 题目大意:幼儿园里正在举办班长选举,除1号小朋友外每个人都会投他最好的朋友,但1号小朋友可以贿赂别人(小伙子有丶想法),被贿赂的小朋友就会把票投给1号小朋友而不是他最好的朋友,对于不同的小朋友贿赂的花费也不同,1号小朋友想要自己是唯一的班长(票数最高),问他最少需要花费多少糖果? 由题目来想,很容易想到贪心,但是不知道怎么贪心.如果是简单让1号是票数最高的小朋友,他每次贿赂都有两种选择,一种是贿赂花费小的人来投他,另一种是贿赂票数比他…
借用别人一句话,还以为是个高贵的dp... ... 一打眼一看是波兰式的题,有点懵还以为要用后缀表达式或者dp以下什么什么的,比赛后半阶段才开始仔细研究这题发现贪心就能搞,奈何读错题了!!交换的时候可以任意两个字符交换然而就那么看成了只能相邻的数字字符与'*'字符交换....../(ㄒoㄒ)/~~...但赛后补题的时候发现细节考虑的不好,还是应该锻炼下自己的逻辑整理... 怎么贪咧... 第一步,全数字串即合法,直接输出0即可: 第二步,数字不够的话要添.所谓数字够,即数字的个数至少要比星号个数…