码迷,mamicode.com
首页 > 其他好文 > 详细

BZOJ 1610 Usaco Line

时间:2017-09-08 20:33:55      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:splay   sed   int   ble   ons   题目   bzoj   space   color   

一道很水的题目,一开始用Set做。莫名其妙WA了,后来想了想。
精度问题很关键!!!

Set AC写法

技术分享
#include <cstdio>
#include <algorithm>
#include <set>
 
using namespace std;
 
 
int n,tot;
double x[233],y[233];
double k,eps=1e-10;
 
struct CMP{
    inline bool operator()(const double x,const double y)const{
        return x>eps+y;
    }
};
 
set<double,CMP>s;
 
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%lf%lf",&x[i],&y[i]);
    }
    for(int i=1;i<n;i++){
        for(int j=i+1;j<=n;j++){
            double fy = y[i] - y[j];
            double fx = x[i] - x[j];
            if(fx==0) s.insert(99999999);
            else s.insert(fy/fx);
        }
    }
    printf("%d\n",s.size());
    return 0;
}
Set

 

Sort AC写法

技术分享
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
 
 
int n,tot=1,pos;
int x[202],y[202];
double k[200005];
 
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d",&x[i],&y[i]);
    }
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            double fy = y[i] - y[j];
            double fx = x[i] - x[j];
            if(fy==0) k[++pos] = 0;
            else if(fx==0) k[++pos]=1000000;
            else k[++pos] = fy/fx;
        }
    }
    std::sort(k+1,k+pos+1);
    for(int i=2;i<=pos;i++){
        if( fabs(k[i]-k[i-1]) > 1e-10) tot++;
    }
    printf("%d\n",tot);
    return 0;
}
Sort

 

BZOJ 1610 Usaco Line

标签:splay   sed   int   ble   ons   题目   bzoj   space   color   

原文地址:http://www.cnblogs.com/OIerLYF/p/7496120.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!