zoukankan      html  css  js  c++  java
  • 找礼物(find)(模拟)

    找礼物(find)

    时间限制: 1 Sec  内存限制: 64 MB
    提交: 57  解决: 4
    [提交][状态][讨论版]

    题目描述

    新 年到了,你的好友和你(共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
    
    【分析】太坑了,太坑了,太坑了,重要的事情说三遍。一开始用double存距离,WA了好几发,然后听了一个大神的劝告,乖乖的用上long long。下面是AC代码。
    #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>
    #define inf 0x3f3f3f3f
    #define mod 1000000007
    typedef long long ll;
    using namespace std;
    const int N=100010;
    int k,n,m;
    queue<string>q;
    struct man
    {
        ll s;
        string name;
    };man a[N],w[N];
    bool cmp(man g,man h)
    {
        return g.s<h.s;
    }
    int main () {
         cin>>n>>k;
         string l;
        for(int i=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;
        int j=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...
    ");exit(0);}
        int ans=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())
            {
                string ss=q.front();q.pop();cout<<ss<<endl;
            }
         return 0;
    }
    View Code
  • 相关阅读:
    js引用类型赋值不改变原对象值
    VS2017启动实例调试(谷歌浏览器)闪退问题
    ext6时间控件(带时分秒)
    extjs列表中文件上传与下载(带有重命名操作)
    c# word(1) 向标签处添加文字
    关于页面加载后执行使用afterrender
    ExtJS,grid多选框列
    vue起手式
    Javascript诞生与历史
    markdown语法说明
  • 原文地址:https://www.cnblogs.com/jianrenfang/p/5722784.html
Copyright © 2011-2022 走看看