2015安徽省賽 C.LU的困惑

來源:互聯網
上載者:User

標籤:

題目描述

Master LU 非常喜歡數學,現在有個問題:在二維空間上一共有n個點,LU每串連兩個點,就會確定一條直線,對應有一個斜率。現在LU把平面內所有點中任意兩點連線,得到的斜率放入一個集合中(若斜率不存在則不計入集合),他想知道這個集合中有多少個元素。

輸入

第一行是一個整數T,代表T組測試資料 每組資料第一行是一個整數n,代表點的數量。2<n<1000 接下來n行,每行兩個整數,0<x<10000,0<y<10000,代表點的座標

輸出

輸出斜率集合中有多少個元素

範例輸入2 4 1 1 2 2 3 3 3 6 4 1 1 2 2 2 0 3 1範例輸出3 3
用set容器
#include<iostream>#include<cstdio>#include<cstring>#include<set>using namespace std;long long d[10005],c[10005];double add(int ax,int bx,int ay,int by){    double tx,ty;    tx=double(bx-ax);    ty=double(by-ay);    if(tx==0){return 23333;}    return ty/tx;} int main(){           set<double> seting;    int T,m,i,j;     double num;    scanf("%d",&T);    while(T>=1)    {        scanf("%d",&m);        for(i=1;i<=m;i++)        {            scanf("%lld %lld",&d[i],&c[i]);        }        for(i=1;i<=m;i++)        {            for(j=i+1;j<=m;j++)            {                num=add(d[i],d[j],c[i],c[j]);                if(num!=23333)                {                    set<double>::iterator it;                    it=seting.find(num);                    if(it==seting.end())                    {                        seting.insert(num);                    }                }            }        }        printf("%d\n",seting.size());        seting.clear();        T--;    }    return 0;}/**************************************************************    Problem: 1207    User: 2014217052    Language: C++    Result: 正確    Time:254 ms    Memory:4572 kb****************************************************************/

 

2015安徽省賽 C.LU的困惑

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.