当前位置:网站首页>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;
}
边栏推荐
- 【微信授权登录】uniapp开发小程序,实现获取微信授权登录功能
- Global and Chinese market of avionics systems 2022-2028: Research Report on technology, participants, trends, market size and share
- How to reflect and solve the problem of bird flight? Why are planes afraid of birds?
- Advanced skills of testers: a guide to the application of unit test reports
- [eight sorts ①] insert sort (direct insert sort, Hill sort)
- Global and Chinese markets for the application of artificial intelligence in security, public security and national security 2022-2028: Research Report on technology, participants, trends, market size
- Global and Chinese markets for freight and logistics 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese market of wireless charging magnetic discs 2022-2028: Research Report on technology, participants, trends, market size and share
- What skills does an excellent software tester need to master?
- [eight sorting ③] quick sorting (dynamic graph deduction Hoare method, digging method, front and back pointer method)
猜你喜欢
"C zero foundation introduction hundred knowledge hundred examples" (73) anonymous function -- lambda expression
Schrodinger's Japanese learning applet source code
测试员8年工资变动,令网友羡慕不已:你一个月顶我一年工资
工作中非常重要的测试策略,你大概没注意过吧
Slf4j print abnormal stack information
Review notes of compilation principles
2022拼多多详情/拼多多商品详情/拼多多sku详情
Otaku wallpaper Daquan wechat applet source code - with dynamic wallpaper to support a variety of traffic owners
What does open loop and closed loop mean?
Zak's latest "neural information transmission", with slides and videos
随机推荐
Some understandings of graph convolution neural network r-gcn considering relations and some explanations of DGL official code
From 20s to 500ms, I used these three methods
How to determine whether the current script is in the node environment or the browser environment?
Global and Chinese market of wireless chipsets 2022-2028: Research Report on technology, participants, trends, market size and share
Excel PivotTable
创业团队如何落地敏捷测试,提升质量效能?丨声网开发者创业讲堂 Vol.03
UDS bootloader of s32kxxx bootloader
[CTF] bjdctf 2020 Bar _ Bacystack2
The 8-year salary change of testers makes netizens envy it: you pay me one year's salary per month
Zak's latest "neural information transmission", with slides and videos
【八大排序①】插入排序(直接插入排序、希尔排序)
Leetcode skimming: stack and queue 02 (realizing stack with queue)
【八大排序④】归并排序、不基于比较的排序(计数排序、基数排序、桶排序)
JS common library CDN recommendation
Leetcode question brushing: stack and queue 07 (maximum value of sliding window)
Deb file installation
King combat power query renamed toolbox applet source code - with traffic main incentive advertisement
[conference resources] the Third International Conference on Automation Science and Engineering in 2022 (jcase 2022)
2022 high altitude installation, maintenance and removal of test question simulation test platform operation
[eight sorts ①] insert sort (direct insert sort, Hill sort)