找礼物(find)
2016-07-31 11:25
344 查看
找礼物(find)
题目描述
新 年到了,你的好友和你(共K个人)的周围满是礼物,你让你的好友先拿,但是每个人只能拿当前离自己最近的礼物[当然如果有并列的多个礼物离你的距离相等 (精确到小数点后四位,所有运算均为去尾),这些礼物就都属于这个人]。现在你们所在的位置是原点(0,0),每个礼物的位置用坐标表示。现在告诉你每个 礼物的坐标,还有每个礼物是谁送的。要你找出你的礼物离你多远,你能拿到多少礼物,这些礼物是谁送的。如果你拿不到礼物,请输出“555…”。输入
第1行:N和K分别表示礼物的个数和人数(K≤N≤100000);第2到N+1行:每行先是赠送礼品人的姓名,然后是礼物的坐标(x,y)(坐标绝对值小于106)。数据间用空格分开。
输出
第1行:D和U表示礼物距你多远(只要去尾后的整数)和你能拿到多少礼物。第2到U+1行:每行一个人名,表示送礼的人(按照输入的顺序输出)。
样例输入
5 2 Jason 1 1 Herry 4 4 Patty 3 4 Tom 2 10 Petter 5 10
样例输出
5 1 Patty
提示
long long大法好
#include <iostream> #include <cstdio> #include <algorithm> #include <queue> #include <cmath> using namespace std; typedef long long int ll; struct point { string name; ll d; int num; }; bool cmp(const point a, const point b) { if(a.d == b.d) { return a.num < b.num; } return a.d < b.d; } int main() { ios::sync_with_stdio(false); int n, k; cin >> n >> k; point s[100002]; ll x, y; for(int i = 0; i < n; i++) { cin >> s[i].name>> x >> y; s[i].num = i; s[i].d = ll(sqrt(x*x + y*y + 0.0)*10000); } sort(s, s+n, cmp); queue<int>que; int cnt = 1; ll lem = s[0].d; if(k == 1){ que.push(0); } for(int i = 1; i < n; i++) { if(s[i].d != lem) { cnt++; lem = s[i].d; } if(cnt == k) { que.push(i); } } if(que.size() > 0) { int x = que.front(); cout<< s[x].d/10000 <<" "<<que.size() << endl; while(!que.empty()){ int x = que.front(); cout << s[x].name << endl; que.pop(); } }else { cout<<"555..."<<endl; } return 0; }
View Code
相关文章推荐
- 找礼物(find)(模拟)
- find 命令用法 find
- uva 11987 Almost Union-Find (并查集)
- EnCase v.s. FTK - find out Chinese characters writing in different direction
- 解决 Could not find junit.jar (junit:junit:4.12) 错误
- Find The Multiple(poj 1426)
- 使用cv::findFundamentalMat要注意的几点
- thinkphp find() 方法和 select()的小区别
- linux常用命令(21):find命令之xargs
- obj type using in findobj
- poj 2356 Find a multiple【抽屉原理】
- find命令
- NDK&nbsp;cygwin编译&nbsp;cannot&nbsp;find&nbsp;lffmp…
- poj 1426 Find The Multiple ( dfs )
- Android studio报:Caused by: java.lang.ClassNotFoundException: Didn't find class "xhs.com.view.ParentV
- gmp4.3.2 安装 configure: error: could not find a working compiler
- find 命令应用
- 遍历ftp上文件 CFtpFileFind
- Win7 64bit 下Python 安装Numpy Unable to find vcvarsall.bat
- hdu 5907 Find Q【模拟】