Question address: http://poj.org/problem? Id = 3270
Note that some of the requirements_ Int64, The other part is ignored (think it is impossibleInt). ResultWaNowNLong unknown reason.
This is a classic question of reverse order. Beginners. There is one more State than the basic number of reverse orders. That is, you need to write one more query.
# Include
Cow sorting
Time Limit: 2000MS
Memory Limit: 65536K
Total Submissions: 6393
Accepted: 2476
DescriptionFarmer John ' s n (1≤ n ≤10,000) Cows is lined up to being milked in the evening. Each cow have a unique "grumpiness" level in the range 1...100,000. Since Grumpy cows is more likely to damage FJ ' s milking equipment, FJ would like to reorder the cows in line so they is Lined up in increasing order of grumpiness. During This proces
the two policies described above? From the greedy point of view, it cannot be better, so we only need to select a smaller one from the above two strategies. Two calculation schemes are provided:
First strategy: sum1 = (L1 + Min (L) + (L2 + Min (L) +... + (Lm-1 + Min (L) among them: sum1 is the total cost, Li is the number of beef temper in the cycle, except that a very small total of S-1, Min (L) is the temper of the smallest cattle.
Sort out and get: sum1 = sum (L) + (m-2) * Min (L)
Second str
, let 6 return to the loop again. The cost of doing so is obvious:
Sum + min + (LEN + 1) * smallest
Sum is the sum of all the numbers in the cycle, Len is the length, Min is the smallest number in the ring, and smallest is the smallest number in the entire series.
5. therefore, the cost of sorting a loop is sum-min + (LEN-1) * min and sum + min + (LEN + 1) * small number of smallest. However, we do not know how to introduce the two formulas here.
6. When calculating a loop, we do not need
POJ 3270-Cow Sorting (replacement group), poj3270-cow
Address: POJ 3270
Question: There are nheaded cows, each of which has a unique "anger value", to sort their anger values from small to large (the time spent exchanging any two cows for their anger values and), find the minimum exchange time.
Ideas:
1. Locate the initial and end states (the initial states are given by the question, and the end States are
For n given numbers, we can consider any arrangement as a replacement. So for the question poj 3270, let's look at this: first, we will give you an order of n different numbers, and then we will sort these numbers from small to small. The question requires an ascending order. Then we regard the input arrangement as a replacement.
Therefore, any replacement can be expressed by multiplying the replacement ring. Therefore, in order for the number in the
/* For each group, we have two types of hair exchange: 1. in the group for, take the smallest number t in the group and the other each number exchange, a total of K-1 times, the cost is: Sum + (K-2) * t.2. will be the smallest number of the series Minn, pulled into the group, exchange the smallest number of T with the group, then exchange the K-1 with the smallest number of others, and then replace the Minn with the T, which costs: sum + T + (k + 1) * Minn so minimum cost we take the smallest of
cost of doing so is clearly:sum + min + (len + 1) * SmallestSum of all the numbers in this loop. Len is the length,min is the smallest number in the ring, andsmallest is the smallest number in the whole sequence. 5. Thus, the price of a loop is sum-min + (len-1) * min and sum + min + (len + 1) * Smallest Small That number. But here are two formulas that do not yet know how to launch. 6. when we calculate the cycle, we do not need to record all the elements of the cycle, only the smallest numbe
[m];//to[] Record mapping relationships on permutation groups9 Ten intCircleintu) One { A intv = u, ans =0; - intCNT =0; - while(U! =To[v]) { theVIS[V] =1; -cnt++; -Ans = ans+B[v]; -v =To[v]; + } -Ans = ans+b[v], cnt++; +VIS[V] =1; A if(CNT = =1)return 0; at Else{ - /*here to determine whether to use the smallest number of cows to help the loop set the team is not the result of a smaller - the smallest cow added to help is the cow with the value b[1] and the smal
from another loop to enter the loop, making the exchange less expensive. For example, the initial state:1 8 9) 7 6Can be decomposed into two loops:(1) (8 6 9 7), obviously, the second loop is (8 6 9 7) and the smallest number is 6. We can deploy the smallest number 1 of the entire sequence into this loop. Change the second loop to: (8 1 9 7). Let this 1 complete the task, then swap with 6, and let 6 go back to the loop. The cost of doing this is obvious: Sum + min + (len + 1) * SmallestThe sum
, is the interchange of the replacement, and then the addition of the cattle in the order, the cost of small* (len-1) + (sum-min)Then interchange with min, spend Small+minTotal cost small* (len+1) +sum+minTake a minimum of two cases.As for the processing sequence, I sort it out after marking each cow where it should be, and then each permutation is done separately.
The code is as Follows:#include #include #include #include #include #include #include #include #include #include #include #
[Linux exploration journey] Part 2 Lesson 1: Terminal terminal, playing a good show, lesson 1 Terminal
Introduction
1. Part 2 Lesson 1:Terminal
2. Lesson 2: command line, the world at your fingertips
Terminal
With the end of the first part, we entered the second part (
Transfer from http://www.xuebuyuan.com/877887.htmlSeptember 07, 2013 ⁄ general ⁄ a total of 4047 characters ⁄ font size small medium big ⁄ comments off Many of the network Service applications on Linux, such as L2TP, PPTP, Telnet, all use pseudo terminal. There are friends who are asking the concept of this, and write down what I know, for discussion.First, the terminalTo understand the pseudo-terminal (P
Linux terminal, network virtual terminal, pseudo-terminal turn from: http://www.xuebuyuan.com/877887.htmlMany of the network Service applications on Linux, such as L2TP, PPTP, Telnet, all use pseudo terminal. There are friends who are asking the concept of this, and write down what I know, for discussion. First, the te
Historical origins of the terminalThe initial computer is expensive, so a computer is generally used by multiple people at the same time. In this case, a computer needs to connect many sets of keyboards and monitors for more than one person to use. In the past, there is a device that can connect to a computer, only a monitor and keyboard, and a simple processing circuit, which itself does not have the ability to process computer information, he is responsible for connecting to a normal computer
[Linux] How to enable a program on a terminal to close the terminal without exiting, linux terminalZookeeper does not exit when the terminal starts a program to close the terminal.
Generally, when the terminal is closed, the background program started in this
Read this article:
Http://stackoverflow.com/questions/21257589/ubuntu-typing-php-in-terminal-shows-a-lot-of-errors
is due to SNMP, if there is no special requirements, remove the PHP7.0-SNMP can be.
'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i
'). Text (i)); }; $numbering. FadeIn (1700); }); });
The above describes Ubuntu typing PHP in
Original URL: http://blog.csdn.net/liaoxinmeng/article/details/5004743First of all:1. Neither the terminal nor the console is the concept of personal computers, but the concept of a small, medium-sized mainframe computer shared by many people.A host, even a lot of terminals, the terminal for the host to provide a human-computer interface, everyone through the terminal
Linux terminal type, linux terminal
Unix is a multi-user and multi-task operating system. Early computers were expensive, so cheap devices were used to connect to the computer (no keyboard or display was available at the time, paper tapes and cards were used for input and output) to use the operating system, this cheap device is a terminal, which can also be cons
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.