当前位置:网站首页>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;
}
边栏推荐
- 期货开户哪家公司好,要正规安全的
- 【kali-权限提升】(4.2.6)社会工程学工具包(上):中间人攻击原理
- 生成验证码工具类
- 堆排序实现代码
- How to add F4 Value Help to the input parameters of the report in the ABAP report
- odoo login layout adjustment
- ptorch
- Goose Factory Robot Dog Fancy Crossing 10m Plum Blossom Pile: Front Flip, Single Pile Jump, Get Up and Bow... No stumble in the whole process
- 传统和加密域名概述
- 进化的黑产 vs 进击的蚂蚁:支付宝的每一次点击,都离不开一张“图”的守护
猜你喜欢
Azure Neural TTS continues to be updated to help enterprises develop small language markets
鹅厂机器狗花式穿越10m梅花桩:前空翻、单桩跳、起身作揖...全程不打一个趔趄
leetcode 240.搜索二维矩阵II 分治思想
软件测试主要是做什么的?
Generate captchas tools
Research on ORACLE subqueries that lead to inability to push predicates
无标题文章
进化的黑产 vs 进击的蚂蚁:支付宝的每一次点击,都离不开一张“图”的守护
APICloud AVM wraps date and time selection components
蒲公英R300A 4G路由器,远程监控PLC教程
随机推荐
Is it safe to open an account with Qiniu Business School?Is it reliable to open an account?
odoo 登录布局调整
如何在Firewalld中为特定IP地址开放端口
启牛商学院开户是安全的吗?开户靠谱吗?
We want to replace the RDS database and upgrade from sqlserver 2016 web to 2017 enterprise cluster version, with expert consultation
分布式文件系统fastDFS
hdu2018 母牛的故事(模拟)
Monaco-Editor Multiplayer Collaboration Editor
性能优化|从ping延时看CPU电源管理
Fortinet全新云原生保护产品上线亚马逊云科技平台
How is the private key generated by OpenSSH used in putty?
Geometric g6 will carry harmonyos system, a comprehensive upgrade competitiveness of products
PX4-Things you need to know for secondary development of flight control-Cxm
大学生图书馆网页设计模板代码 DIV布局书店网页作业成品 学校书籍网页制作模板 学生简单书籍阅读网站设计成品
Rethinking HTAP database caused by rereading GPDB and TiDB papers
软件测试基础笔记
The difference between Redis' memory elimination strategy and expired deletion strategy
C语言初阶-结构体
数组!!!
Azure Neural TTS 持续上新,助力企业开拓小语种市场