当前位置:网站首页>【AcWing 62nd Weekly Game】
【AcWing 62nd Weekly Game】
2022-07-31 01:44:00 【The romantic dog】
更好的阅读体验 \color{red}{更好的阅读体验} 更好的阅读体验
4500. 三个元素
原题链接
思想
pair<int,int> aStores the value and the corresponding subscript- 对值进行排序,Traverse to find three distinct values
- If it exists, output the subscript
代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
pair<int,int> a[N];
void solve(){
int n;
cin >> n;
for(int i = 0; i < n; i ++){
int x;
cin >> x;
a[i] = {
x, i + 1};
}
sort(a,a + n);
int cnt = 0;
int flag = a[0].first;
int ans[10];
ans[cnt] = a[0].second;
for(int i = 1; i < n; i ++){
if(a[i].first != flag){
flag = a[i].first;
ans[++cnt] = a[i].second;
if(cnt == 2) break;
}
}
if(cnt == 2){
for(int i = 0; i <= cnt ; i ++) cout << ans[i] <<" ";
}
else cout << -1 << " " << -1 <<" " << -1;
}
int main(){
solve();
return 0;
}
4501. 收集卡牌
原题链接
思想
vector<int> stStores the number of numbers that can currently be formed into a set,当st.size() == nInstructions can form a setvis[i]标记i是否在st中,numStores the number of uncompleted sets so far and their quantities- If the read number does not exist
st中,then add it and mark it - 每次加入
st对其进行判断:- 若
st.size() == nDescription is complete - 用
string sWhether the mark is complete,在st.size() == n时进行标记 - 将
st和vis清空,遍历numAdd uncompleted numbersst并标记
- 若
- 输出
s即为答案
代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n, m;
map<int,int> num;
bool vis[N];
void solve(){
cin >> n >> m;
string s(m,'0');
vector<int> st;
for(int i = 0; i < m; i ++){
int x;
cin >> x;
num[x]++;
if(!vis[x]){
vis[x] = 1;
num[x] --;
st.push_back(x);
if(st.size() == n){
st.clear();
s[i] = '1';
for(int i = 1; i <= n; i ++) vis[i] = 0;
for(auto &j : num){
if(j.second > 0){
j.second --;
st.push_back(j.first);
vis[j.first] = 1;
}
}
}
}
}
cout << s << endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
AcWing 4502. 集合操作
原题链接
思想
- m a x ( s ) − m e a n ( s ) max(s)−mean(s) max(s)−mean(s)的最大可能值,取决于 m e a n ( s ) mean(s) mean(s)最小z值
- It can be seen from the question that the sequence is monotonically increasing
- 则 m e a n ( s ) mean(s) mean(s)It must be a continuous number from the front+该最大值
- The added number is compared to the average
- If the newly added number is smaller than the average,Then the average value of the current state subset elements must decrease
- 如果相等,平均值不变
- If the newly added number is larger than the average,The average will increase
代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int idx, cnt = 1;
double a[N],s[N];
double check(int u){
return a[idx] - (s[u-1]+a[idx])/u;
}
void solve(){
int _;
cin >> _;
while (_ --){
int op;
cin >> op;
if(op == 1){
cin>>a[++ idx];
s[idx]=s[idx - 1]+a[idx];
}
else{
while(cnt + 1 <= idx && check(cnt + 1) > check(cnt)) ++cnt ;
printf("%.6lf\n", check(cnt));
}
}
}
int main(){
solve();
return 0;
}
边栏推荐
- Centos 7.9 install PostgreSQL14.4 steps
- 蓝牙mesh系统开发三 Ble Mesh 配网器 Provisioner
- 打印任务排序 js od华为
- Are you still working hard on the limit of MySQL paging?
- uniapp使用第三方字体
- Multiplication, DFS order
- 观察者(observer)模式(一)
- 【Map与Set】之LeetCode&牛客练习
- Ticmp - 更快的让应用从 MySQL 迁移到 TiDB
- C language _ structure pointer array function voting system
猜你喜欢

TiCDC 架构和数据同步链路解析

最高月薪20K?平均薪资近万...在华为子公司工作是什么体验?

leetcode-1161:最大层内元素和

《云原生的本手、妙手和俗手》——2022全国新高考I卷作文

"Cloud native's master, master and vulgar skills" - 2022 National New College Entrance Examination Volume I Composition

Installation problem corresponding to tensorflow and GPU version

prometheus 监控概述

蓝牙mesh系统开发二 mesh节点开发

"Real" emotions dictionary based on the text sentiment analysis and LDA theme analysis

Word/Excel 固定表格大小,填写内容时,表格不随单元格内容变化
随机推荐
使用docker安装mysql
验证 XML 文档
leetcode-952:按公因数计算最大组件大小
如何在 go 程序中暴露 Prometheus 指标
蓝牙mesh系统开发三 Ble Mesh 配网器 Provisioner
TiDB 在多点数字化零售场景下的应用
爬虫文本数据清洗
RTL8720DN开发笔记一 环境搭建与mqtt实例
Bert usage and word prediction based on Keras_bert model
Crawler text data cleaning
MySQL的分页你还在使劲的limit?
C语言小程序 -- 常见经典练习题
pycharm重命名后无法运行(报错: can‘t open file......No such file or directory)
Shell 脚本循环遍历日志文件中的值进行求和并计算平均值,最大值和最小值
手把手教你配置Jenkins自动化邮件通知
华为od 转骰子 js
内网渗透——提权
《实战》基于电商领域的词性提取及其决策树模型建模
case语句的综合结果,你究竟会了吗?【Verilog高级教程】
仿牛客网项目总结