zoukankan      html  css  js  c++  java
  • 贪心—— Zoj_3589

    难点不在贪心,在于对字符串的处理,字符串处理为数字sscanf就可以了

    View Code
    #include<iostream>
    #include<algorithm>
    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    using namespace std;

    struct data
    {
    double x,y;
    int time;
    }s[100009];

    double dis[100009];

    double fdis(double x0,double y0,double x1,double y1)
    {
    double all=(x0-x1)*(x0-x1)+(y0-y1)*(y0-y1);
    return sqrt(all);
    }

    int cmp(data a,data b)
    {
    return a.time<b.time;
    }

    int main()
    {
    char str[1009];
    scanf("%s",str);
    int k;
    int end=0;

    while(1)
    {
    int i;
    int add=0;
    scanf("%d",&k);
    while(1)
    {
    if(scanf("%s",str)==EOF)
    {
    end=1;
    break;
    }
    if(strcmp(str,"[HitObjects]")==0)
    {
    break;
    }

    sscanf(str,"%lf,%lf,%d,%*lf,%*lf",&s[add].x,&s[add].y,&s[add].time);
    add++;
    }

    if(k==1)
    {
    printf("0.000\n");
    }
    else
    {
    sort(&s[0],&s[add],cmp);
    for(i=0;i<add-1;i++)
    {
    dis[i]=fdis(s[i].x,s[i].y,s[i+1].x,s[i+1].y);
    }
    sort(&dis[0],&dis[add-1]);

    printf("%.3lf\n",dis[add-k]);
    }

    if(end==1)
    {
    break;
    }
    }

    return 0;
    }



  • 相关阅读:
    第十五周作业
    第十四周作业
    第十三周
    第十二周作业
    第二次考试
    太强了,大佬开源的算法小抄彻底火了
    npm--npm 全局安装路径的修改和环境变量的配置
    239
    238
    学术类论文查看--AMiner
  • 原文地址:https://www.cnblogs.com/huhuuu/p/2398763.html
Copyright © 2011-2022 走看看