Address: http://acm.uestc.edu.cn/#/problem/show/1329
Topic:
Ching and MagicTime limit:1200/800ms (java/others) Memory limit:65535/65535kb (java/others)SubmitStatus
"Your membrane will not save you"--clam
In the way to save the princess, the Qing school elder sister, the blade has long been rusty stains.
A day Ching is worrying about the problem of weapons, met the tree in the days of the line Liao.
Day Line Liao Mouth Micro-Yang, seems to see through the Ching of the mind, deliberately wait here.
"Young man, do you desire to master the power of thunder?" "The day Liao is asking."
Was almost a salted fish Ching gladly agreed. Yu Shiqing began to follow the Magic Master Day Liao learning the power of magic.
Just getting started, Ching found that each magic is made up of two basic elements, A and B elements.
And the magic of each magic is the synthesis of the magic of A and B elements of the size and.
For example, a element with a size of 3 and a B element with a size of 6 can form a magical magic of 9.
Now the Qing school sister collected N "> N n a element and N "> n n a B element.
Keen Ching immediately found that he could assemble N & #x2217; N " >n∗n n∗n magic.
Modest Ching doesn't want to jump too much, so he's ready to N & #x2217; N " >n∗n n∗n magic of the smallest N "> n n species show to the day Liao inspection.
Now Ching want to know what the smallest n-n species of n ∗nn∗n Magic is.
Of course, from small to large output OH ~
Input
First line an integer N "> N n
The next line has N "> N n number, indicating N "> n n a element
The next line has N "> N n number, indicating N "> n n a b element
1 & #x2264; N & #x2264; 100000 " >1≤n≤100000 1≤n≤100000
1≤A[i],B[i]≤1000000000 1≤a[i],b[i]≤1000000000
Output
Output N ">< Span id= "mathjax-span-242" class= "Mrow" >n n line, one integer per line
Represents the smallest n n of n ∗nn∗n Magic
Sample Input and output
Sample Input |
Sample Output |
51 3 2 4 5 6 3 4 1 7 |
23445 |
Ideas:
is to first drag a[i]+b[0] into a priority queue, and then remove the minimum value a[i]+b[k] at the same time, and throw a[i]+b[k+1] in, and then until the n number is removed.
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 using namespacestd; - inta[100000],b[100000]; - intc[100000]; - + intMain (void) - { + intN; ACin>>N; at for(intI=1; i<=n;i++) -scanf"%d",&a[i]); -Sort (A +1, a+n+1); - for(intI=1; i<=n;i++) -scanf"%d",&b[i]); -Sort (b +1, b+n+1); inpriority_queue<pair<int,int> >s; - for(intI=1; i<=n;i++) toS.push (Make_pair (a[i]+b[1]),1)); + for(intI=1; i<=n;i++) - { thepair<int,int> temp=s.top (); S.pop (); *c[i]=-Temp.first; $ intk=Temp.second;Panax Notoginseng if(temp.second<n) S.push (Make_pair (-(-temp.first-b[k]+b[k+1]), K +1)); - } the for(intI=1; i<=n;i++) +printf"%d\n", C[i]); A return 0; the } + - $ //struct Node $ //{ - //int sum,b; - //node (int a,int b): Sum (a), B (b) {} the //bool operator< (node &a) const - // {Wuyi //return sum>a.sum; the // } - //};
View Code
hdu1329 Ching and Magic