C++ primer 笔记----语句
1、复合语句是指用花括号括起来的语句和声明的序列,也被称作块,一个块就是一个作用域,在块中引入的名字只能在块内部以及嵌套在块中的子块里访问;块不以分号作为结束。
2、悬垂else:如何确定某个else与哪个if匹配;C++规定else与离它最近的尚未匹配的if匹配,从而消除了程序的二义性。
3、break语句的作用是中断当前的控制流;case关键字和它对应的值一起被称为case标签,case标...
POJ Find them, Catch them 并查集变形
The police office in Tadu City decides to say ends to the chaos, as launch actions to root up the TWO gangs in the city, Gang Dragon and Gang Snake. However, the police first needs to identify which g...
POJ 1988 Cube Stacking
Farmer John and Betsy are playing a game with N (1 <= N <= 30,000)identical cubes labeled 1 through N. They start with N stacks, each containing a single cube. Farmer John asks Betsy to perform ...
POJ 2431 Expedition 贪心算法+优先队列
A group of cows grabbed a truck and ventured on an expedition deep into the jungle. Being rather poor drivers, the cows unfortunately managed to run over a rock and puncture the truck's fuel tank. The...
POJ 1456 Supermarket
A supermarket has a set Prod of products on sale. It earns a profit px for each product x∈Prod sold by a deadline dx that is measured as an integral number of time units starting from the moment the s...
POJ 1984 Navigation Nightmare
Farmer John's pastoral neighborhood has N farms (2 <= N <= 40,000), usually numbered/labeled 1..N. A series of M (1 <= M < 40,000) vertical and horizontal roads each of varying lengths (1 ...
HDU 4496 D-City
Luxer is a really bad guy. He destroys everything he met.
One day Luxer went to D-city. D-city has N D-points and M D-lines. Each D-line connects exactly two D-points. Luxer will destroy all the D-lin...
POJ 2494 A Bug's Life 并查集变形
Background
Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that they only interact with bugs of the opposite gende...
POJ 1182 食物链 并查集变式
动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形。A吃B, B吃C,C吃A。
现有N个动物,以1-N编号。每个动物都是A,B,C中的一种,但是我们并不知道它到底是哪一种。
有人用两种说法对这N个动物所构成的食物链关系进行描述:
第一种说法是"1 X Y",表示X和Y是同类。
第二种说法是"2 X Y",表示X吃Y。
此人对N个动物,用上述两种说法,一句接一句地说出K句话,这K句话...
HDU 2860 Regroup
When ALPC42 got to a panzer brigade, He was asked to build software to help them regroup the battalions or companies.
As the tradition of army, soldiers are rated according his or her abilities, takin...
POJ 3617 Best Cow Line 贪心
Description
FJ is about to take his N (1 ≤ N ≤ 2,000) cows to the annual"Farmer of the Year" competition. In this contest every farmer arranges his cows in a line and herds them past the judges.
The...
POJ 3069 Saruman's Army 贪心
Description
Saruman the White must lead his army along a straight path from Isengard to Helm’s Deep. To keep track of his forces, Saruman distributes seeing stones, known as palantirs, among the troo...
PKU 3253 Fence Repair 贪心
Farmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needs N (1 ≤ N ≤ 20,000) planks of wood, each having some integer length Li (1 ≤ Li ...
POJ 1733 Parity game 区间并查集
Now and then you play the following game with your friend. Your friend writes down a sequence consisting of zeroes and ones. You choose a continuous subsequence (for example the subsequence from the t...
HDU 3038 How Many Answers Are Wrong 区间并查集
TT and FF are ... friends. Uh... very very good friends -________-b
FF is a bad boy, he is always wooing TT to play the following game with him. This is a very humdrum game. To begin with, TT should w...
C++ map 常用操作的使用方式
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
using namespace std;
map<int,int>mapp;
int main()
{
//判断map是否为空
...
ZOJ 3261 Connections in Galaxy War 并查集+离线处理
In order to strengthen the defense ability, many stars in galaxy allied together and built many bidirectional tunnels to exchange messages. However, when the Galaxy War began, some tunnels were destro...
线段树的区间更新+懒惰标记
这一部分感觉是最难的一部分了。
想要更新区间的值,可以通过一个for循环进行单点更新。。但是这样貌似比普通的遍历还慢。
所以,聪明的人们想到了一个好办法解决线段树不能解决区间更新的问题。通过一个懒惰标记来对已经更新的区间进行标记,然后计算出值,然后直接返回,不在更新子节点的值了。
当进行多次更新的时候,这时候就可以通过下推标记进行更新子节点。
代码如下:
下推懒惰标记:
//下推懒...
今日推荐
周排行