Address: http://acm.uestc.edu.cn/#/problem/show/1338
Ideas:
learned and Heroes CollegeTime limit:6000/2000ms (java/others) Memory limit:225535/225535kb (java/others)SubmitStatus
Most humans, in this era, have the power to be called "personalities," but those who have power do not necessarily belong to the righteous. Wherever evil arises, there must be a hero who will come forward to save the crowd. A young man born without power------learned dreamed of a top hero since childhood, and his dream is to become a great hero, but he can realize his dream without power? Despite the difficulties, the teenager still does not give up, toward his own goal to go forward bravely!
......
Although learned has no personality, learned is indeed a "hero" with a super-strong will.
The so-called heroes are able to stand up when everyone is indifferent!
Today, learned appeared!
Learned faces a matrix of n∗mn∗m, each of which has a monster in each position.
Learned in order to better defeat them, his first task is to analyze the combat effectiveness of monsters.
In order to simplify the calculation of your analysis time, learned need to get another n∗mn∗m matrix.
This matrix satisfies the following requirements:
1. In each row of this new matrix, the size relationship in each column is the same as the original matrix.
2. The minimum value of this new matrix should be as small as possible, so that the smallest value is minimized, so that the second small value is as small as possible ... So that the maximum value is as small as possible.
Now learned is very busy, please help learned output this matrix!
Input
The first line of N,m represents the size of the matrix
Next n lines, m integers per line, represents the combat effectiveness of monsters
Guarantee:
1<=n∗m<=1000000 1<=n∗m<=1000000
The monster's combat effectiveness is the number within the INT range.
Output
To output a new matrix ~
The smallest number in the new matrix is at least 1 oh.
Sample Input and output
Sample Input |
Sample Output |
3 31 2 34 5 67 8 9 |
1 2 32 3 43 4 5 |
2 21 43 2 |
1 22 1 |
Ideas:
The most basic idea is to order all the numbers, and then fill in one, but because the same number of peers in the same column is troublesome.
So every time you drag all the same number of peers in the same column into the same set, and check the set to maintain the same number of values should be put
Just such a layer of consolidation, until filled out.
But the output of the time to use and check the set of the answer recorded in the output ... (saying the question has been thinking about me for 10,000 years,,,,
1#include <iostream>2#include <algorithm>3#include <cstdio>4#include <cmath>5#include <cstring>6#include <queue>7#include <stack>8#include <map>9#include <vector>Ten#include <cstdlib> One#include <string> A - #definePI ACOs ((double)-1) - #defineE exp (double (1)) the Const intmax=1e6+Ten; - using namespacestd; - structnode - { + intv,x,y; - }a[max]; + intAns[max],xmax[max],ymax[max],hx[max],hy[max]; A intRoot[max]; at intFdintx) - { - returnx!=root[x]?root[x]=FD (Root[x]): x; - } - voidJoinintXinty) - { in intA=FD (x), b=fd (y); - if(a!=b) root[a]=b; to } + BOOLcmpstructNode C,structNode B) - { the returnc.v<B.V; * } $ intMain (void)Panax Notoginseng { - intn,m; theCin>>n>>m; + for(intI=1; i<=n;i++) A for(intj=1; j<=m;j++) the { +scanf"%d", &a[(i-1) *m+j].v); -a[(I-1) *m+j].x=i;a[(I-1) *m+j].y=J; $ } $Sort (A +1, a+n*m+1, CMP); -memset (Xmax,0,sizeof(Xmax)); -memset (Ymax,0,sizeof(Ymax));//all set to 0, thememset (ans,0,sizeof(ans)); - intSame=1;//record the same elementsWuyi for(intI=1; i<=n*m;i++) theroot[i]=i; - for(intI=1; i<=n*m;i++) Wu { - if(I!=n*m && a[i].v==a[i+1].v) About Continue; $ for(intj=same;j<=i;j++) - { -Hx[a[j].x]=hy[a[j].y]= (a[j].x-1) *m+a[j].y; - } A for(intj=same;j<=i;j++) + { theJoin (hx[a[j].x], (a[j].x-1) *m+a[j].y); -Join (Hy[a[j].y], (a[j].x-1) *m+a[j].y); $ } the for(intj=same;j<=i;j++) the { the intx = a[j].x,y=a[j].y; the intRT = FD ((a[j].x-1) *m+a[j].y); -Ans[rt]=max (Ans[rt],max (xmax[x],ymax[y]) +1); in } the for(intj=same;j<=i;j++) the { About intx = a[j].x,y=a[j].y; theXmax[x]=max (XMAX[X],ANS[FD (a[j].x-1) *m+a[j].y)]); theYmax[y]=max (YMAX[Y],ANS[FD (a[j].x-1) *m+a[j].y)]); the } +same=i+1; - } the for(intI=1; i<=n*m;i++)Bayi { the if(i%m==0) theprintf"%d \ n", ANS[FD (i)]); - Else -printf"%d", ANS[FD (i)]); the } the return 0; the}
View Code
Hdu1338 learned and Heroes College