要点

  • 我在想贪心是对的那要二分图何用,自己的想法是:二分图最开始并不知道怎么匹配最好所以就按输入顺序连了,之后慢慢修改;而这道匹配也成对匹配但从一开始你就可以知道选哪个最划算,就是贪心地选最小的。不必考虑有没有可能最优答案是这个人不穿而让给别人,因为这俩人谁穿都一样,贡献都是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(贪心)的更多相关文章

  1. CodeForces - 893D 贪心

    http://codeforces.com/problemset/problem/893/D 题意 Recenlty Luba有一张信用卡可用,一开始金额为0,每天早上可以去充任意数量的钱.到了晚上, ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. C - Ordering Pizza CodeForces - 867C 贪心 经典

    C - Ordering Pizza CodeForces - 867C C - Ordering Pizza 这个是最难的,一个贪心,很经典,但是我不会,早训结束看了题解才知道怎么贪心的. 这个是先 ...

  6. Codeforces 570C 贪心

    题目:http://codeforces.com/contest/570/problem/C 题意:给你一个字符串,由‘.’和小写字母组成.把两个相邻的‘.’替换成一个‘.’,算一次变换.现在给你一些 ...

  7. Codeforces 732e [贪心][stl乱搞]

    /* 不要低头,不要放弃,不要气馁,不要慌张 题意: 给n个插座,m个电脑.每个插座都有一个电压,每个电脑都有需求电压. 每个插座可以接若干变压器,每个变压器可以使得电压变为x/2上取整. 有无限个变 ...

  8. Codeforces 721D [贪心]

    /* 不要低头,不要放弃,不要气馁,不要慌张. 题意: 给一列数a,可以进行k次操作,每次操作可以选取任意一个数加x或者减x,x是固定的数.求如何才能使得这个数列所有数乘积最小. 思路: 贪心...讨 ...

  9. CodeForces - 424B (贪心算法)

    Megacity Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Sta ...

随机推荐

  1. BZOJ 1198 [HNOI2006]军机调度:dfs

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1198 题意: 有n个雇佣军,m个任务. 第i个雇佣军能够参加cnt个任务,分别为temp[ ...

  2. kvm初体验之八:调整vm的vcpu, memory, disk大小

    假设host上创建的vm的名字为vm1. 1. 查看vm1的domain information [root@tanghuimin thm]# virsh dominfo vm1 Id: 10 Nam ...

  3. sphinx 全文搜索引擎

    sphinx的安装与配置 --------------------------------------------------------------------------------------- ...

  4. 改变Ecplise项目窗口字体样式

    Eclipse\plugins\org.eclipse.ui.themes_1.1.1.v20151026-1355\css e4-dark_win.css CTabFolder Tree, CTab ...

  5. 基于 bi-LSTM和CRF的中文命名实体识别

    follow: https://github.com/zjy-ucas/ChineseNER  这里边主要识别的实体如图所示,其实也就主要识别人名PER,机构ORG和地点LOC: B表示开始的字节,I ...

  6. PS 滤镜— — 镜头光晕

    clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm'); I=imread ...

  7. super.onCreate(savedInstanceState) 以及onCreate(Bundle savedInstanceState, PersistableBundle persistentState)

    super.onCreate(savedInstanceState) 调用父类的onCreate构造函数. 当一个Activity在生命周期结束前,会调用onSaveInsanceState()这个回 ...

  8. Codeforces Round #394 (Div. 2) 题解

    无需吟唱,直接传送 problem A 题目大意 已知有n个偶数,m个奇数,问这些数有没有可能组成一个严格递增1的序列 题解 判断abs(n,m) <= 1即可,注意n,m均为0的情况. Cod ...

  9. CF1076E:Vasya and a Tree

    浅谈树状数组与线段树:https://www.cnblogs.com/AKMer/p/9946944.html 题目传送门:https://codeforces.com/problemset/prob ...

  10. 实现PIX需要参考的标准资料

    •初步了解PIX V2和V3:"IHE_ITI_TF_Rev8-0_Vol1_FT_2011-08-19"中第5章和第23章 •了解PIX V2相关事务: "IHE_IT ...