当前位置:网站首页>Cat Party (Easy Edition)
Cat Party (Easy Edition)
2022-07-02 00:56:00 【Learning KL & TK】
The meaning of the topic : Let you find the maximum length x,1 - x Between ( You can delete perhaps Don't delete ) A number , Give Way 1-x All numbers between are the same , Find the longest position .
Their thinking :
One :
1 The number of occurrences of each color is 1.
2 Only one color appears the most , And the number of occurrences is I.
3 The number of occurrences of a color is 1, Other colors appear the same number of times .
4 One color appears more times than any other color 1 Time
#include <iostream>
#include <stdio.h>
using namespace std;
const int N = 1e5 + 10;
int n, color, ans, mx, f[N], cnt[N];
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; i++){
scanf("%d", &color);
cnt[f[color]]--;
f[color]++;
cnt[f[color]]++;
mx = max(mx, f[color]);
bool ok = false;
if (cnt[1] == i)
ok = true;
else if (cnt[i] == 1)
ok = true;
else if (cnt[1] == 1 && cnt[mx] * mx == i - 1)
ok = true;
else if (cnt[mx - 1] * (mx - 1) == i - mx && cnt[mx] == 1)
ok = true;
if (ok)
ans = i;
}
printf("%d", ans);
return 0;
}Solution 2 :
This is a good feeling after reading the problem-solving ideas of other bloggers
Link to the original text :https://blog.csdn.net/Tc_To_Top/article/details/90179927
Their thinking
The main idea of the topic : Find a maximum number x, bring u[1]~u[x] Under the condition that a position must be deleted , The frequency of other numbers is the same
Topic analysis : set up u[i] The frequency of occurrence is a, frequency a stay 1~i The number of occurrences in is b, Subject requirements 1~i You must delete a position in , So if a*b=i-1 The current i feasible , There is also a case like example 1 , namely a*b=i, If at this time i+1<=n, Then bring it i+1 Also meet the requirements of the topic
#include"bits/stdc++.h"
#define ll long long
#define pi pair<int,int>
#define inf 0x3f3f3f3f
#define _for(i,a,b) for(int i=a;i<=b;i++)
#define for_(i,a,b) for(int i=a;i<b;i++)
#define _fr(i,a,b) for(int i=a;i>=b;i--)
#define fr_(i,a,b) for(int i=a;i>b;i--)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
const int N = 1e5+5;
const ll mod = 1e9+7;
const double lp=1.000000011;
map<char,int>mp;
int n,x;
int a[N],b[N];
void solve(){
cin >> n;
int ans = 1;
_for(i,1,n){
cin >> x;
a[x]++;
b[a[x]]++;
if(i != n && a[x] * b[a[x]] == i){
ans = i+1;
}else if(a[x] * b[a[x]] == i-1){
ans = i;
}
}
cout << ans << endl;
}
int main()
{
IOS;
solve();
return 0;
}边栏推荐
- LeetCode 0241.为运算表达式设计优先级 - DFS
- [JS download files through url]
- Comprehensive broadcast of global and Chinese markets 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese markets for power over Ethernet (POE) solutions 2022-2028: Research Report on technology, participants, trends, market size and share
- S32Kxxx bootloader之UDS bootloader
- [eight sorts ②] select sort (select sort, heap sort)
- 2023 Lexus ES products have been announced, which makes great progress this time
- [wechat authorized login] the small program developed by uniapp realizes the function of obtaining wechat authorized login
- gradle
- export default 导出的对象,不能解构问题,和module.exports的区别
猜你喜欢

Excel PivotTable

Leetcode skimming: stack and queue 04 (delete all adjacent duplicates in the string)

BPR (Bayesian personalized sorting)

Upgraded wechat tool applet source code for mobile phone detection - supports a variety of main traffic modes

创业团队如何落地敏捷测试,提升质量效能?丨声网开发者创业讲堂 Vol.03

Creating logical volumes and viewing and modifying attributes for AIX storage management

Excel search and reference function

Use es to realize epidemic map or take out order function (including code and data)
![[eight sorting ③] quick sorting (dynamic graph deduction Hoare method, digging method, front and back pointer method)](/img/c2/7ebc67e9b886e3baf3c98489bf9bce.png)
[eight sorting ③] quick sorting (dynamic graph deduction Hoare method, digging method, front and back pointer method)

Geek DIY open source solution sharing - digital amplitude frequency equalization power amplifier design (practical embedded electronic design works, comprehensive practice of software and hardware)
随机推荐
JMeter做接口测试,如何提取登录Cookie
Friends circle community program source code sharing
2022 pinduoduo details / pinduoduo product details / pinduoduo SKU details
excel查找与引用函数
【八大排序③】快速排序(动图演绎Hoare法、挖坑法、前后指针法)
449-原码、补码、反码
Powerful calendar wechat applet source code - support the main mode of doing more traffic
Kuberntes cloud native combat high availability deployment architecture
[eight sorts ①] insert sort (direct insert sort, Hill sort)
[CTF] bjdctf 2020 Bar _ Bacystack2
sso单点登录的实现。
Geek DIY open source solution sharing - digital amplitude frequency equalization power amplifier design (practical embedded electronic design works, comprehensive practice of software and hardware)
How to reflect and solve the problem of bird flight? Why are planes afraid of birds?
Bilstm CRF code implementation
Some understandings of graph convolution neural network r-gcn considering relations and some explanations of DGL official code
【八大排序④】归并排序、不基于比较的排序(计数排序、基数排序、桶排序)
Leetcode skimming: stack and queue 05 (inverse Polish expression evaluation)
[wechat authorized login] the small program developed by uniapp realizes the function of obtaining wechat authorized login
【微信授权登录】uniapp开发小程序,实现获取微信授权登录功能
Upgraded wechat tool applet source code for mobile phone detection - supports a variety of main traffic modes