Codeforces956D. Contact ATC

$n \leq 100000$个飞机在坐标轴上,给坐标给速度,坐标速度异号,还有一个风速在$[-w,w]$区间,$w$比最小的速度绝对值要小。由于风速不知道,所以问有多少对飞机可能在原点相遇。

思维定势:$\frac{x_i}{v_i+v}=\frac{x_j}{v_j+v}$,$v$是风速,然后推下去,会推到一个三维偏序。。

没有观察题目性质。这个时间是关于风速单调而连续的,所以只要风速最小和风速最大这两个东西求个逆序对就行了。

似乎卡精度,用了分数。

这种题要写题解感觉最近脑子有点锈。。有没有神犇愿意帮忙除个锈啊QAQ

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<stdlib.h>
 4 //#include<math.h>
 5 //#include<queue>
 6 //#include<vector>
 7 #include<algorithm>
 8 //#include<iostream>
 9 //#include<assert.h>
10 using namespace std;
11
12 int n,w;
13 #define maxn 200011
14
15 struct frac
16 {
17     int a,b;
18     bool operator < (const frac &x) const {return 1ll*a*x.b<1ll*b*x.a;}
19     bool operator == (const frac &x) const {return 1ll*a*x.b==1ll*b*x.a;}
20 };
21
22 struct Poi{frac x,y; int z;}p[maxn];
23 bool cmpx(const Poi &a,const Poi &b) {return b.x<a.x || (a.x==b.x && a.y<b.y);}
24 frac lisa[maxn]; int li=0;
25
26 struct BIT
27 {
28     int a[maxn],n;
29     void clear(int m) {n=m;}
30     void add(int x,int v) {for (;x<=n;x+=x&-x) a[x]+=v;}
31     int query(int x) {int ans=0; for (;x;x-=x&-x) ans+=a[x]; return ans;}
32 }t;
33
34 #define LL long long
35 int main()
36 {
37     scanf("%d%d",&n,&w);
38     for (int i=1,a,b;i<=n;i++)
39     {
40         scanf("%d%d",&a,&b);
41         if (a<0) p[i].x=(frac){-a,b-w},p[i].y=(frac){-a,b+w};
42         else p[i].x=(frac){a,w-b},p[i].y=(frac){a,-w-b};
43         lisa[++li]=p[i].y;
44     }
45     sort(lisa+1,lisa+1+li);
46     for (int i=1;i<=n;i++) p[i].z=lower_bound(lisa+1,lisa+1+li,p[i].y)-lisa;
47
48     sort(p+1,p+1+n,cmpx);
49     t.clear(n);
50     LL ans=0;
51     for (int i=1;i<=n;i++)
52     {
53         ans+=t.query(p[i].z);
54         t.add(p[i].z,1);
55     }
56     printf("%lld\n",ans);
57     return 0;
58 }

原文地址:https://www.cnblogs.com/Blue233333/p/8797934.html

时间: 2024-08-30 15:06:29

Codeforces956D. Contact ATC的相关文章

CF 472 div1 D. Contact ATC

#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <vector> const int N = 1e5

Codeforces Round #472 (based on VK Cup 2018 Round 2)解题报告

A. Mystical Mosaic 题目大意: 给一个空白矩阵,每次可以选一些行和一些列并让他们的交点涂黑,每次选的行和列不能有交集. 给出最后的矩阵样子,问能不能经过若干次以上操作后得到最后的矩阵. 思路: 每一行都可以确定哪些列必须被覆盖记为Si,任意两个不同的行之间要么S相等要么相交为空集. 所以我们要做的就是确定任意两行,他们的S要么相等要么相交为空集,这是答案为Yes的充要条件. 代码: 1 #include <bits/stdc++.h> 2 using namespace st

2018暑期做题部分整合

<Matrix>(HDU) 题意:n*m矩阵,每个点可黑可白,问有多少种方案使矩阵至少有A行B列全黑. 思路:第一反应当然是容斥,但是发现a+1行全黑的方案,并不是恰被a行全黑的方案多算a次,所以直接+1,-1,+1,-1这样的容斥系数就不可行. 而如果DP,复杂度太高,不可行. 于是考虑手推容斥系数,a行全黑的方案,被计数的次数取为([a>=A]-被更小的a计算次数)即可. 收获:对于复杂的计数问题,如果分类时,一种方案会在若干类中重复计数,可以使用推广的容斥来做. <Alway

洛谷 P3133 [USACO16JAN]无线电联系Radio Contact

P3133 [USACO16JAN]无线电联系Radio Contact 题目描述 Farmer John has lost his favorite cow bell, and Bessie the cow has agreed to help him find it! They both fan out and search the farm along different paths, but stay in contact via radio so they can keep in to

手动添加arraylist注解类(Contact联系人对象)

因为在Java核心库不支持arraylist xml直接注解,这里可以自己写个小工具类 Contact.java: package com.newer.xml; import java.util.ArrayList; import org.simpleframework.xml.Attribute; import org.simpleframework.xml.Element; import org.simpleframework.xml.ElementList; import org.simp

C#通讯录——Windows Form Contact List

C#通讯录 Windows Form Contact List 主窗口 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using Syste

解决方法:An error occurred on the server when processing the URL. Please contact the system administrator

在WINDOWS7或SERVER2008上安装了IIS7.5,调试ASP程序时出现以下错误: An error occurred on the server when processing the URL. Please contact the system administrator 解决方法如下:     设置方法一: 以管理员身份运行CMD,将目录定位到%windir%\system32\inetsrv\,然后执行appcmd set config -section:asp -script

UValive3268 Jamie&#39;s Contact Groups(二分+最大流)

题目地址:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1269 Jamie is a very popular girl and has quite a lot of friends, so she always keeps a very long contact list in her cell phone. The c

tomcat shutdown.sh结束不了,Could not contact localhost:8005

使用./shutdown.sh关闭Tomcat,有时会关闭成功,有时会出现关闭错误; Jul 06, 2017 10:57:37 AM org.apache.catalina.startup.Catalina stopServerSEVERE: Could not contact localhost:8005. Tomcat may not be running.Jul 06, 2017 10:57:37 AM org.apache.catalina.startup.Catalina stopS