CF 222D Olympiad 双指针
来源:互联网 发布:淘宝上有高仿手表买么 编辑:程序博客网 时间:2024/05/16 17:57
题目链接:这里
题意:第一行给出两个个数字k和n,第二三行分别有k个数字,求将第二、三行之间的数字相互组合,求最多有多少个组合的和不小于n
解法:将两行数字分别排序,用双端指针分别从头和尾查找最多有多少组合。
代码:
//CF 222D#include <bits/stdc++.h>using namespace std;const int maxn = 1e5+7;int n, x, a[maxn], b[maxn], c[maxn];int main(){ scanf("%d%d", &n, &x); for(int i = 1; i <= n; i++) scanf("%d", &a[i]); for(int i = 1; i <= n; i++) scanf("%d", &b[i]); sort(a+1, a+n+1); sort(b+1, b+n+1); int cnt = n, ans = 0; for(int i = 1; i <= n; i++){ if(a[i] + b[cnt] >= x) cnt--; } ans = n - cnt; cnt = n; for(int i = 1; i <= n; i++){ if(a[cnt] + b[i] >= x) cnt--; } ans = max(ans, n - cnt); printf("1 %d\n", ans); return 0;}
0 0
- CF 222D Olympiad 双指针
- CodeForces 222D Olympiad
- CodeForces 222D Olympiad
- CodeForces 222D Olympiad
- codeforces 222D Olympiad(贪心)
- Codeforces 222D Olympiad(贪心)
- codeforces 662D International Olympiad
- 枚举暴力 cf B. Preparing Olympiad
- cf#306-B. Preparing Olympiad-bitmask暴力
- 【CF 675D】 Tree Construction(离线二分+左右指针)
- olympiad
- Codeforces 662D International Olympiad【贪心】
- CF #347 (Div.2) C. International Olympiad(模拟)
- CF D. Buses
- D. Ball CF
- CF 148D
- CF 173D-- Palindromes
- CF 228D Zigzag
- 基因相关性
- TV Picture菜单的基本参数和属性
- LUbuntu16.10下支持中文(搜狗)输入
- sublime text 3 less安装图文讲解
- 数据库 知识点汇总
- CF 222D Olympiad 双指针
- Android Studio 入门之ListView初级
- 4. HDFS 常用Java API 总结
- 使用Split分割字符串出现数组越界异常java.lang.ArrayIndexOutOfBoundsException
- 数据结构的应用
- 通过生成函数求解汉诺塔的通项公式
- 大型网站架构演化(七)——使用分布式文件系统和分布式数据库系统
- 理解Ionic、Angular、Cordova及插件之间的关系
- Qt学习笔记(二)---实现四则运算