I'm bored with it ..
In fact, the key to this question is not the method of reverse order, because it is also possible to use brute force.
To give a sequence with the length of n (n
I use array a [0 ~ N-1] to store raw data. You only need to find the sum of the reverse order of the original sequence, and then for each order of a [I] (0
1. Violence Law.
265 Ms
212 K
600 B
Problem: 1394 (minimum inversion number) Judge Status: A
For computers that can access the Internet:1. There must be a 1394 data cable2. Select the 1394 connection at the same time, and right-click the local connection and bridge (objective: to associate the local connection that can connect to the Internet with the 1394 connection ))3. Right-click Network Bridge and select Properties (SET network environment)The netwo
Test instructionsGive you n number, n number is a whole arrangement of 0~n-1.The minimum value required to count all of its forms in reverse order. All of its forms mean that the first number at the beginning of the array is constantly placed in the last face of the array.Inverse pairs: iIdeas:A tree array is also available,Look at the codeCode:Const intMAXN =50005;intsum[maxn2];intN;voidPushup (intRT) {Sum[rt]= sum[rt1] + sum[rt1|1];}voidBuildintLintRintRT) {Sum[rt]=0; if(L==R)return; intm = (L
(4) = 1 to get the reverse number of 4 for 1.5. Enter 3, call Update (3, 1), set 3rd bit to 11 2 3) 4 51 1 1) 1 1Do you calculate a number that is smaller than 3 on 1-3? Here is a tree-like array of getsum (3) = 3 operations,Now use the input subscript 5-getsum (3) = 2 to get the reverse number of 3 for 2.6.0+1+2+1+2 = 6 This is the final reverse number.Analyze the time complexity, first use the fast sort, the time complexity is O (NLOGN),CODE:Segment Tree:#include Tree-like array:#include Hdu
, each element is less than n and not duplicated, each operation puts the first element at the end, and the smallest number of reverse order in n operations.Idea: First to find the original array of reverse order number, each time the first place at the end, NUM (reverse order number) plus greater than a[i], and then subtract less than a[i]. Code:1#include 2#include 3#include 4#include 5#include 6#include 7#include 8#include Set>9 using namespacestd;Ten One #defineN 5005 A #definell Root - #def
Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1394
Idea: first calculate the number of reverse orders, then there is a technique (true pitfall) ...... can be done using a line segment tree or a tree array. The shift technique is that the reverse order number is reduced ant [I], while the n-1-ant [I] is increased.
#include
There is an error... Wrong took us an hour .. That is, when the line segment tree is built, it must be open to
Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1394
Give N, and then give a group of 0 ~ N-1, calculate the number of reverse orders of this sequence, and the minimum value of the number of reverse orders after the exchange. The exchange rules are as follows:
A1, A2,..., An-1, an (where m = 0-the initial seqence)A2, A3,..., An, A1 (where M = 1)A3, A4,..., An, A1, A2 (where m = 2)...An, A1, A2,..., An-1 (where M = N-1)
For example, if w
Link: HDU 1394 minimum inversion number
This is an extension of the smallest reverse order. You can use a tree array. For a sequence of $ N $ numbers $ A $, the number of $ I $ ($ I \ in [0, n) $) the number of reverse orders $ r_ I $ can be expressed as its badge $ I $ minus the number before it and not greater than its number. For example, a [8] = 4 for the number in sequence a =. The number of reverse orders $ r_8 = 8-3 = 5 $, and the second 3 indi
HDU 1394 Minimum Inversion Number (reverse Number of Line Segment trees)
Address: HDU 1394
You can use the line segment tree to calculate the number of reverse orders.
The maintenance information of this question indicates whether each number has been displayed. After each input, the query is performed from the value of the point to n-1. Each time a number is found, because it is found after the number, thi
After the main board is changed for the Ubuntu host, the integrated network port of the main board cannot access the Internet. After the network port of the Ubuntu host is changed, the integrated network port of the main board cannot access the Internet. Error in Network Information Query: ifconfig eth0 eth0: Interface Information Retrieval error: Device not foundifconfig eth1eth1: Interface Information Retrieval error: Device not found open/etc/udev/rules. d/70-persistent-net.rules you can find
How to Set BIOS for Asus motherboard ?, Asus motherboard bios
There will be a first startup Item during system reinstallation. If you are using a USB flash drive to reinstall the system, set USB as the first boot item. If you are using another boot item, choose other items. The key point here is how to set this first boot item, that is, how to set the computer BIOS /?
First, insert the prepared usb flash
HDU-1394-Minimum Inversion Number
Http://acm.hdu.edu.cn/showproblem.php? Pid = 1, 1394
The meaning is to give n numbers, calculate their reverse order number, and move the first number to the end each time, then calculate its reverse order number, and find the smallest reverse order number in the n orders
A simple definition of The number of reverse orders: The inversion number of a givennumber sequence a1,
Test instructions: Give the number of n, each time you can move the first number to the last position, ask the nth permutation of the smallest inverse logarithmFirst, we'll find out the logarithm of the first reverse order.Then for a number a[i], a number smaller than it has a[i]-1, a number larger than it has n-a[i]So the a[i] moved to the end of the sequence, the equivalent of the loss of a[i]-1 reverse order number, got n-a[i] the reverse numberFor a total of n-2*a[i] + oneDo another n compar
=1394Title: To a group of numbers, each time you can get the beginning of the number to the end, ask such a sequence of the number of reverse order of the smallest inverse valueTitle Analysis: First Use the tree-like array to reverse the number, the reverse value after each Exchange can be directly calculated, because it is a 0~n-1 arrangement, so the first number (set to FIR) to the last to reduce the number of FIR in reverse order, and this group is sure to have n-fir-1 number is greater than
Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1394Test instructions: give you a 0-n-1 arrangement, for this arrangement you can put the first element to the last, and ask the number of reverse pairs you might getThe number of reverse pairs of the original sequence is calculated, then the first element is n-1 to the last operation, and the number of reverse pairs of the new sequence can be obtained with O (1) complexity after each operation.The key point of this problem is to find out the
Question address: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1394
Tree array. I first thought about it, but I didn't think of it:When the number of team heads is placed at the end of the team, the number of reverse orders in the queue may change...
When deducting the number of reverse orders, we forget to subtract the number of new reverse orders!
# Include
Link:
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1394
Question:
For a sequence of N numbers A1, A2,..., An, the range of these numbers is 0 ~ N-1, you can move the number of m above to the back to form a new sequence:
A1, A2,..., An-1, an (where m = 0-the initial seqence)A2, A3,..., An, A1 (where M = 1)A3, A4,..., An, A1, A2 (where m = 2)...An, A1, A2,..., An-1 (where M = N-1)What is the minimum number of reverse sequences?
Analysis and Summary
Question Link: Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1394
Analysis:First, this is the problem of solving the reverse order number. First, we need to know what the reverse order number is?
In an arrangement, if the front and back positions of a pair of numbers are in the opposite order of size, that is, the front number is greater than the back number, they are called a reverse order. The total number of reverse orders in an arrangement is
Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1394
Solution Report: Give a sequence, find the reverse Number of the sequence, and then move the first number to the last one in sequence. What is the reverse Number of the sequence with the smallest backward number in this process?
One advantage of this problem is that the input sequence must be 0 to n-1, so discretization is not allowed, another benefit is that we can calculate the tota
constant to meet in the 1~m in the number of add in, so the optimal solution is constantly updated. */#include#include#defineM 200010#defineINF 0x3f3f3f3fusing namespacestd;intA[m],sum[m];intMain () {intn,m; scanf ("%d%d",n,m); for(intI=1; i) scanf ("%d",A[i]); intL=1, cnt=0, ans=INF; for(intR=1; r) { if(a[r]1|| A[R]GT;M)Continue; if(!sum[a[r]]) cnt++; SUM[A[R]]++; if(cnt==m) { for(inti=l;i) { if(sum[a[i]]>1) {Sum[a[i]]--; L++; } Else Break;
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.