当前位置:网站首页>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;
}
边栏推荐
- export default 导出的对象,不能解构问题,和module.exports的区别
- [leetcode] number of maximum consecutive ones
- Accelerator systems initiative is an independent non-profit organization
- 2022拼多多详情/拼多多商品详情/拼多多sku详情
- AIX存储管理之卷组属性的查看和修改(二)
- JS -- image to base code, base to file object
- Kuberntes cloud native combat high availability deployment architecture
- LeetCode 0241. Design priority for arithmetic expressions - DFS
- You probably haven't noticed the very important testing strategy in your work
- Synthetic watermelon game wechat applet source code / wechat game applet source code
猜你喜欢
How to reflect and solve the problem of bird flight? Why are planes afraid of birds?
Collection: comprehensive summary of storage knowledge
You probably haven't noticed the very important testing strategy in your work
Creation of volume group for AIX storage management (I)
King combat power query renamed toolbox applet source code - with traffic main incentive advertisement
工作中非常重要的测试策略,你大概没注意过吧
2022 low voltage electrician examination questions and answers
Evolution of Himalayan self-developed gateway architecture
JS -- image to base code, base to file object
创业团队如何落地敏捷测试,提升质量效能?丨声网开发者创业讲堂 Vol.03
随机推荐
How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03
Global and Chinese market of avionics systems 2022-2028: Research Report on technology, participants, trends, market size and share
Bilstm CRF code implementation
[wechat authorized login] the small program developed by uniapp realizes the function of obtaining wechat authorized login
Global and Chinese markets for supply chain strategy and operation consulting 2022-2028: Research Report on technology, participants, trends, market size and share
How can programmers better plan their career development?
什么是商业养老保险?商业养老保险安全靠谱吗?
Cookie, session, tooken
创业团队如何落地敏捷测试,提升质量效能?丨声网开发者创业讲堂 Vol.03
Leetcode skimming: stack and queue 06 (top k high-frequency elements)
XMIND mind map
Which securities company is safer to open a stock account
JMeter做接口测试,如何提取登录Cookie
2022拼多多详情/拼多多商品详情/拼多多sku详情
Node - generate wechat permission verification configuration
Node——生成微信权限验证配置
To meet the needs of consumers in technological upgrading, Angel water purifier's competitive way of "value war"
Zak's latest "neural information transmission", with slides and videos
股票开户哪个证券公司比较安全
【CTF】bjdctf_2020_babystack2