Find a present (find)
Time limit: 1 Sec memory limit: up to MB
Submitted by: $ 4 Solution:
Submitted State [Discussion Version]
Title Description
New Year is coming, your friends and you (a total of K-person) are full of gifts, you let your friends take first, but everyone can only take the present to their nearest gift [of course, if there are multiple gifts in parallel to your distance (accurate to four digits after the decimal point, all operations are the tail), these gifts belong to this person]. Now your position is the origin (0,0), and the position of each gift is expressed in coordinates. Now tell you the coordinates of each gift, and who sent each gift. To find out how far your gift is from you, how many gifts you can get, and who sent the gifts. If you can't get a gift, please output "555 ...".
Input
Line 1th: N and K indicate the number and number of gifts (k≤n≤100000) respectively;
2nd to n+1: Each line first presents the person's name, then the gift coordinates (x, y) (the coordinate absolute value is less than 106). The data is separated by a space.
Output
Line 1th: D and U indicate how far the gift is from you (as long as you go to the end of the whole number) and how many gifts you can get.
2nd to u+1: One person per line, indicating the giver (output in the order entered).
Sample input
5 2Jason 1 1Herry 4 4Patty 3 4Tom 2 10Petter 5 10
Sample output
5 1Patty
"Analysis" too pit, too pit, too pits, important things to say three times. Beginning with a double storage distance, WA a few rounds, and then listened to a great God's advice, obediently use long long. The following is the AC code.
#include <iostream>#include<cstring>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<time.h>#include<string>#include<map>#include<stack>#include<vector>#include<Set>#include<queue>#defineINF 0x3f3f3f3f#defineMoD 1000000007typedefLong Longll;using namespacestd;Const intn=100010;intK,n,m;queue<string>Q;structman{ll S; stringname;}; Man A[n],w[n];BOOLCMP (man G,man h) {returng.s<H.S;}intMain () {CIN>>n>>K; stringl; for(intI=0; i<n;i++) {ll aa,b; CIN>>l>>aa>>b; A[i].s= (ll) (sqrt (aa*aa+b*b+0.0)*10000LL); A[i].name=l; W[i].s=a[i].s;w[i].name=l; } sort (A,a+n,cmp); ll T=a[0].s; intj=0, I; K=k-1; while(k--) { for(i=j;i<n;i++) { if(a[i].s==t)Continue; Else{J=i; T=A[i].s; Break; }} J=i; T=A[i].s; } if(j>=n) {printf ("555...\n"); exit (0);} intans=0; for(i=0; i<n;i++) { if(w[i].s==t) {Ans++;q.push (w[i].name);Continue;} } LL DD=A[j].s; cout<<dd/10000<<" "<<ans<<Endl; while(!Q.empty ()) { stringSs=q.front (); Q.pop ();cout<<ss<<Endl; } return 0;}
View Code
Find a Present (find) (analog)