zoukankan      html  css  js  c++  java
  • POJ1328 qsort

    至于很多朋友说这道题快排为什么不行,请看qcmp函数,返回1与-1

    // Rader.cpp : Defines the entry point for the console application.
    //

    #include "stdafx.h"
    #include <algorithm>
    #include <math.h>
    #include <iostream>
    using namespace std;
    typedef struct island{
        double l;
        double r;
    }Node;
    int   qcmp(   const   void   *arg1,   const   void   *arg2   )  
    {  
        return   (((Node*)arg1)->l >  ((Node*)arg2)->l)?1:-1;
    }
    int   cmp(   Node   arg1,   Node   arg2   )  
    {  
        return   arg1.l<  arg2.l;
    }
    int main(int argc, char* argv[])
    {
        freopen("d:/t.txt","r",stdin);
        int count;
        int r;
        int c = 0;
        while(cin>>count>>r&&(count||r)){
            bool err = false;
            Node n[1000];
            c++;
            for(int i=0;i<count;i++){
                double x,y;
                cin>>x>>y;
                y=y<0?-y:y;
                if(y>r){
                    err = true;
                }
                double d = sqrt(r*r-y*y);
                n[i].l = x-d;
                n[i].r = x+d;
            }
            if(err)
            {
                printf("Case %d: -1\n",c);
                continue;
            }
            qsort(n,count,sizeof(n[0]),qcmp);
            //sort(n,n+count,cmp);
            for(int m = 0;m<count;m++)
                printf("%f\n",n[m].l);
            int ans = 1;
            double left = n[0].r;

            for(int j=1;j<count;j++){
                if(n[j].r<=left){
                    left = n[j].r;
                }else{
                    if(n[j].l>left){ans++;left = n[j].r;}
                }
            }
            printf("Case %d: %d\n",c,ans);
        }
        return 0;
    }

  • 相关阅读:
    CentOS7.6下 MariaDB的MHA 集群搭建(一)
    Mariadb10.4 集群压力测试(一)
    Galera 核心参数详解(一)
    Mariadb10.4+ ERROR 1118 (42000): Row size too large (> 8126). Changing some columns to TEXT or BLOB may help. In current row format, BLOB prefix of 0 bytes is stored inline.
    手动打造一个弹窗程序
    IAT HOOK
    进制的本质
    基于数组越界的缓冲区溢出
    函数调用堆栈图-c语言
    算法之二分查找(上)-c语言实现
  • 原文地址:https://www.cnblogs.com/yangyh/p/2033104.html
Copyright © 2011-2022 走看看