CodeForces 651B

Posted starry

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeForces 651B相关的知识,希望对你有一定的参考价值。

CodeForces 651B

 

相邻后面的数比前面的数大,就加一,求最终的结果,比赛时做时就直接去模拟了,慢了许多,不过数不是很多就不要紧了。

下面是我的代码:

  

 1 #include <bits/stdc++.h>
 2 #define ll long long
 3 using namespace std;
 4 int a[1010],vis[1010];
 5 int main(){
 6     int n, num;
 7     cin >> n;
 8     for(int i = 0; i < n; i ++){
 9         cin >> a[i];
10     }
11     sort(a,a+n);
12     int ans = 0;
13     int cnt = 0;
14     while(true){
15         if(cnt == n)break;
16         int flag = 0,a1,a2;
17         for(int i = 0; i < n; i ++){
18             if(!vis[i] && !flag){
19                 a1 = a[i];
20                 flag = vis[i] = 1;
21                 cnt++;
22             }else if(!vis[i] && a1 < a[i] && flag){
23                 ans++;
24                 vis[i] = true;
25                 cnt++;
26                 a1 = a[i];
27             }
28         }
29     }
30     cout << ans << endl;
31     return 0;
32 }

 

 

其实这个只要求出出现次数最多的数,再让n去减下记行了。

1 #include <iostream>
2 using namespace std;
3 int t,i,a[1001],n,k;
4 main(){
5     cin>>n;
6     while(i++<n)
7     cin>>t,k=(++a[t]>k?a[t]:k);
8     cout<<n-k;
9 }

 

以上是关于CodeForces 651B的主要内容,如果未能解决你的问题,请参考以下文章

[2016-03-08][651][codeforces][B][Beautiful Paintings]

[Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3)][C. Playing Piano](代码片段

c_cpp Codeforces片段

Codeforces 86C Genetic engineering(AC自动机+DP)

CodeForces 1005D Polycarp and Div 3(思维贪心dp)

(Incomplete) Codeforces 394 (Div 2 only)