Codeforces 161A(贪心)
要点
- 我在想贪心是对的那要二分图何用,自己的想法是:二分图最开始并不知道怎么匹配最好所以就按输入顺序连了,之后慢慢修改;而这道匹配也成对匹配但从一开始你就可以知道选哪个最划算,就是贪心地选最小的。不必考虑有没有可能最优答案是这个人不穿而让给别人,因为这俩人谁穿都一样,贡献都是1.
#include <cstdio>
#include <vector>
using std::vector;
using std::pair;
const int maxn = 1e5 + 5;
int n, m, x, y;
int a[maxn], b[maxn];
vector<pair<int, int>> v;
int main() {
scanf("%d %d %d %d", &n, &m, &x, &y);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
for (int i = 1; i <= m; i++)
scanf("%d", &b[i]);
for (int i = 1, j = 1; i <= n; i++) {
for (; j <= m && a[i] - x > b[j]; j++);
if (j > m) break;
if (a[i] + y >= b[j]) {
v.push_back({i, j});
j++;
}
}
printf("%d\n", (int)v.size());
for (auto i : v) {
printf("%d %d\n", i.first, i.second);
}
}
Codeforces 161A(贪心)的更多相关文章
- CodeForces - 893D 贪心
http://codeforces.com/problemset/problem/893/D 题意 Recenlty Luba有一张信用卡可用,一开始金额为0,每天早上可以去充任意数量的钱.到了晚上, ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划
There are n people and k keys on a straight line. Every person wants to get to the office which is l ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 828D) - 贪心
Arkady needs your help again! This time he decided to build his own high-speed Internet exchange poi ...
- CodeForces - 93B(贪心+vector<pair<int,double> >+double 的精度操作
题目链接:http://codeforces.com/problemset/problem/93/B B. End of Exams time limit per test 1 second memo ...
- C - Ordering Pizza CodeForces - 867C 贪心 经典
C - Ordering Pizza CodeForces - 867C C - Ordering Pizza 这个是最难的,一个贪心,很经典,但是我不会,早训结束看了题解才知道怎么贪心的. 这个是先 ...
- Codeforces 570C 贪心
题目:http://codeforces.com/contest/570/problem/C 题意:给你一个字符串,由‘.’和小写字母组成.把两个相邻的‘.’替换成一个‘.’,算一次变换.现在给你一些 ...
- Codeforces 732e [贪心][stl乱搞]
/* 不要低头,不要放弃,不要气馁,不要慌张 题意: 给n个插座,m个电脑.每个插座都有一个电压,每个电脑都有需求电压. 每个插座可以接若干变压器,每个变压器可以使得电压变为x/2上取整. 有无限个变 ...
- Codeforces 721D [贪心]
/* 不要低头,不要放弃,不要气馁,不要慌张. 题意: 给一列数a,可以进行k次操作,每次操作可以选取任意一个数加x或者减x,x是固定的数.求如何才能使得这个数列所有数乘积最小. 思路: 贪心...讨 ...
- CodeForces - 424B (贪心算法)
Megacity Time Limit: 2000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Sta ...
随机推荐
- 线程池ThreadPool的常用方法介绍
线程池ThreadPool的常用方法介绍 如果您理解了线程池目的及优点后,让我们温故下线程池的常用的几个方法: 1. public static Boolean QueueUserWorkItem(W ...
- mysql之count
两种引擎对count的处理 CREATE TABLE `test` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `name` char(15) D ...
- 书写优雅的shell脚本(八)- 日期格式化
1. 将日期格式转为时间戳 获取当前时间:currenttime=`date "+%Y-%m-%d %H:%M:%S"` 结果:2015-04-13 11:15:43 将当前时间转 ...
- hdu-5862 Counting Intersections(线段树+扫描线)
题目链接: Counting Intersections Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K ...
- ACM学习历程——HDU4472 Count(数学递推) (12年长春区域赛)
Description Prof. Tigris is the head of an archaeological team who is currently in charge of an exca ...
- node.js setup wizard ended prematurely Win7安装nodejs失败解决方法
笔记本win7在nodejs官方网站下载.msi文件安装,安装到一半的时候,进度条提示:roll back,because of a error.node.JS setup wizard ended ...
- JS---分解质因数
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- [Hadoop] Sqoop安装过程详解
Sqoop是一个用来将Hadoop和关系型数据库中的数据相互转移的工具,可以将一个关系型数据库(例如 : MySQL ,Oracle ,Postgres等)中的数据导进到Hadoop的HDFS中,也可 ...
- There is no resul…
There is no result type defined for type 'json' mapped with name 'success'. 这个错误是json初学者很容易遇到的错误:现在把 ...
- apache配置中的小细节
configuration error: couldn’t perform authentication错误的解决办法 configuration error: couldn’t perform au ...