当前位置:网站首页>【Acwing】第62场周赛 题解
【Acwing】第62场周赛 题解
2022-07-31 22:27:00 【玄澈_】
AcWing 4500. 三个元素
输入样例1:
6 3 1 4 1 5 9
输出样例1:
4 1 3
输入样例2:
5 1 1000000000 1 1000000000 1
输出样例2:
-1 -1 -1
输入样例3:
9 10 10 11 10 10 10 10 10 1
输出样例3:
9 8 3
方法一:先读入并找到 max 和 min 值 ,然后再循环一遍找到任意的
,最后进行判断即可
#include <iostream> #include <algorithm> using namespace std; const int N = 3010, INF = 0x3f3f3f3f; int a[N]; int main() { int max = 0, min = INF, mid = 0; int i1 = -1, i2 = -1 , i3 = -1; int n; cin >> n; for(int i = 1; i <= n; i ++ ) { cin >> a[i]; if(a[i] > max) max = a[i], i1 = i; if(a[i] < min) min = a[i], i2 = i; } for(int i = 1; i <= n; i ++ ) { if(a[i] > min && a[i] < max) mid = a[i], i3 = i; } //printf("%d %d %d\n", min, max, mid); if(max != min && max != mid && min != mid && i1 != i2 && i1 != i3 && i2 != i3 && i1 != -1 && i2 != -1 && i3 != -1) { printf("%d %d %d", i2, i3, i1); } else puts("-1 -1 -1"); return 0; }
方法2:使用map来存储并判断
#include <iostream> #include <cstring> #include <map> #include <vector> using namespace std; int main() { int n; cin >> n; map<int, int> pos; for(int i = 1; i <= n; i ++ ) { int x; cin >> x; pos[x] = i; } if(pos.size() < 3) puts("-1 -1 -1"); else { vector<int> res; for(auto [k, v] : pos) res.push_back(v); for(int i = 0; i < 3; i ++ ) cout << res[i] << ' '; } return 0; }
AcWing 4501. 收集卡牌
输入样例1:
3 11 2 3 1 2 2 2 3 2 2 3 1
输出样例1:
00100000001
输入样例2:
4 8 4 1 3 3 2 3 3 3
输出样例2:
00001000
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 100010;
int n, m;
int cnt[N];
int main()
{
cin >> n >> m;
int tot = 0;
while(m -- )
{
int x; scanf("%d", &x);
if(!cnt[x]) tot ++ ;
cnt[x] ++ ;
if(tot == n)
{
printf("1");
for(int i = 1; i <= n; i ++ )
if(-- cnt[i] == 0)
tot -- ;
}
else
{
printf("0");
}
}
return 0;
}
AcWing 4502. 集合操作
输入样例1:
6 1 3 2 1 4 2 1 8 2
输出样例1:
0.000000 0.500000 3.000000
输入样例2:
4 1 1 1 4 1 5 2
输出样例2:
2.000000
#include <iostream> #include <cstring> #include <algorithm> using namespace std; const int N = 500010; int n, m; int w[N]; int main() { scanf("%d", &m); double res = 0, sum = 0; int k = 0; while (m -- ) { int op, x; scanf("%d", &op); if (op == 1) { scanf("%d", &x); w[ ++ n] = x; while (k + 1 <= n && w[k + 1] <= (sum + w[n]) / (k + 1)) sum += w[ ++ k]; res = max(res, w[n] - (sum + w[n]) / (k + 1)); } else { printf("%lf\n", res); } } return 0; }
边栏推荐
- Several methods of mysql backup table
- VOT2021 game introduction
- [QNX Hypervisor 2.2用户手册]9.15 suppress
- Collation of knowledge points in Ningbo University NBU IT project management final exam
- A solution to the server encountered an internal error that prevented it from fulfilling this request [easy to understand]
- Embedded development has no passion, is it normal?
- Commonly used security penetration testing tools (penetration testing tools)
- Binary tree non-recursive traversal
- Linux environment redis cluster to build "recommended collection"
- Thymeleaf是什么?该如何使用。
猜你喜欢
[Intensive reading of the paper] iNeRF
统计UTF-8字符串中的字符函数
Structure of the actual combat battalion module eight operations
Quick Start Tutorial for flyway
二叉树非递归遍历
How to reduce the gap between software design and implementation
Recognize anomalies (you will understand after reading this)
ECCV 2022 Huake & ETH propose OSFormer, the first one-stage Transformer framework for camouflaging instance segmentation!The code is open source!...
嵌入式开发没有激情了,正常吗?
The principle of ReentrantLock (to be continued)
随机推荐
NVIDIA has begun testing graphics products with AD106 and AD107 GPU cores
Qualcomm cDSP simple programming example (to query Qualcomm cDSP usage, signature), RK3588 npu usage query
Memblaze released the first enterprise-grade SSD based on long-lasting particles. What is the new value behind it?
Realize serial port receiving data based on STM32 ring queue
Unity - LineRenderer show a line
求n以内的素数
不知道该怎么办的同步问题
How to identify fake reptiles?
Redis Overview: Talk to the interviewer all night long about Redis caching, persistence, elimination mechanism, sentinel, and the underlying principles of clusters!...
Architecture Battalion Module 8 Homework
利用反射实现一个管理对象信息的简单框架
ReentrantLock原理(未完待续)
二叉树非递归遍历
In Golang go-redis cluster mode, new connections are constantly created, and the problem of decreased efficiency is solved
VOT2021比赛简介
Unity-LineRenderer显示一条线
flowable workflow all business concepts
How to get useragent
[QNX Hypervisor 2.2用户手册]9.14 set
The uniapp applet checks and prompts for updates