0、常用技巧
文章平均质量分 60
童凌
当你停下来休息的时候,不要忘记别人还在奔跑!——一个普通的软件工程专业学生
展开
-
0x3f3f3f3f…编程中无穷大常量的设置技巧
转载自http://www.xuebuyuan.com/1263959.html如果问题中各数据的范围明确,那么无穷大的设定不是问题,在不明确的情况下,很多程序员都取0x7fffffff作为无穷大,因为这是32-bit int的最大值。如果这个无穷大只用于一般的比较(比如求最小值时min变量的初值),那么0x7fffffff确实是一个完美的选择,但是在更多的情况下,0x7f转载 2015-05-26 08:52:05 · 736 阅读 · 0 评论 -
[贪心] poj 2376 Cleaning Shifts
Cleaning Shifts Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13438 Accepted: 3467 DescriptionFarmer John is assigning some of his N (1 <= N <= 25,000) cows to do some clean原创 2015-08-04 19:21:39 · 491 阅读 · 0 评论 -
[二分]poj3061 Susequence
Subsequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9895 Accepted: 3999 DescriptionA sequence of N positive integers (10 < N < 100 000), each of them less than or equal 1原创 2015-08-03 10:21:39 · 489 阅读 · 0 评论 -
[技巧]集合的二进制整数表示
先看一个题:poj3279 fliptilehttp://blog.csdn.net/tlonline/article/details/47066733在这题目中,需要枚举出第一行所有可能的表现形式。为了尝试第一行的所有可能性,使用了集合的整数表示方法。在程序中表示集合的方法有很多种,当元素比较少时,像这样,用二进制码来表示比较方便。集合{0,1,2…n-1}的子集可以用以下方式编码成整数。原创 2015-08-03 14:35:36 · 1517 阅读 · 0 评论 -
[尺取法] poj3061 Subsequence
http://poj.org/problem?id=3061//设置以下的算法: //1、给定起点s=e=1; //2、e一直往后走,直到sum(s,t)>S 更新res //3、减去第一个数,然后回到步骤2#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace原创 2015-08-03 10:41:47 · 359 阅读 · 0 评论 -
[二分] 二分搜索,不光是用来查找值
例: 给定n,k值,数组中有n个数,求满足ai==k条件的最小的i。Sample input 10 2 4 6 7 8 10 12 13 15 16 8 9 11 …Sample output Ans:5 Ans:6 Ans:7用二分的思想,可以很轻松地将其范围搜索到对应的区间:#include <iostream>#include <cstdio>using namespa原创 2015-07-22 16:25:58 · 632 阅读 · 0 评论 -
[折半枚举] poj 2785 4 Values whose Sum is 0
Values whose Sum is 0 Time Limit: 15000MS Memory Limit: 228000K Total Submissions: 17715 Accepted: 5209 Case Time Limit: 5000MS DescriptionThe SUM problem can be formulated as follows: g原创 2015-08-03 15:19:21 · 507 阅读 · 0 评论 -
[尺取法] poj3320 Jessica's Reading Problem
Jessica’s Reading Problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8531 Accepted: 2732 DescriptionJessica’s a very lovely girl wooed by lots of boys. Recently she has a pr原创 2015-08-03 12:44:21 · 511 阅读 · 0 评论 -
[二分]poj 1064 Cable Master
M - Cable master Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u SubmitStatus Description Inhabitants of the Wonderland have decided to hold a regional programming cont原创 2015-08-01 15:23:04 · 436 阅读 · 0 评论 -
[贪心]poj1017 packets
题目链接:POJ1017-packets题意:一个工厂制造的产品形状都是长方体盒子,它们的高度都是 h,长和宽都相等,一共有六个型号,分别为1*1, 2*2, 3*3, 4*4, 5*5, 6*6。这些产品通常使用一个 6*6*h 的长方体箱子包装然后邮寄给客户。因为邮费很贵,所以工厂要想方设法的减小每个订单运送时的箱子数量BoxNum。 由于盒子和箱子原创 2015-07-20 15:54:25 · 466 阅读 · 0 评论 -
[贪心]HDU1085 Moving Tables
D - Moving Tables Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u SubmitStatus Description The famous ACM (Advanced Computer Maker) Company has rented a floor of a buil原创 2015-07-24 13:44:58 · 447 阅读 · 0 评论 -
[区间合并,优化] hdu5358多校联合 第六场 First one
First One Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 142 Accepted Submission(s): 37Problem Description soda has an integer array a1原创 2015-08-07 10:01:02 · 631 阅读 · 0 评论 -
[枚举+贪心] hdu5353多校联合 第六场 Average
http://acm.hdu.edu.cn/showproblem.php?pid=5353枚举第一个人对第二个人的三种操作,然后这样第i个人必然对第i+1个人按照 1.少一个糖果就从下一个人手中拿一个 2.多一个就给一个给下一个人 3.刚好就是平均数跳过 4.无解 这四种操作贪心即可。#include<map>#include<string>#include<cstring>#in原创 2015-08-07 10:06:11 · 558 阅读 · 1 评论 -
[贪心+优先队列] hdu5360多校联合 第六场 Hiking
http://acm.hdu.edu.cn/showproblem.php?pid=5360贪心的思路还是比较好想的,每次选择cur(已经邀请成功的人数)所在的区间中右端点最小的(因为右端点大的在后面可以邀请成功的几率大),然后很自然的想到可以用一个优先队列来维护这些区间,只要每次把左端点小于等于cur的区间放到优先队列中即可。#include<cstdio>#include<cstring>#原创 2015-08-07 10:15:12 · 475 阅读 · 0 评论 -
[贪心]hdu5355 多校联合第六场 Cake
首先我们是能够知道每份蛋糕的尺寸的,利用 n*(n+1)/2m可以算出来, 如果不能整除的话,那么一定无解。然后我们考虑如何构造一组解,对于一块蛋糕,我想到了一个贪心策咯,尽量选择最大块的蛋糕,因为如果能选但是不选这块蛋糕,那么也一定是通过选取小块的蛋糕来拼凑出这块蛋糕的大小,但是如果小的拼凑出了这块,那么就不能用于拼凑其他的蛋糕,显然选择最大的这块是最优的,因为他不可能被用来拼凑出其他的蛋糕。原创 2015-08-07 10:19:09 · 690 阅读 · 0 评论 -
[贪心] poj3040 Allowance
http://poj.org/problem?id=3040#include <iostream>#include<algorithm>#include<math.h>#include<stdio.h>#include<string.h>const int INF=0x3f3f3f3f;using namespace std;struct node{ int val,num;/原创 2015-08-07 11:31:05 · 786 阅读 · 0 评论 -
[贪心] poj3262 Protecting the Flowers
Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5343 Accepted: 2105 DescriptionFarmer John went to cut some wood and left N (2 ≤ N ≤ 100,000) cows eating t原创 2015-08-07 17:19:17 · 461 阅读 · 0 评论 -
[贪心] hdu5386 多校联合第八场 Cover
CoverTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1049 Accepted Submission(s): 217Special JudgeProblem DescriptionYou have原创 2015-08-14 11:15:01 · 569 阅读 · 0 评论 -
algorithm中的next_permutation函数
这个函数是按照字典序用来生成全排列,做一些枚举,搜索啊这些很暴力的时候很有用,特别是需要字典序输出的时候,以前很苦恼的字典序问题用现在的方法,好像可以解决了。。先来看一个例子:#include <algorithm>#include <iostream>#include<cstdio>using namespace std;int main(){ int a[] = {1,2,3,5原创 2015-08-05 15:18:42 · 516 阅读 · 0 评论 -
[二分+模拟]poj 3273 Monthly Expense
Description Farmer John is an astounding accounting wizard and has realized he might run out of money to run the farm. He has already calculated and recorded the exact amount of money (1 ≤ moneyi ≤ 10原创 2015-08-01 13:59:49 · 434 阅读 · 0 评论 -
[二分+贪心] poj 2456 Aggressive cows
N - Aggressive cows Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u SubmitStatus Description Farmer John has built a new long barn, with N (2 <= N <= 100,000) stalls. T原创 2015-08-01 15:48:22 · 487 阅读 · 0 评论 -
[二分]poj2976 Dropping tests
E - Dropping tests Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u SubmitStatus Description In a certain course, you take n tests. If you get ai out of bi questions cor原创 2015-08-01 17:00:09 · 522 阅读 · 0 评论 -
[二分+贪心]2015百度之星初赛第一场 序列变换
序列变换Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 158 Accepted Submission(s): 83Problem Description给定序列A={A1,A2,...,A原创 2015-05-31 09:41:21 · 799 阅读 · 0 评论 -
[递归]Vicsek Fractal
题目描述Vicsek分形是一种美丽的正方形分形图案。一阶的Vicsek分形是一个正方形:#二阶的Vicsek分形是会在一阶的基础上扩展:# . #. # .# . #同样的,三阶的Vicsek分形是在二阶的基础上原创 2015-05-19 09:22:41 · 1201 阅读 · 0 评论 -
[RMQ+二分] 2015多校联合第一场 Assignment
AssignmentTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1626 Accepted Submission(s): 388Problem Description Tom owns a company and he原创 2015-07-22 15:24:53 · 440 阅读 · 0 评论 -
[贪心] HDU1009 FatMouse' Trade
A - FatMouse’ Trade Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u SubmitStatus Description FatMouse prepared M pounds of cat food, ready to trade with the cats guardi原创 2015-07-24 10:22:37 · 358 阅读 · 0 评论 -
[离散化]求区域的个数
w×h的格子上画了n条垂直或水平的宽度为1的直线,求出这些线将鸽子划分成了多少个区域? 1<=w,h<=1000000 1<=n<=500准备好w*h的数组,并记录是否有直线通过,然后用普通dfs的方法,可以求出被分割出的区域个数。但是这个问题中w和h最大为1000000,不能开w*h的数组。所以,我们要用坐标离散化的技巧。如上图所示,将前后没有变化的行列消除后,并不会影响区域的个数。#in原创 2015-07-21 10:41:11 · 861 阅读 · 0 评论 -
[二分、贪心]Codeforces Round #307 (Div. 2) C.GukiZ hates Boxes
H - GukiZ hates BoxesTime Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64uSubmit Status Practice CodeForces 551CDescriptionProfessor GukiZ is concerned ab原创 2015-07-16 12:10:37 · 651 阅读 · 0 评论 -
[贪心]HDU2037 今年暑假不AC
今年暑假不AC Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u SubmitStatus Description “今年暑假不AC?” “是的。” “那你干什么呢?” “看世界杯呀,笨蛋!” “@#$%^&*%…” 确实如此,世界杯来了,球迷的节日也来了,估计很多ACMe原创 2015-07-24 20:50:20 · 507 阅读 · 0 评论 -
[枚举]BestCoder 1st Anniversary$1002 Hidden String
Hidden String Accepts: 437 Submissions: 2174 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)问题描述今天是BestCoder一周年纪念日. 比赛管理员Soda有一个长度为n的字符串原创 2015-07-26 11:53:27 · 540 阅读 · 0 评论 -
[水题] HDU 1049 Climbing Worm
C - Climbing Worm Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u SubmitStatus Description An inch worm is at the bottom of a well n inches deep. It has enough energy t原创 2015-07-24 13:15:58 · 420 阅读 · 0 评论 -
[贪心]poj1862 Stripies
http://poj.org/problem?id=1862 简单题,每次取最大的两个做运算即可。#include <iostream>#include<algorithm>#include<queue>#include<cstdio>#include<cmath>#include<cstring>using namespace std;int n;int main(){原创 2015-08-07 16:31:53 · 579 阅读 · 0 评论 -
[二分+贪心] POJ 3258 River Hopscotch
Description Every year the cows hold an event featuring a peculiar version of hopscotch that involves carefully jumping from rock to rock in a river. The excitement takes place on a long, straight riv原创 2015-08-01 12:41:03 · 479 阅读 · 0 评论 -
[二分]poj3104 Drying
C - Drying Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u SubmitStatus Description It is very hard to wash and especially to dry clothes in winter. But Jane is a very原创 2015-08-01 15:04:58 · 478 阅读 · 0 评论 -
求最大连续区间和的几种方法
今天做bestcoder想到的,几种做最大连续区间和的方法。定义最大连续区间和:给定一个长度为n的序列a[1],a[2]...a[n],求一个连续的子序列a[i],a[i+1]...a[j-1],a[j]使得a[i]+a[i+1]...+a[j-1]+a[j]最大。1、根据定义来枚举:枚举上下界i,j,维护一个max值其中枚举上下界的复杂度为O(n²),求区间和复杂度为原创 2015-07-11 21:00:54 · 6195 阅读 · 0 评论 -
[常用技巧] 数据离散化入门介绍
离散化是程序设计中一个非常常用的技巧,它可以有效地降低时间复杂度。其基本思想就是在众多可能的情况中“只考虑我需要用到的值”。下面用几个例子说明,如何运用离散化改进一个低效的,甚至根本不可能实现的算法。先看UVA10173 [http://acm.uva.es/p/v101/10173.html]题目意思很简单,给定平面上n个点的坐标,求能够覆盖这些点的最小的矩形面积。由于不知道这个矩形到底有倾斜多原创 2015-07-20 10:14:27 · 6377 阅读 · 3 评论 -
2015 湘潭邀请赛 Fraction
FractionProblem Description:Everyone has silly periods, especially for RenShengGe. It's a sunny day, no one knows what happened to RenShengGe, RenShengGe says that he wants to change all decim原创 2015-06-15 14:02:54 · 1118 阅读 · 0 评论 -
[优先队列+贪心]poj3614 Sunscreen
那么将奶牛按照阳光强度的最小值从小到大排序。 将防晒霜也按照能固定的阳光强度从小到大排序从最小的防晒霜枚举,将所有符合 最小值小于等于该防晒霜的 奶牛的 最大值 放入优先队列之中。 然后优先队列是小值先出 所以就可以将这些最大值中的最小的取出来。更新答案。#include <iostream>#include<algorithm>#include<queue>#include<math原创 2015-08-07 15:51:31 · 418 阅读 · 0 评论 -
[二分] 最大化平均值
有n个物品的重量和价值分别是wi和vi,从中选出k个物品,使得单位重量的价值最大。 1≤k≤n≤10^4 1≤wi,vi≤10^6样例输入: n = 3 k = 2 w1=2 v1=2 w2=5 v2=3 w3=2 v3=1输出: 0.75(如果选1号和3号物品,平均价值是(2+1)/(2+2) = 0.75)一般最先想到的方法可能是把物品按照单位价值进行排序,从大到小贪心地进原创 2015-08-08 11:52:00 · 591 阅读 · 0 评论 -
[贪心]poj3045 Cow Acrobats
写出式子,风险值就应该等于W总-Wnow-Snow,那么就应该为W总-(Wnow+Snow),然后可以看出要值最小,那么Wnow+Snow应该最大,所以按这个进行排序,然后最大的放最下面即可#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <v原创 2015-08-08 10:57:05 · 458 阅读 · 0 评论