日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【CodeForces - 195D】Analyzing Polyline (思维,卡精度的处理方式)

發(fā)布時(shí)間:2023/12/10 编程问答 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【CodeForces - 195D】Analyzing Polyline (思维,卡精度的处理方式) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題干:

As Valeric and Valerko were watching one of the last Euro Championship games in a sports bar, they broke a mug. Of course, the guys paid for it but the barman said that he will let them watch football in his bar only if they help his son complete a programming task. The task goes like that.

Let's consider a set of functions of the following form:

Let's define a sum of?n?functions?y1(x),?...,?yn(x)?of the given type as functions(x)?=?y1(x)?+?...?+?yn(x)?for any?x. It's easy to show that in this case the graph?s(x)is a polyline. You are given?n?functions of the given type, your task is to find the number of angles that do not equal 180 degrees, in the graph?s(x), that is the sum of the given functions.

Valeric and Valerko really want to watch the next Euro Championship game, so they asked you to help them.

Input

The first line contains integer?n?(1?≤?n?≤?105)?— the number of functions. Each of the following?n?lines contains two space-separated integer numbers?ki,?bi?(?-?109?≤?ki,?bi?≤?109)?that determine the?i-th function.

Output

Print a single number — the number of angles that do not equal 180 degrees in the graph of the polyline that equals the sum of the given functions.

Examples

Input

1 1 0

Output

1

Input

3 1 0 0 2 -1 1

Output

2

Input

3 -2 -4 1 7 -5 1

Output

3

題目大意:

? ? 定義一個(gè)y()函數(shù),然后定義一個(gè)s(x)函數(shù),問我們s(x)函數(shù)上有多少個(gè)不是180°的傾角。

解題報(bào)告:

? ? ? 我們假象y(x)不是那樣定義的,它就是簡單的一次函數(shù),那么n個(gè)一次函數(shù)相加肯定是一次函數(shù),都是180°的傾角(直的),那么問題就出現(xiàn)在y(x)<0時(shí),y(x)=0,也就是它本身應(yīng)該加上一個(gè)小于0的數(shù)結(jié)果加上0了,所以就會(huì)有彎曲。也就是記錄與x軸有多少不同的交點(diǎn)。

? ? ? 這題要是直接用set存,然后需要開long double 記錄斜率,并且選擇合適的編譯器,才可以ac。。。不然就卡精度

? ? ?更好的方法是直接以最簡分?jǐn)?shù)的方式存啊。

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<set> #define ll long long #define mp make_pair using namespace std; struct Node {ll b,k; } node[100000 + 5]; set<pair<ll,ll> > st; int main () {ll n,k,b;cin>>n;for(int i = 1; i<=n; i++) {scanf("%lld%lld",&k,&b);if(k == 0) continue;if(k<0&&b<0) k=-k,b=-b;if(b == 0) {st.insert(mp(0,0));continue;}if(k<0&&b>0) k=-k,b=-b;st.insert(mp(k/__gcd(abs(k),abs(b)),b/__gcd(abs(k),abs(b)))); }cout << st.size() << endl;return 0 ; }

?

總結(jié)

以上是生活随笔為你收集整理的【CodeForces - 195D】Analyzing Polyline (思维,卡精度的处理方式)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。