CodeForces - 1324D Pair of Topics(二分或双指针)
题意:略
题记:
做法一:二分
#include<bits/stdc++.h>using namespace std;
typedef long long ll;
const int N=2e5+10;
int a[N],b[N],c[N];int main(){int n;cin>>n;for(int i=1;i<=n;i++)cin>>a[i];for(int i=1;i<=n;i++)cin>>b[i],c[i]=a[i]-b[i];sort(c+1,c+1+n);ll ans=0;for(int i=1;i<=n;i++){if(c[i]<=0) continue;int p=upper_bound(c+1,c+1+n,-c[i])-c;ans+=i-p;}cout<<ans<<endl;return 0;
}
做法二:双指针
#include<bits/stdc++.h>using namespace std;
typedef long long ll;
const int N=2e5+10;
int a[N],b[N],c[N];int main(){int n;cin>>n;for(int i=1;i<=n;i++)cin>>a[i];for(int i=1;i<=n;i++)cin>>b[i],c[i]=a[i]-b[i];sort(c+1,c+1+n);ll ans=0;int l=1,r=n;while(l<r){if(c[l]+c[r]>0){ans+=r-l;r--;}else l++;}cout<<ans<<endl;return 0;
}
CodeForces - 1324D Pair of Topics(二分或双指针)相关推荐
- [Codeforces Round #627]1324D - Pair of Topics[二分]
1324D - Pair of Topics[二分] time limit per test memory limit per test input output 2 seconds 256 mega ...
- CodeForces - 1324D Pair of Topics (分治+排序)
CodeForces - 1324D Pair of Topics 题目大意: 这题大意ai+aj>bi+bj全在这个式子上,就问你满足的组合有几种, 题目分析: 整理一下,得到(ai-bi)+ ...
- CodeForces - 1324D Pair of Topics(思维+二分)
题目链接:https://vjudge.net/contest/362265#problem/D The next lecture in a high school requires two topi ...
- [codeforces 1324D] Pair of Topics 分而治之+排列组合
Codeforces Round #627 (Div. 3) 比赛人数6434 [codeforces 1324C] Frog Jumps 一直向右+边界处理 总目录详见https://bl ...
- Codeforces 1324D Pair of Topics
题目链接:https://codeforces.com/contest/1324/problem/D 题目描述 有两个长度为 n 的数组 A, B.问有多少对 (i,j) 满足 i < j 且 ...
- cf 1324D. Pair of Topics
D. Pair of Topics 题意:给定ab序列,问i<j且ai+aj>bi+bj的对数. 转化:ai-bi<-(aj-bj) 一开始拿到题目想着sort,但是发现i<j ...
- Codeforces 359D Pair of Numbers | 二分+ST表+gcd
题面: 给一个序列,求最长的合法区间,合法被定义为这个序列的gcd=区间最小值 输出最长合法区间个数,r-l长度 接下来输出每个合法区间的左端点 题解: 由于区间gcd满足单调性,所以我们可以二分区间 ...
- CodeForces - 1324 D. Pair of Topics 思维+多解法
CodeForces - 1324 D. Pair of Topics 原题地址: http://codeforces.com/contest/1324/problem/D 基本题意: 给你一个数组, ...
- Codeforces1324D Pair of Topics (思维 + 二分)
题目链接: Pair of Topics 大致题意 给定两个数组a和b, 要求找出所有满足i < j 并且 ai + aj > bi + bj 的所有数对. 解题思路 我们不难想到先对等式 ...
最新文章
- Spring3.2.0-mybatis3.2.0 基于全注解搭建的后台框架-基础版
- 安装fiddler做代理,本地开发手机端看效果
- 用gameMaker做个小游戏
- map初始化_您可曾这样初始化一个map呢?
- oracle leg函数,oracle对象 约束索引 游标 函数
- 职业学校计算机主要学什么条件,职业学校计算机教学计划
- oopc——6.oopc的好处
- 台积电CEO魏哲家:3nm工艺按计划推进 明年一季度将看到营收
- 求众数leetcode(169)+投票算法
- 入门 ggplot2 的图形语法
- 在linux系统上启动oracle的服务
- Python安装指南
- 图解TCPIP 学习笔记(一)
- 2014年南京航空航天大学计算机学院推荐研究生公示,2014年南航计算机科学与技术学院考研分数线及复试调剂办法...
- usb网卡android驱动+win7,usb网卡万能驱动_手把手教你usb网卡驱动
- [高通SDM450][Android9.0]PL2303G驱动升级
- 计算机图形学实用教程苏小红,计算机图形学实用教程(第4版)
- 51单片机流水灯和蜂鸣器同步
- 22届哈工大深圳计算机854考研经验贴、过程总结贴(初试 353 复试 304 上岸哈工大深圳)
- 通过 api 调用检查具体日期是否为法定节假日