摘要: 基础线段树是一些基本操作之间的组合:基本操作:单点更新、单点查询、区间更新,区间求和、区间最值1、单点增减,区间求和http://acm.hdu.edu.cn/showproblem.php?pid=1166View Code #include<algorithm>#include<cstring>#include<cstdio>#define MAXN 500000using namespace std;struct SegTree{ int left,right; int anssum;}tree[MAXN<<2];void build(in 阅读全文
posted @ 2012-10-03 15:01 mtry 阅读(506) 评论(0) 推荐(0) 编辑
摘要: Fence RailsBurch, Kolstad, and SchrijversFarmer John is trying to erect a fence around part of his field. He has decided on the shape of the fence and has even already installed the posts, but he's having a problem with the rails. The local lumber store has dropped off boards of varying lengths; 阅读全文
posted @ 2012-09-27 20:58 mtry 阅读(558) 评论(0) 推荐(0) 编辑
摘要: Beef McNuggetsHubert ChenFarmer Brown's cows are up in arms, having heard that McDonalds is considering the introduction of a new product: Beef McNuggets. The cows are trying to find any possible way to put such a product in a negative light.One strategy the cows are pursuing is that of `inferio 阅读全文
posted @ 2012-09-26 14:17 mtry 阅读(922) 评论(0) 推荐(0) 编辑
摘要: Closed FencesA closed fence in the plane is a set of non-crossing, connected line segments with N corners (3 < N < 200). The corners or vertices are each distinct and are listed in counter-clockwise order in an array {xi, yi}, i in (1..N).Every pair of adjacent vertices defines a side of the f 阅读全文
posted @ 2012-09-21 09:43 mtry 阅读(675) 评论(0) 推荐(0) 编辑
摘要: American HeritageFarmer John takes the heritage of his cows very seriously. He is not, however, a truly fine bookkeeper. He keeps his cow genealogies as binary trees and, instead of writing them in graphic form, he records them in the more linear `tree in-order' and `tree pre-order' notation 阅读全文
posted @ 2012-09-19 15:46 mtry 阅读(294) 评论(0) 推荐(0) 编辑
摘要: Electric FenceDon PieleIn this problem, `lattice points' in the plane are points with integer coordinates.In order to contain his cows, Farmer John constructs a triangular electric fence by stringing a "hot" wire from the origin (0,0) to a lattice point [n,m] (0<=;n<32000, 0<m 阅读全文
posted @ 2012-09-19 13:01 mtry 阅读(359) 评论(1) 推荐(0) 编辑
摘要: Raucous RockersYou just inherited the rights to N (1 <= N <= 20) previously unreleased songs recorded by the popular group Raucous Rockers. You plan to release a set of M (1 <= M <= 20) compact disks with a selection of these songs. Each disk can hold a maximum of T (1 <= T <= 20) 阅读全文
posted @ 2012-09-18 22:35 mtry 阅读(595) 评论(0) 推荐(0) 编辑
摘要: Shopping OffersIOI'95In a certain shop, each kind of product has an integer price. For example, the price of a flower is 2 zorkmids (z) and the price of a vase is 5z. In order to attract more customers, the shop introduces some special offers.A special offer consists of one or more product items 阅读全文
posted @ 2012-09-18 21:02 mtry 阅读(645) 评论(0) 推荐(0) 编辑
摘要: Riding the FencesFarmer John owns a large number of fences that must be repaired annually. He traverses the fences by riding a horse along each and every one of them (and nowhere else) and fixing the broken parts.Farmer John is as lazy as the next farmer and hates to ride the same fence twice. Your 阅读全文
posted @ 2012-09-18 10:41 mtry 阅读(3313) 评论(0) 推荐(0) 编辑
摘要: 欧拉路径和欧拉回路欧拉路径:从某结点出发一笔画成所经过的路线叫做欧拉路径。欧拉回路:在欧拉路径的基础上又回到起点。a、凡是由偶点组成的连通图,一定可以一笔画成。画时可以把任一偶点为起点,最后一定能以这个点为终点画完此图。 b、凡是只有两个奇点的连通图(其余都为偶点),一定可以一笔画成。画时必须把一个奇点为起点,另一个奇点终点。 c、其他情况的图都不能一笔画出。(有偶数个奇点除以2便可算出此图需几笔画成。)欧拉回路和欧拉路径的判断欧拉回路:无向图:每个顶点的度数都是偶数,则存在欧拉回路。有向图:每个顶点的入度都等于出度,则存在欧拉回路。欧拉路径:无向图:当且仅当该图所有顶点的度数为偶数 或... 阅读全文
posted @ 2012-09-18 09:53 mtry 阅读(10556) 评论(0) 推荐(1) 编辑
摘要: CamelotIOI 98Centuries ago, King Arthur and the Knights of the Round Table used to meet every year on New Year's Day to celebrate their fellowship. In remembrance of these events, we consider a board game for one player, on which one chesspiece king and several knight pieces are placed on square 阅读全文
posted @ 2012-09-17 14:09 mtry 阅读(628) 评论(0) 推荐(1) 编辑
摘要: Home on the RangeFarmer John grazes his cows on a large, square field N (2 <= N <= 250) miles on a side (because, for some reason, his cows will only graze on precisely square land segments). Regrettably, the cows have ravaged some of the land (always in 1 mile square increments). FJ needs to 阅读全文
posted @ 2012-09-15 15:25 mtry 阅读(358) 评论(0) 推荐(0) 编辑
摘要: A GameIOI'96 - Day 1Consider the following two-player game played with a sequence of N positive integers (2 <= N <= 100) laid onto a game board. Player 1 starts the game. The players move alternately by selecting a number from either the left or the right end of the sequence. That number i 阅读全文
posted @ 2012-09-15 10:37 mtry 阅读(493) 评论(0) 推荐(0) 编辑
摘要: Spinning Wheels1998 ACM NE RegionalsEach of five opaque spinning wheels has one or more wedges cut out of its edges. These wedges must be aligned quickly and correctly. Each wheel also has an alignment mark (at 0 degrees) so that the wheels can all be started in a known position. Wheels rotate in th 阅读全文
posted @ 2012-09-14 15:27 mtry 阅读(380) 评论(0) 推荐(0) 编辑
摘要: StringsobitsKim SchrijversConsider an ordered set S of strings of N (1 <= N <= 31) bits. Bits, of course, are either 0 or 1.This set of strings is interesting because it is ordered and contains all possible strings of length N that have L (1 <= L <= N) or fewer bits that are `1'.Your 阅读全文
posted @ 2012-09-14 11:22 mtry 阅读(321) 评论(0) 推荐(0) 编辑
摘要: Sweet ButterGreg Galperin -- 2001Farmer John has discovered the secret to making the sweetest butter in all of Wisconsin: sugar. By placing a sugar cube out in the pastures, he knows the N (1 <= N <= 500) cows will lick it and thus will produce super-sweet butter which can be marketed at bette 阅读全文
posted @ 2012-09-13 21:49 mtry 阅读(280) 评论(0) 推荐(0) 编辑
摘要: Magic SquaresIOI'96Following the success of the magic cube, Mr. Rubik invented its planar version, called magic squares. This is a sheet composed of 8 equal-sized squares:12348765In this task we consider the version where each square has a different color. Colors are denoted by the first 8 posit 阅读全文
posted @ 2012-09-13 20:49 mtry 阅读(687) 评论(0) 推荐(0) 编辑
摘要: Feed Ratios1998 ACM Finals, Dan AdkinsFarmer John feeds his cows only the finest mixture of cow food, which has three components: Barley, Oats, and Wheat. While he knows the precise mixture of these easily mixable grains, he can not buy that mixture! He buys three other mixtures of the three grains 阅读全文
posted @ 2012-09-13 18:37 mtry 阅读(442) 评论(0) 推荐(0) 编辑
摘要: FactorialsThe factorial of an integer N, written N!, is the product of all the integers from 1 through N inclusive. The factorial quickly becomes very large: 13! is too large to store in a 32-bit integer on most computers, and 70! is too large for most floating-point variables. Your task is to find 阅读全文
posted @ 2012-09-13 14:22 mtry 阅读(335) 评论(0) 推荐(0) 编辑
摘要: Shaping RegionsN opaque rectangles (1 <= N <= 1000) of various colors are placed on a white sheet of paper whose size is A wide by B long. The rectangles are put with their sides parallel to the sheet's borders. All rectangles fall within the borders of the sheet so that different figures 阅读全文
posted @ 2012-09-13 11:26 mtry 阅读(298) 评论(0) 推荐(0) 编辑