题意:https://codeforc.es/problemset/problem/195/D

求折线段数。

思路:

对pos进行sort,对不同区间段加k,两个dp处理不同k>0 or k<0前后缀,判断即可。

注意:long double,ESP=1e-20。

 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>//freopen("C:\\Users\\13606\\Desktop\\草稿.txt","r",stdin);
#include <bitset>
//#include <map>
//#include<unordered_map>
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr
#include <string>
#include <time.h>//srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
#include <vector>//emplace_back
//#include <math.h>
//#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
#define fo(a,b,c) for(register int a=b;a<=c;++a)
#define fr(a,b,c) for(register int a=b;a>=c;--a)
#define mem(a,b) memset(a,b,sizeof(a))
#define pr printf
#define sc scanf
#define ls rt<<1
#define rs rt<<1|1
typedef long long ll;
#define RG register int;
void swapp(int &a,int &b);
double fabss(double a);
int maxx(int a,int b);
int minn(int a,int b);
int Del_bit_1(int n);
int lowbit(int n);
int abss(int a);
//const long long INF=(1LL<<60);
const double E=2.718281828;
const double PI=acos(-1.0);
const int inf=(<<);
const double ESP=1e-;
const int mod=(int)1e9+;
const int N=(int)1e6+; struct node
{
int k,b,id;
long double pos;
friend bool operator<(node a,node b)
{
return a.pos<b.pos;
}
}a[N]; long double get(int k,int b)
{
long double len=1.0*b/(1.0*k);
len=abs(len);
if(k>)
{
if(b>)
return -len;
else
return len;
}
else
{
if(b>)
return len;
else
return -len;
}
}
bool same(long double x,long double y)
{
return abs(x-y)<ESP;
} ll dp[N],dp2[N]; int main()
{
int n,cnt=;
long double xx;
sc("%d",&n);
for(int i=;i<=n;++i)
{
int k,b;
sc("%d%d",&k,&b);
if(k==)
continue;
a[++cnt]={k,b},a[cnt].pos=get(a[cnt].k,a[cnt].b);
}
n=cnt;
sort(a+,a++n);
a[].id=;
int id=;
for(int i=;i<=n;++i)
{
if(!same(a[i].pos,a[i-].pos))
id++;
a[i].id=id;
}
for(int i=;i<=n;++i)
if(a[i].k>)
dp[a[i].id]+=a[i].k;
for(int i=;i<=n;++i)
dp[i]+=dp[i-];
for(int i=n;i>=;--i)
{
if(a[i].k<)
dp2[a[i].id-]+=a[i].k;
}
for(int i=n;i>=;--i)
dp2[i]+=dp2[i+];
int ans=;
for(int i=;i<=id;++i)
if(dp[i]+dp2[i]!=dp[i-]+dp2[i-])
ans++;
pr("%d\n",ans);
return ;
} /**************************************************************************************/ int maxx(int a,int b)
{
return a>b?a:b;
} void swapp(int &a,int &b)
{
a^=b^=a^=b;
} int lowbit(int n)
{
return n&(-n);
} int Del_bit_1(int n)
{
return n&(n-);
} int abss(int a)
{
return a>?a:-a;
} double fabss(double a)
{
return a>?a:-a;
} int minn(int a,int b)
{
return a<b?a:b;
}

Analyzing Polyline -- Codeforces Round #123 (Div. 2)的更多相关文章

  1. Codeforces Round #123 (Div. 2)

    A. Let's Watch Football 记时间为\(t\), 则\(bt+(b-a)c>=0\),可得\[t \ge \frac{c(a-b)}{b}\] B. After Traini ...

  2. codeforces 578a//A Problem about Polyline// Codeforces Round #320 (Div. 1)

    题意:一个等腰直角三角形一样的周期函数(只有x+轴),经过给定的点(a,b),并且半周期为X,使X尽量大,问X最大为多少? 如果a=b,结果就为b 如果a<b无解. 否则,b/(2*k*x-a) ...

  3. [Codeforces Round #340 (Div. 2)]

    [Codeforces Round #340 (Div. 2)] vp了一场cf..(打不了深夜的场啊!!) A.Elephant 水题,直接贪心,能用5步走5步. B.Chocolate 乘法原理计 ...

  4. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  5. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  6. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  7. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  8. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  9. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

随机推荐

  1. [Linux]虚拟机无法安装deepin15.9的解决方案

    虚拟机deepin15.9无法安装 sda assuming drive cache write through 显示内存不行,重启仍然无法安装 解决方案: 选择全盘安装方式 如果有全屏问题,需安装v ...

  2. Python3 Address already in use 解决方法

    1.查看使用端口号netstat -ntlp 2.根据端口号找到pid 3.杀死程序 kill -9 pid 4.重新启动程序 简单粗暴 我使用python3时编写Socket,linux系统下使用c ...

  3. mounted里面this.$refs.xxx的内容是undefined

    在mounted(){}钩子里面使用this.$refs.xxx,打印出来的却是undefined? DOM结构已经渲染出来了,但是如果在DOM结构中的某个DOM节点使用了v-if.v-show或者v ...

  4. C++11正则表达式初探

    C++正则表达式 在此之前都没有了解过C++的正则,不过现在大多数赛事都支持C++11了,因此有必要学习一下,用于快速A签到题. 所在头文件 #include<regex> 正则表达式语法 ...

  5. flask 部署

    学习 Flask,写完一个 Flask 应用需要部署的时候,就想着折腾自己的服务器.根据搜索的教程照做,对于原理一知半解,磕磕碰碰,只要运行起来了,谢天谢地然后不再折腾了,到下一次还需要部署时,这样的 ...

  6. python并发——信号量

    信号量通常用于保护数量有限的资源,例如数据库服务器.在资源数量固定的任何情况下,都应该使用有界信号量.在生成任何工作线程前,应该在主线程中初始化信号量. 工作线程生成后,当需要连接服务器时,这些线程将 ...

  7. spark MLlib的 pipeline方式

    spark mllib的pipeline,是指将多个机器学习的算法串联到一个工作链中,依次执行各种算法. 在Pipeline中的每个算法被称为"PipelineStage",表示其 ...

  8. 关于jenkins

    启动不了时可更改端口 java -jar jenkins.war –httpPort=8090

  9. 解决Sublime Text3中文显示乱码问题

    一.安装包管理器 使用Ctrl+~快捷键或者通过View->Show Console菜单打开命令行,粘贴如下代码 import urllib.request,os; pf = 'Package ...

  10. 记录学习Linux过程

    第一步fdisk-l 出错 Permission denied? ubuntu@VM-0-6-ubuntu:~$ fdisk -l fdisk: cannot open /dev/vda: Permi ...