当前位置:网站首页>Codeforces Round #707 (Div. 2) C(抽屉原理)
Codeforces Round #707 (Div. 2) C(抽屉原理)
2022-08-08 19:01:00 【Here_SDUT】
题意
给你一个数组,找出四个数,使得其中两个的和等于另外两个的和,输出下标。最多2e5个数,每个数范围为1-2.5e6。
分析
由于数字范围为1-2.5e6,所以两个数字相加最多达到5e6,运用抽屉原理知道,如果有5e6+1个数,那么这些数里一定有数相同。所以我们可以直接暴力合并所有的数,最多合并5e6+1次就会产生至少两个相同的数,直接跳出循环。还有一个坑,本题不能顺序遍历,而是要按间隔遍历,样例8会卡顺序遍历。顺序遍历的缺点是冲突的风险太大了,每次便利的时候,对于内循环的所有结果都不能贡献给答案,因为有一个共同的数。
代码
// _ooOoo_
// o8888888o
// 88" . "88
// (| -_- |)
// O\ = /O
// ____/`---'\____
// . ' \| |// `.
// / \||| : |||// \
// / _||||| -:- |||||- \
// | | \\ - /// | |
// | \_| ''\---/'' | |
// \ .-\__ `-` ___/-. /
// ___`. .' /--.--\ `. . __
// ."" '< `.___\_<|>_/___.' >'"".
// | | : `- \`.;`\ _ /`;.`/ - ` : | |
// \ \ `-. \_ __\ /__ _/ .-` / /
// ======`-.____`-.___\_____/___.-`____.-'======
// `=---='
//
// .............................................
// 佛祖保佑 一发AC 永无BUG
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn = 7e6 + 10;
const int inf = 0x3f3f3f3f;
const double PI = acos(-1.0);
typedef pair<int, int> PII;
vector<PII> num[maxn];
inline int read() {
int X = 0;
bool flag = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') flag = 0;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
X = (X << 1) + (X << 3) + ch - '0';
ch = getchar();
}
if (flag) return X;
return ~(X - 1);
}
int a[maxn];
int main(int argc, char const *argv[]) {
int n 9;
n = read();
for (int i = 1; i <= n; i++) a[i] = read();
for (int i = 1; i <= n; i++) {
for (int j = 1; j + i <= n; j++) {
int x = a[j] + a[j + i];
num[x].push_back({j, j + i});
for (int k = 0; k < num[x].size(); k++) {
if (num[x][k].first == j || num[x][k].first == j + i ||
num[x][k].second == j || num[x][k].second == j + i)
continue;
puts("YES");
cout << j << ' ' << j + i << ' ' << num[x][k].first << ' '
<< num[x][k].second << endl;
return 0;
}
}
}
// for (int i = 1; i <= n; i++) {
// for (int j = i + 1; j <= n; j++) {
// int x = a[i] + a[j];
// num[x].push_back({i, j});
// for (int k = 0; k < num[x].size(); k++) {
// if (num[x][k].first == i || num[x][k].first == j ||
// num[x][k].second == i || num[x][k].second == j)
// continue;
// puts("YES");
// cout << i << ' ' << j << ' ' << num[x][k].first << ' '
// << num[x][k].second << endl;
// return 0;
// }
// }
// }
puts("NO");
return 0;
}边栏推荐
- [BJDCTF2020]Easy MD5
- Performance optimization | CPU power management from the perspective of ping delay
- 几何g6将搭载harmonyos系统,产品竞争力全面升级
- shell九九乘法口诀表
- Implement the entire process of Mock API with tools
- Codeforces Round #705 (Div. 2)
- PG 之 huge page
- 第4讲:SQL语句之DDL类型的数据库定义语言
- FastDFS distributed file system
- APICloud AVM wraps date and time selection components
猜你喜欢

卡通渲染的历史

Michael Bronstein 系列长文:迈向几何深度学习(之三)——第一个几何神经网络模型

用工具实现 Mock API 的整个流程

【kali-权限提升】(4.2.6)社会工程学工具包(上):中间人攻击原理

Implementing Forward+ in Unity URP

How to add F4 Value Help trial version to the input parameters of the report in the ABAP report

Laravel 5.8 Notes

一起了解分层架构&SOA架构

odoo login layout adjustment

Azure Neural TTS 持续上新,助力企业开拓小语种市场
随机推荐
nyoj685 查找字符串(map)
使用 lua 运行 fscript
PX4-Things you need to know for secondary development of flight control-Cxm
分布式文件系统fastDFS
Flutter Chart
We want to replace the RDS database and upgrade from sqlserver 2016 web to 2017 enterprise cluster version, with expert consultation
证券开户选哪个券商平台比较好,哪个更安全
nyoj 712 探 寻 宝 藏(双线dp 第六届河南省程序设计大赛)
智驾科技完成C1轮融资,此前2轮已融4.5亿元
Transsion Holdings: At present, there is no clear plan for the company's mobile phone products to enter the Chinese market
uniapp父组件使用prop将异步的数据传给子组件
启牛商学院开户是安全的吗?开户靠谱吗?
Open Office XML 格式中的 Style 设计原理
APICloud AVM wraps date and time selection components
ABAP 报表中如何给报表的输入参数增添 F4 Value Help
堆排序实现代码
[BJDCTF2020]Easy MD5
第4讲:SQL语句之DDL类型的数据库定义语言
如何在EasyDSS中使用ffmpeg实现点播视频的拼接与合成?
odoo login layout adjustment