当前位置:网站首页>【Acwing】The 62nd Weekly Game Solution
【Acwing】The 62nd Weekly Game Solution
2022-07-31 22:48:00 【Xuan Che_】

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
方法一:Read in and find first max 和 min 值 ,Then loop again to find any
,The final judgment can be made
#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:使用mapto store and judge
#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; }
边栏推荐
- One thing to say, is outsourcing company worth it?
- ICML2022 | 深入研究置换敏感的图神经网络
- AI automatic code writing plugin Copilot (co-pilot)
- Commonly used security penetration testing tools (penetration testing tools)
- 什么是客户画像管理?
- Structure of the actual combat battalion module eight operations
- Go mode tidy reports an error go warning “all” matched no packages
- Unity - LineRenderer show a line
- C程序设计-方法与实践(清华大学出版社)习题解析
- Pytest初体验
猜你喜欢

How to identify fake reptiles?

GateWay implements load balancing

Collation of knowledge points in Ningbo University NBU IT project management final exam

基于单片机GSM的防火防盗系统的设计

C#中引用类型的变量做为参数在方法调用时加不加 ref 关键字的不同之处

TestCafeSummary

Daily practice——Randomly generate an integer between 1-100 and see how many times you can guess.Requirements: The number of guesses cannot exceed 7 times, and after each guess, it will prompt "bigger"

ECCV 2022 Huake & ETH propose OSFormer, the first one-stage Transformer framework for camouflaging instance segmentation!The code is open source!...

The difference between adding or not adding the ref keyword when a variable of reference type is used as a parameter in a method call in C#
![[Intensive reading of the paper] iNeRF](/img/a7/910667911e1ce8996b9d22de63ea04.png)
[Intensive reading of the paper] iNeRF
随机推荐
#yyds干货盘点# 面试必刷TOP101:链表中环的入口结点
(26)Blender源码分析之顶层菜单的关于菜单
Shell常用脚本:Nexus批量上传本地仓库增强版脚本(强烈推荐)
I don't know what to do with sync issues
不知道该怎么办的同步问题
TestCafeSummary
How to reduce the gap between software design and implementation
手写一个简单的web服务器(B/S架构)
10大主流3D建模技术
TypeScript 的组件
One thing to say, is outsourcing company worth it?
"The core concept of" image classification and target detection in the positive and negative samples and understanding architecture
22年8月推广大使额外奖励规则
"SDOI2016" Journey Problem Solution
GateWay implements load balancing
Pytest初体验
linux view redis version command (linux view mysql version number)
数据分析(一)——matplotlib
Go mode tidy reports an error go warning “all” matched no packages
@JsonFormat(pattern=“yyyy-MM-dd“)时间差问题

,The final judgment can be made
