• LeetCode 149 Max Points on a Line


    题目

    煞笔题目,怪不得那么多人diss

    两层for循环,它还疯狂卡精度,double的精度不够,必须long double

    class Solution {
    public:
        map<pair<long double,long double>,int> m;
        map<pair<long double,long double>,int> m2;
        map<pair<pair<long double,long double>,int>,int> m3;
        
        int maxPoints(vector<vector<int>>& points) {
            
            if(points.size()==0)
                return 0;
            int mm =1;
            
            for(int i=0;i<points.size();i++)
            {
                
                m2[make_pair(points[i][0],points[i][1])]++;
                
                mm =max(mm,m2[make_pair(points[i][0],points[i][1])]);
                
            }
            
            for(int i=0;i<points.size();i++)
            {
                for(int j=i+1;j<points.size();j++)
                {
                    
                    long double k;
                    if(points[i][0]-points[j][0]==0)
                        k = 99999999;
                    else
                        k =(long double) (points[i][1] - points[j][1]) / (points[i][0] - points[j][0]);
                    long double b;
                    if(points[i][0]-points[j][0]==0)
                        b = points[i][0];
                    else
                        b = points[i][1] - points[i][0]*k;
                    
                    //k = (long double)(((long long int)(k*10000000000))/10000000000.0);
                    //b = (long double)(((long long int)(b*10000000000))/10000000000.0);
                
                    if(m3[make_pair(make_pair(k,b),i)]==0)
                    {
                        m[make_pair(k,b)] +=1;
                        m3[make_pair(make_pair(k,b),i)]=1;
                    }
                    
                    if(m3[make_pair(make_pair(k,b),j)]==0)
                    {
                        m[make_pair(k,b)] +=1;
                        m3[make_pair(make_pair(k,b),j)]=1;
                    }
                    
                    
                }
            }
            
            map<pair<long double,long double>,int>::iterator it;
            
            it = m.begin();
            
            while(it != m.end())
            {
                
                mm =max(mm,it->second);
                it++;
            }
            return mm;
            
        }
    };
    
  • 相关阅读:
    nyoj 311 完全背包
    nyoj 737 石子合并(一)
    nyoj 232 How to eat more Banana
    nyoj 456 邮票分你一半
    nyoj 236 心急的C小加
    nyoj 195 飞翔
    nyoj 201 作业题
    SOS 调试扩展 (SOS.dll)
    使用Windbg和SoS扩展调试分析.NET程序
    windbg命令分类与概述
  • 原文地址:https://www.cnblogs.com/dacc123/p/10767241.html
Copyright © 2020-2023  润新知