这个题目用贪心来做,关键是怎么贪心最小,那就是排序的问题了. 加入给定两个数a1, b1, a2, b2.那么如果先选1再选2的话,总的耗费就是a1 + a1 * b2 + a2; 如果先选2再选1,总的耗费就是a2 + a2 * b1 + a1.这时比较两个数的大小,发现两边都有a1+a2,所以只是比较a1*b2和a2 * b1的大小. #include <cstdio> #include <cstring> #include <algorithm> using na…
HDU 4442 Physical Examination(贪心) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=4442 Description WANGPENG is a freshman. He is requested to have a physical examination when entering the university. Now WANGPENG arrives at the hospital. Er-.. Th…
Physical Examination Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 6155 Accepted Submission(s): 1754 Problem Description WANGPENG is a freshman. He is requested to have a physical examination wh…
Physical Examination Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4442 Description WANGPENG is a freshman. He is requested to have a physical examination when entering the university. Now WAN…
昨天模拟赛的时候坑了好久,刚开始感觉是dp,仔细一看数据范围太大. 题目大意:一个人要参加考试,一共有n个科目,每个科目都有一个相应的队列,完成这门科目的总时间为a+b*(前面已完成科目所花的总时间).问:怎样安排考试的顺序使考完所花的总时间最短. 分析:假设已经花了time时间,在剩下的科目中任意取两个科目x,y. 先考试x:Tx=time+(ay*time+ax+bx*by*(ax+time)): 先考试y:Ty=time+(by*time+bx+ax+ay*(bx+time)). 化简之后…
Balala Power! Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1411    Accepted Submission(s): 239 Problem Description Talented Mr.Tang has n strings consisting of only lower case characters.…
Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean. The warehouse has N rooms. The i-th room contains J[i] pounds of JavaBeans and requires F[i] pound…
hdu 4825 Xor Sum(trie+贪心) 刚刚补了前天的CF的D题再做这题感觉轻松了许多.简直一个模子啊...跑树上异或x最大值.贪心地让某位的值与x对应位的值不同即可. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #define CLR(a,b) memset((a),(b),sizeof(…
HDU.3342 Legal or Not (拓扑排序 TopSort) 题意分析 裸的拓扑排序 根据是否成环来判断是否合法 详解请移步 算法学习 拓扑排序(TopSort) 代码总览 #include <iostream> #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <sstream> #include…
HDU.1285 确定比赛名次 (拓扑排序 TopSort) 题意分析 裸的拓扑排序 详解请移步 算法学习 拓扑排序(TopSort) 只不过这道的额外要求是,输出字典序最小的那组解.那么解决方案就是每次扫描1-n节点的入度,并且只取出1个编号最小的节点,处理他然后继续取,直到所有节点取出,即可满足字典序最小. 代码总览 #include <iostream> #include <iostream> #include <cstdio> #include <algo…