CodeForces 651B
生活随笔
收集整理的這篇文章主要介紹了
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 }?
轉載于:https://www.cnblogs.com/xingkongyihao/p/7112702.html
總結
以上是生活随笔為你收集整理的CodeForces 651B的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 制作系统盘,重装新系统。
- 下一篇: 地图上显示div点位