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

痴心易碎 提交于 2019-12-23 02:16:10
[2016-03-08][651][[codeforces]][B][Beautiful Paintings]
  • 题目编号:CF 651 B
  • 题目大意:画展有n个画,每个画beauty值已知,客人每经过一个比之前一个画更美的,客人会变得beauty,重新安排画的顺序,求客人开心时间的最大值
  • 输入:n 和每个话的beauty
  • 输出:时间
  • 分析:
    • 如果beauty为a的画,数量为 k,那么beaty小于或者大于a的k个,总能安排让客人开心,所以,除了数量k最大的那个beauty之外,每个beauty总能找到一个能让个人开心的上一个或者下一个画,
    • 如  1 2 3 5 3 2 1 表示每个beauty的数量,数量5两边的数字,显然都能找到一个能让客人开心的上一个或者下一个
    • 计算时间:看5前面,每个beauty都能在后面找到一个另客人开心的画,所以时间为1 + 2 + 3 ,后面反过来同理 3 + 2 + 1 ,所以总共时间是 1 + 2 + 3 + 3 + 2 + 1
  • 方法:从上面分析可是,maxtime = n - maxk;




#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;
#define CLR(x,y) memset((x),(y),sizeof((x)))
#define FOR(x,y,z) for(int (x)=(y);(x)<(z);++(x))
#define FORD(x,y,z) for(int (x)=(y);(x)>=(z);--(x))
#define FOR2(x,y,z) int (x);for((x)=(y);(x)<(z);++(x))
#define FORD2(x,y,z) int (x);for((x)=(y);(x)>=(z);--(x))
int cnta[1000 + 10];
int main(){
        //freopen("in.txt","r",stdin);
        //freopen("out.txt","w",stdout);
        int n,x;CLR(cnta,0);
        scanf("%d",&n);
        FOR(i,0,n){
                scanf("%d",&x);
                ++cnta[x];
        }
        int maxk = 0;
        FOR(i,0,1009)   maxk = max(maxk,cnta[i]);
        printf("%d\n",n - maxk);
    return 0;
}  




易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!