POJ 1988 Cube Stacking, pojstacking
Source: http://poj.org/problem? Id = 1988
Cube Stacking
Time Limit:2000 MS |
|
Memory Limit:30000 K |
Total Submissions:19173 |
|
Accepted:6693 |
Case Time Limit:1000 MS |
Description
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 P (1 <= P <= 100,000) operation. there are two types of operations:
Moves and counts.
* In a move operation, Farmer John asks Bessie to move the stack containing cube X on top of the stack containing cube Y.
* In a count operation, Farmer John asks Bessie to count the number of cubes on the stack with cube X that are under the cube X and report that value.
Write a program that can verify the results of the game.
Input
* Line 1: A single integer, P
* Lines 2 .. P + 1: Each of these lines describes a legal operation. line 2 describes the first operation, etc. each line begins with a 'M' for a move operation or a 'C' for a count operation. for move operations, the line also contains two integers: X and Y. for count operations, the line also contains a single integer: X.
Note that the value for N does not appear in the input file. No move operation will request a move a stack onto itself.
Output
Print the output from each of the count operations in the same order as the input file.
Sample Input
6M 1 6C 1M 2 4M 2 6C 3C 4
Sample Output
102
Source
USACO 2004 u s Open
Question: vector and query set ~~~ The legend of Vijos 1443 galaxy hero is similar to that of Vijos ~~ This is really cool. Once it is done, there will be no changes to the AC.
AC code:
#include<cstdio>const int Max=30001;int father[Max],loc[Max],root[Max],t,x,y;char ch;int find(int k){if(k==father[k]) return k;int temp=find(father[k]);loc[k]+=loc[father[k]];father[k]=temp;return temp;}int main(){scanf("%d",&t);for(int i=1;i<Max;i++){father[i]=i;loc[i]=0;root[i]=1;}while(t--){getchar();scanf("%c",&ch);if(ch=='M'){scanf("%d%d",&x,&y);int tempx=find(x),tempy=find(y);father[tempy]=tempx; loc[tempy]=root[tempx];root[tempx]+=root[tempy];}else {scanf("%d",&x);int tempx=find(x);printf("%d\n",root[tempx]-loc[x]-1);}}return 0;}
Pku 1988 Cube Stacking help
Isn't this a false positive?
What are the uses and query sets of Peking University acm questions?
POJ 1611 The Suspects most basic query set
POJ 2524 basic Ubiquitous Religions query set
POJ 1182 extension of food chain and query set
Note: There is only one group of data;
Make full use of the conditions given by the question: there are three types of animals A, B, C, and the food chains of these three types of animals.
It constitutes an interesting ring. A eats B, B eats C, and C eats. That is to say, there are only three groups.
POJ 2492 A Bug's Life and expansion of query Sets
Method 1: depth-first Traversal
Each traversal record indicates whether the path is male or female. Only male-> female, female-> male meets the requirement. Otherwise, locate the homosexuality and end the program.
Method 2: Bipartite Graph Matching
Method 3: Expand the query set: it is very similar to 1182, but there are two groups, and 1182 is three groups, 1611 is not limited.
POJ 1861 Network = zju_1542 and query set + custom sorting + greedy search "minimal spanning tree"
The answer is not unique, but QSORT () and SORT () can be used on ZOJ, and only SORT () can be used on POJ...
POJ 1703 Find them, Catch them and query the expansion of the Set
This is very similar to POJ 2492 A Bug's Life, that is, the code will be AC after A slight modification!
Note: And of course, at least one of them belongs to Gang Dragon, and the same for Gang Snake. There are only two groups.
POJ 2236 Wireless Network and query set Application
Note: 1. Check the Set; 2. The range of N can be 1001; 3. From the N + 1 line, the first input can be a string.
POJ 1988 Cube Stacking and good query set Application
1. Like Galaxy hero legend = NOI2002 Galaxy; 2. An array behind [x] is added to record the relative position of warship x in the column; 3. For detailed problem report, see Galaxy hero legend.
JOJ 1905 Freckles = POJ 2560 Minimum Spanning Tree
Method 1: Prim algorithm; Method 2: Query sets to implement the Kruskar Algorithm for the Minimum Spanning Tree