The problem is the simple application of the minimal spanning tree. At first, did not think of using the smallest spanning tree to do, think of is greedy, when known to use the smallest spanning tree to do, but also made a very serious mistake, is the time complexity of the estimate wrong, leading to the beginning dare not write, thinking of other methods. Think of it as a lesson.The following is the code of the AC, with detailed comments, with a check set to judge the ring, the time complexity
program should print exactly one blank line.Sample Input3 5 the - 63923 99999Sample Output 3 5 Good Choice 20 63923 99999 Good ChoiceConsider a large number; Pay attention to the format;1#include 2 #defineMAX 100010;3 4 intgcdintAintb//greatest common divisor;5 {6 if(!B)returnA;7 Else8 returnGCD (b,a%b);9 }Ten One intMain () A { - intM,n; - while(~SCANF ("%d%d",m,N)) the { - intlen=gcd (m,n); - if(len==1) -printf"%10d%10d G
This problem, simple BFS can be done. The approximate meaning of the topic is the shortest time from the r of the map to reach a.In the beginning, with the normal queue to do, the result of memory is super, the reason is N and M maximum 200; a normal queue wastes a lot of memory, so you should use a priority queue instead.The following is the code for AC:#include Hangzhou Electric acm1242--rescue~~bfs+ Priority queue
U Calculate ETime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)Total submission (s): 35178 Accepted Submission (s): 15843Problem Descriptiona Simple Mathematical formula-E iswhere n is allowed to go to infinity. This can actually yield very accurate approximations of e using relatively small values of N.Outputoutput The approximations of e generated by the above formula for the values of nFrom 0 to 9. The beginning of your output should appear similar to that shown be
just because of one detail wrong wa one afternoon. now talk about this problem, generally we bfs when the depth and adjacency table related, this because the focus is the direction, we can think of the turn 0 bends is a layer, 1 bends is the second floor .... In accordance with this rule, BFs arrives at eachthe number of turns in the junction is the fewest number of times, I was wrong in the beginning of the program logic is not a search in the end. Instead of encountering a node that has been
Lowest Common Multiple PlusTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)Total submission (s): 39183 Accepted Submission (s): 16144Problem description to find the number of n least common multiple.Input inputs contain multiple test instances, and each test instance starts with a positive integer n, followed by n positive integers.Output outputs their least common multiple for each set of test data, with one row for each test instance output. You can assume that t
Number of Split planes = number of intersections + vertex number +1Make f (n-1) The number of planes divided by the first n-1 polyline, when the nth polyline is added.Because each edge intersects with the two edges of the front n-1 polyline, the number of intersections is increased by 2*2* (n-1) and the vertex is increased by 1, soF (n) =f (n-1) +4 (n-1) +1F (n-1) =f (n-2) +4 (n-2) +1....F (2) =f (1) +4*1+1F (1) =2F (N) -2=4 ((n-1) + (n-2) +...+1) + (n-1) =4* ((1+n-1) * (n-1)/2) +n-1=2 (n*n-n) +
low energy particle quantity. Each output occupies one row.Sample Input5 2 -1Sample Output571 209 One 4 long int against GNU C + +, using __int64 against VC6SOURCE2006/1/15 ACM Program Design Final Exam//careful;1#include 2__int64 biao[ *],sieve[ *];3 intMain ()4 {5 intI,j,n;6biao[1]=3; sieve[1]=1;7 for(i=2;i the; i++)8 {9biao[i]=biao[i-1]*3+sieve[i-1]*2;Tensieve[i]=biao[i-1]+sieve[i-1]; One } A while(~SCANF ("%d", n) n!=-1) - { - if(n==0) theprintf"1, 0\n");
Peach in mindTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)Total submission (s): 41117 Accepted Submission (s): 30915Problem DescriptionLike the journey of the students must know that Wu empty eat peach story, you must all think this monkey too noisy, in fact you are some do not know: Goku is a mathematical problem in the study!What's the problem? The question he studied was how many peaches there were!However, in the end, he still failed to solve the problem, heh
Problem Descriptionhoho, finally from Speakless hand to win all the candy, is Gardon eat candy when there is a special hobby, is not like the same candy put together to eat, like to eat first, the next time to eat another, so But Gardon don't know if there is a candy-eating order so he can finish all the candies? Please write a program to help calculate the first line of input has an integer t, followed by the T Group of data, each group of data accounted for 2 rows, the first row is an integer
Electric Research Class-7 Chinese Chess Game Summary
Intelligence: Chinese chess!
In order to enrich the students' after-school life, promote friendship among the students, cultivate their personal interests, and improve their overall quality, we also advocate a good spirit of playing chess and morality and spread a high spirit of competition, carry forward the excellent traditional culture of the Chinese nation and appreciate the profound elegance
(1) Through the digital map clearly show the site visitor analysis of the most noteworthy indicators, such as the number of visitors, order rate, payment rate ...(2) The number of visitors per day, the composition of visitors, the number of people consulted, the number of people to be paid and the average transaction amount are displayed visually through the histogram by time-day dimension;(3) using the world map, the city as the dimension of the main distribution of visitors, you can see at a g
http://acm.hdu.edu.cn/showproblem.php?pid=2680Problem Descriptionone Day, Kiki wants to visit one of her friends. As she is liable to carsickness, she wants to arrive at her friend's home as soon as possible. Now give your a map of the city ' s traffic route, and the stations which is near Kiki's home so, she can take. Suppose Kiki can change the bus at any station. Please find the least time Kiki needs to spend. To make it easy, if the city has n bus stations, the stations would been expressed
1 //bare topology Ordering, note that the first output is a small number, using the priority queue to2#include 3#include 4#include 5#include 6#include 7 using namespacestd;8 Const intMAXN =505;9vectorint>V[MAXN];Tenpriority_queueint>Q; One intF[MAXN]; A intMain () - { - intn,m,x,y; the while(~SCANF ("%d%d",n,m)) - { -Memset (F,0,sizeoff); - for(inti =1; I i) + v[i].clear (); - while(m--) + { Ascanf"%d%d",x,y); at v[x].push_back (y); -++F[y]; - } -
means it can be processed either A at mode_x, or in machine B at mode_y.Obviously, to accomplish all the jobs, we need to change the machine's working mode from time to time, but unfortunately, The machine's working mode can only is changed by restarting it manually. By changing the sequence of the jobs and assigning each job to a suitable machine, please write a program to minimize the Times of restarting machines.Inputthe input file for this program consists of several configurations. The fir
Harry and Magical ComputerTime limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)Total submission (s): 265 Accepted Submission (s): 123Problem DescriptionIn reward of being yearly outstanding magic student, Harry gets a magical computer. When the computer begins-deal with a process, it'll work until the ending of the processes. One day the computer got N processes to deal with. We number the processes from 1 to n. However there is some dependencies between some processes
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.