zoukankan      html  css  js  c++  java
  • HDU 1173 采矿

    某天gameboy玩魔兽RPG。有一个任务是在一个富含金矿的圆形小岛上建一个基地,以最快的速度采集完这个小岛上的所有金矿。这个小岛上有n(0<n<1000000)个金矿,每个金矿的矿藏量是相等的。而且这个小岛的地势非常平坦,所以基地可以建在小岛的任何位置,每个金矿的采矿速度只跟矿藏到基地的路程长度有关。为了不让这个任务太无聊,游戏设计者对这个小岛施了个“魔法”,规定矿工在小岛上只能正南正北正西正东走。也就是说矿工不能斜着在岛上走。

    这个小岛在一个二维直角坐标系中描述。

    你的任务就是帮gameboy找一个建造基地的位置,使矿工能以最快的速度采完所有矿。
     

    Input
    输入数据有多组。每组数据的第一行是一个正整数n(0<n<1000000),表示小岛上有n个金矿。在接下来的n行中,每行有两个实数x,y,表示其中一个金矿的坐标。n=0表示输入数据结束。
     

    Output
    每一组输入数据对应一行输出,输出两个实数x,y(保留小数点后两位),也就是你找到的建造基地的位置坐标。如果坐标不唯一,可以任选一个输出。
     

    Sample Input
    4 1.0 1.0 3.0 1.0 3.0 3.0 1.0 3.0 0
     

    Sample Output
    2.00 2.00
     
    刚看到题目时都不知道怎么做,没想到这么水,中位数????
     
    C

    #include <stdio.h>
    #include <stdlib.h>
    double x[1000000],y[1000000];
    int cmp(const void *a,const void *b)
    {
        return (*(double *)a)>(*(double *)b)?1:-1;
    }
    int main()
    {
        freopen("in.txt","r",stdin);
        int n,i;
        while(scanf("%d",&n),n)
        {
            for(i=0;i<n;i++)
              scanf("%lf%lf",&x[i],&y[i]);
            qsort(x,n,sizeof(x[0]),cmp);
            qsort(y,n,sizeof(y[0]),cmp);
            printf("%.2lf %.2lf\n",x[n/2],y[n/2]);
        }
        return 0;
    }

    C++
    #include <cmath>
    #include <queue>
    #include <cstdio>
    #include <cstdlib>
    #include <string.h>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    double x[1000000],y[1000000];
    bool cmp(double a,double b)
    {
        return a<b;
    }
    int main()
    {
        freopen("in.txt","r",stdin);
        int n,i;
        while(scanf("%d",&n),n)
        {
            for(i=0;i<n;i++)
              scanf("%lf%lf",&x[i],&y[i]);
            sort(x,x+n,cmp);
            sort(y,y+n,cmp);
            printf("%.2lf %.2lf\n",x[n/2],y[n/2]);
        }
     return 0;
    }

  • 相关阅读:
    hdu5834 Magic boy Bi Luo with his excited tree 【树形dp】
    POJ2152 Fire 【树形dp】
    POJ1848 Tree 【树形dp】
    hdu3586 Information Disturbing 【树形dp】
    BZOJ4557 [JLoi2016]侦察守卫 【树形dp】
    BZOJ4000 [TJOI2015]棋盘 【状压dp + 矩阵优化】
    BZOJ1487 [HNOI2009]无归岛 【仙人掌dp】
    BZOJ4002 [JLOI2015]有意义的字符串 【数学 + 矩乘】
    洛谷P3832 [NOI2017]蚯蚓排队 【链表 + 字符串hash】
    3-3 银行业务队列简单模拟
  • 原文地址:https://www.cnblogs.com/372465774y/p/2434665.html
Copyright © 2011-2022 走看看