挑战程序设计竞赛(第二版)
文章平均质量分 73
例题,解析
普通网友
这个作者很懒,什么都没留下…
展开
-
AOJ 1313 Intersection of Two Prisms (数值积分)
Intersection of Two PrismsSuppose that P1 is an infinite-height prism whose axis is parallel to the z-axis, and P2 is also an infinite-height prism whose axis is parallel to the y-axis. P1 is原创 2016-05-23 22:06:55 · 1825 阅读 · 0 评论 -
POJ 2187 Beauty Contest (旋转卡壳法)
Beauty ContestTime Limit: 3000MS Memory Limit: 65536KTotal Submissions: 33457 Accepted: 10367DescriptionBessie, Farmer John's prize cow, has just won first place原创 2016-05-23 21:42:52 · 1905 阅读 · 0 评论 -
POJ 2932 Coneology (平面扫描)
ConeologyTime Limit: 5000MS Memory Limit: 65536KTotal Submissions: 3713 Accepted: 720DescriptionA student named Round Square loved to play with cones. He would ar原创 2016-05-15 14:08:59 · 1992 阅读 · 0 评论 -
AOJ 2308 White Bird (极限情况)
White BirdTime Limit : 5 sec, Memory Limit : 65536 KBWhite BirdAngry Birds is a mobile game of a big craze all over the world. You were convinced that it was a waste of time to play原创 2016-05-15 13:38:51 · 2314 阅读 · 2 评论 -
POJ 1127 Jack Straws (计算几何)
Jack StrawsTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 3945 Accepted: 1787DescriptionIn the game of Jack Straws, a number of plastic or wooden "stra原创 2016-05-15 13:09:30 · 2299 阅读 · 0 评论 -
POJ 1769 Minimizing maximizer
Minimizing maximizerTime Limit: 5000MS Memory Limit: 30000KTotal Submissions: 3773 Accepted: 1501DescriptionThe company Chris Ltd. is preparing a new sorting hard原创 2016-05-11 13:11:05 · 804 阅读 · 0 评论 -
POJ 3233 Matrix Power Series (矩阵的幂)
Matrix Power SeriesTime Limit: 3000MS Memory Limit: 131072KTotal Submissions: 19480 Accepted: 8214DescriptionGiven a n × n matrix A and a positive integer k, fi原创 2016-05-11 11:24:56 · 485 阅读 · 0 评论 -
POJ 3734 Blocks (矩阵的幂)
BlocksTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 5335 Accepted: 2494DescriptionPanda has received an assignment of painting a line of blocks. Since原创 2016-05-09 19:27:07 · 876 阅读 · 0 评论 -
矩阵的幂 斐波那契数列
题意:斐波那契数列是由如下递推式定义的数列F0 = 0F1 = 1Fn+2 = Fn+1 + Fn求这个数列第n项的值对10000取余后的结果输入:n = 10输出:55#include #include using namespace std;//用二维vector来表示矩阵typedef vector vec;typedef vector ma原创 2016-05-06 11:51:43 · 759 阅读 · 0 评论 -
铺砖问题 (状态压缩DP)
题意:给定n*m的格子,每个格子被染成了黑色或者白色。现在要用1 * 2 的砖块覆盖这些格子,要求块与块之间互相不重叠,且覆盖了所有白色的格子,但不覆盖任意一个黑色格子。求一个有多少种覆盖方法,输出方案数对M取余后的结果。输入:n= 3m= 4每个格子的颜色如下所示(.表示白色,x表示黑色)….x.…输出:2分析:由于黑色的格子不能被覆盖原创 2016-05-06 11:12:55 · 4280 阅读 · 0 评论 -
POJ 2686 Traveling by Stagecoach (状态压缩DP)
Traveling by StagecoachTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 2776 Accepted: 996 Special JudgeDescriptionOnce upon a time, there was a trav原创 2016-05-05 14:45:26 · 2142 阅读 · 0 评论 -
旅行商问题 (状态压缩DP)
旅行商问题给定一个n个顶点组成的带权有向图的距离矩阵d(I, j)(INF表示没有边)。要求从顶点0出发,经过每个顶点恰好一次后再回到顶点0。问所经过的边的总权重的最小值是多少?分析:dp[S][v]表示从v出发访问剩余的所有顶点,最终回到顶点0的路径的权值总和的最小值int dp[1 void solve(){ //用足够大的值初始化数组 for (int原创 2016-05-05 14:30:43 · 2331 阅读 · 1 评论 -
POJ 2104 K-th Number (线段树)
K-th NumberTime Limit: 20000MS Memory Limit: 65536KTotal Submissions: 46589 Accepted: 15553Case Time Limit: 2000MSDescriptionYou are working for Macrohard c原创 2016-05-03 10:19:34 · 3553 阅读 · 0 评论 -
分桶法和平方分割
分桶法(bucketmethod)是把一排物品或者平面分成桶,每个桶分别维护自己内部的信息,以达到高效计算的目的的方法。其中,平方分割(sqrtdecomposition)是把排成一排的n个元素每根号n个分在一个桶内进行维护的方法的统称。这样的分割方法可以使对区间的操作的复杂度降至O(根号n)。和线段树一样,根据维护的数据不同,平方分割可以支持很多不同的操作。接下来,和线段树一样,原创 2016-04-28 15:07:47 · 4869 阅读 · 0 评论 -
POJ 3468 A Simple Problem with Integers (树状数组)
A Simple Problem with IntegersTime Limit: 5000MS Memory Limit: 131072KTotal Submissions: 88353 Accepted: 27469Case Time Limit: 2000MSDescriptionYou have N i原创 2016-04-25 20:45:00 · 658 阅读 · 0 评论 -
冒泡排序的交换次数
题意:给定一个1~n的排列a0,a1,…an-1,求对这个数列进行冒泡排序所需要的交换次数(冒泡排序是每次找到满足ai>ai+1的i,并交换ai和ai+1,直到这样的i不存在为止的算法)。限制条件:1 输入:n=4, a={3,1,4,2}输出:3 冒泡排序的复杂度是O(n2),所有无法通过模拟冒泡排序的过程来计算需要的交换次数。不过我们可以通过选取适当的数据结原创 2016-04-25 19:05:13 · 23424 阅读 · 8 评论 -
Binary Indexed Tree (树状数组)
树状数组是能够完成下述操作的数据结构给一个初始值全为0的数列a1,a2,…an。*给定i,计算a1+a2+…+ai*给定i和x,执行ai += x1.基于线段树的实现如果使用线段树,只需要对RMQ的样例做少许修改就可以实现这两个功能。线段树的每个节点上维护的是对应的区间的和。接下来,我们来看如何计算从s到t的和。在基于线段树的实现中,这个和是可以直接求得的。原创 2016-04-25 18:51:48 · 1329 阅读 · 0 评论 -
POJ 2991 Crane 线段树
CraneTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 5091 Accepted: 1368 Special JudgeDescriptionACM has bought a new crane (crane -- jeřáb) . The c原创 2016-04-22 18:35:28 · 1843 阅读 · 0 评论 -
线段树
线段树1.线段树的概念线段树是擅长处理区间的。线段树是一个完美的二叉树(所有的叶子的深度都相同,并且每个节点要么是叶子要么有2个儿子的树),树上的每个节点都维护一个区间。根维护的是整个区间,每个节点维护的是父亲的区间二等分后的其中一个子区间。当有n个元素时,对区间的操作可以在O(logn)的时间内完成。根据节点中维护的数据的不同,线段树可以提供不同的功能。2.基于线段树的RMQ的结原创 2016-04-22 13:20:11 · 551 阅读 · 1 评论 -
区域的个数 (坐标离散化)
区域的个数题意:w * h的格子上画了n条或垂直或水平的宽度为1的直线。求出这些线段将格子划分成了多少个区域。输入:w = 10, h = 10, n = 5x1 = {1, 1, 4, 9, 10}x2 = {6, 10, 4, 9, 10}y1 = {4, 8, 1, 1, 6}y2 = {4, 8, 10, 5, 10}(对应于前面的例图)原创 2016-04-22 12:51:03 · 1108 阅读 · 0 评论 -
超大背包问题 (折半枚举)
题意:有重量和价值分别为wi,vi的n个物品。从这些物品中挑选总重量不超过W的物品,求所有挑选方案中价值总和的最大值。限制条件:1 1 1 输入:n = 4w = {2, 1, 3, 2}v = {3, 2, 4, 2}W = 5输出:7(挑选0、1、3号物品)分析:这个问题是前面介绍过的背包问题,不过这次价值和重量都可以是非常大的数值,原创 2016-04-19 15:50:56 · 3139 阅读 · 2 评论 -
POJ 2785 4 Values whose Sum is 0 折半枚举(双向搜索)
4 Values whose Sum is 0Time Limit: 15000MS Memory Limit: 228000KTotal Submissions: 19158 Accepted: 5714Case Time Limit: 5000MSDescriptionThe SUM problem can原创 2016-04-18 22:06:06 · 1535 阅读 · 0 评论 -
POJ 3684 Physics Experiment 弹性碰撞
Physics ExperimentTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 1709 Accepted: 582 Special JudgeDescriptionSimon is doing a physics experiment wit原创 2016-04-15 22:03:25 · 1945 阅读 · 0 评论 -
POJ 3279 Fliptile 开关问题
FliptileTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 6541 Accepted: 2487DescriptionFarmer John knows that an intellectually satisfied cow is a happy原创 2016-04-15 22:02:05 · 1567 阅读 · 0 评论 -
POJ 3276 Face The Right Way 反转(开关问题)
Face The Right WayTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 3797 Accepted: 1750DescriptionFarmer John has arranged his N (1 ≤ N ≤ 5,000) cows in a原创 2016-04-14 19:24:54 · 923 阅读 · 0 评论 -
POJ 3320 Jessica's Reading Problem
Jessica's Reading ProblemTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 9654 Accepted: 3163DescriptionJessica's a very lovely girl wooed by lots of boy原创 2016-04-11 18:39:03 · 981 阅读 · 0 评论 -
尺取法 POJ 3061 Subsequence
SubsequenceTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 11168 Accepted: 4636DescriptionA sequence of N positive integers (10 < N < 100 000), each of原创 2016-04-11 14:29:02 · 588 阅读 · 0 评论 -
最大化平均值
题意:有n个物品的重量和价值分别是wi和vi。从中选出k个物品使得单位重量的价值最大输入:3 22 25 32 1输出:0.75 分析:一般最先想到的方法可能是把物品按照单位价值进行排序,从小到大贪心的进行选取,但是这个方法对于样例输入得到的结果是5/7=0.714.所以这个方法是不可行的。实际上,对于这个问题使用二分搜索法可以很好的解决。原创 2016-04-10 18:25:29 · 1382 阅读 · 0 评论 -
POJ 2456 Aggressive cows (贪心 + 二分)
Aggressive cowsTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 9797 Accepted: 4865DescriptionFarmer John has built a new long barn, with N (2 His C原创 2016-04-10 18:17:19 · 1632 阅读 · 0 评论 -
POJ 1064 Cable master
Cable masterTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 34728 Accepted: 7391DescriptionInhabitants of the Wonderland have decided to hold a regional原创 2016-04-10 18:03:23 · 907 阅读 · 0 评论 -
从有序数组中查找某个值 low_bound
二分搜索题意:给定长度为n的单调不下降数列a0, ...an-1和一个数k,求满足ai>=k条件的最小的i。不存在的情况下输出n。输入:5 32 3 3 5 6输出:1#include using namespace std;int n, k;int a[1000000 + 10];void solve(){ //初始化解的存在范原创 2016-04-10 17:30:46 · 1416 阅读 · 0 评论 -
2008 APAC local onsites Problem C. Millionaire
Problem C. MillionaireThis contest is open for practice. You can try every problem as many times as you like, though we won't keep track of which problems you solve. Read the Quick-Start Gui原创 2016-04-09 18:27:31 · 1822 阅读 · 2 评论 -
GCJ 2009 Round 1C Bribe the Prisoners
Bribe the Prisonersno tags ProblemIn a kingdom there are prison cells (numbered 1 to P) built to form a straight line segment. Cells number i and i+1 are adjacen原创 2016-04-09 18:13:18 · 1668 阅读 · 0 评论 -
GCJ 2009 Round2 Problem A. Crazy Rows
Problem A. Crazy RowsThis contest is open for practice. You can try every problem as many times as you like, though we won't keep track of which problems you solve. Read the Quick-Start Guide to get原创 2016-04-09 17:54:16 · 1171 阅读 · 0 评论 -
GCJ 2008 Round1A Problem A. Minimum Scalar Product
Problem A. Minimum Scalar ProductThis contest is open for practice. You can try every problem as many times as you like, though we won't keep track of which problems you solve. Read the Quick-Start原创 2016-04-09 17:50:57 · 1107 阅读 · 0 评论 -
UVa 10006 Carmichael Numbers (快速幂运算)
快速幂运算---反复平方法/** [题意]* 输入n,若满足如下两个条件,则n是Carmichael number* 1、n不是素数* 2、对于所有a(2** [解题方法]* 快速幂取模,注意运算过程中的乘法溢出int*/#include using namespace std;typedef long原创 2016-04-08 19:37:14 · 1315 阅读 · 0 评论 -
区间筛法
例:区间内素数的个数题意:给定整数a和b,请问区间[a,b)以内有多少个素数? (a 输入:22 3722801763489 22801787897输出:31000typedef long long ll;const int MAX_L = 1000000000000 + 10;const int MAX_SQRT_B = 10000原创 2016-04-08 19:32:41 · 2485 阅读 · 0 评论 -
埃式筛法
例:素数的个数题意:给定整数n,请问n以内有多少个素数 (n 输入:111000000输出:578498#include using namespace std;const int maxn = 1000000 + 10;int prime[maxn]; //第i个素数bool is_prime[maxn]; //is_prime[i]为t原创 2016-04-08 19:24:25 · 4008 阅读 · 0 评论 -
素性测试
例:素数判定题意:给定整数n,请判定n是不是素数。//假设输入的都是正数//素性测试,复杂度为根号nbool is_prime(int n){ for (int i = 2; i * i <= n; i++){ if (n % i == 0){ return false; } return n != 1;原创 2016-04-08 19:13:57 · 1302 阅读 · 0 评论 -
辗转相除法
1.求最大公约数例:线段上格点的个数题意:给定平面上的两个格点P1 = (x1,y1)和P2 = (x2, y2),线段P1P2上,除P1和P2以外一共有几个格点?输入:1 115 3输出:3#include #include #include using namespace std;int gcd(int a, int b){ if (b原创 2016-04-08 19:09:33 · 1361 阅读 · 0 评论