Analyzing Polyline -- Codeforces Round #123 (Div. 2)
题意: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)的更多相关文章
- 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 ...
- 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) ...
- [Codeforces Round #340 (Div. 2)]
[Codeforces Round #340 (Div. 2)] vp了一场cf..(打不了深夜的场啊!!) A.Elephant 水题,直接贪心,能用5步走5步. B.Chocolate 乘法原理计 ...
- 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 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- 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 ...
随机推荐
- Java程序基本结构
/** * 可以用来自动创建文档的注释 */ public class Hello { public static void main(String[] args) { // 向屏幕输出文本: Sys ...
- windows 安装python2.7
下载:https://www.python.org/downloads/release/python-2716/ 安装即可. 设置环境变量 进入C:\Python27,修改python.exe 为py ...
- MySQL安装及基础命令
介绍数据库安装基础命令 linux的下载和安装 mac的下载和安装 windows的下载和安装 介绍: 数据库在开发中占据的位置? 数据库能更简单的使用存储在文件中的数据能更好的解决并发问题,数据统一 ...
- BZOJ 4898 Luogu P3778 [APIO2017]商旅 (分数规划、最短路)
题目链接: (bzoj)https://www.lydsy.com/JudgeOnline/problem.php?id=4898 (luogu)https://www.luogu.org/probl ...
- nodejs豆瓣爬虫
从零开始nodejs系列文章,将介绍如何利Javascript做为服务端脚本,通过Nodejs框架web开发.Nodejs框架是基于V8的引擎,是目前速度最快的Javascript引擎.chrome浏 ...
- 微信支付宝xposed个人收款免签支付源码
源码介绍: 个人免签支付是指使用自己的微信支付宝账号作为个人网站的收款账号,网站订单支付成功后,网站能实时收到成功回调信息. 系统基于xposed逆向微信.支付宝.云闪付来实现个人收款免 ...
- 第11组 Alpha冲刺(2/6)
第11组 Alpha冲刺(2/6) 队名 不知道叫什么团队 组长博客 https://www.cnblogs.com/xxylac/p/11860949.html 作业博客 https://edu ...
- IDEA Method definition shorthands are not supported by current JavaScript version
sentinel-dashboard前端用到了AngularJS v1.4.8,在IDEA里修改js,触发js验证时有一些js文件会出现红色波浪线. 在代码行里鼠标一上去提示信息:Method def ...
- Bootstrap4项目开发实战视频教程
一.企业网站项目 课件 0.课程简介 1.顶部区域的制作 2.导航区域的制作 3.轮播区域的制作 4.产品区域的制作 5.最新资讯区域的制作 6.底部区域的制作 二.化妆品网站项目 1.项目初始化_导 ...
- Win10设置文件夹权限报错-(提示:无法枚举容器中的对象 访问被拒绝)
一.右击文件 选择“属性”-“安全”-“高级”,如下图 二.查看哪个用户的权限是:“完全控制”,我这里是“SYSTEM”用户. 三.选择顶部的 “更改-“高级”-“立即查找”,然后选择管理员账户“SY ...