zoukankan      html  css  js  c++  java
  • [Codeforces673C]Bear and Colors(枚举,暴力)

    题目链接:http://codeforces.com/contest/673/problem/C

    题意:给一串数,不同大小的区间内出现次数最多的那个数在计数的时候会+1,问所有区间都这样计一次数,所有的数字的计数结果。如果有数字出现次数相同多,取最小的那个。

    数据<=5000,那就暴力枚举每一个区间,每次维护当前出现最多次数和当前需要计数的那个数,每次更新一个值,那最大值就是这个值或者是之前存好的。每次判断就可以了,注意相同的时候取最小的那个数。

      1 /*
      2 ━━━━━┒ギリギリ♂ eye!
      3 ┓┏┓┏┓┃キリキリ♂ mind!
      4 ┛┗┛┗┛┃\○/
      5 ┓┏┓┏┓┃ /
      6 ┛┗┛┗┛┃ノ)
      7 ┓┏┓┏┓┃
      8 ┛┗┛┗┛┃
      9 ┓┏┓┏┓┃
     10 ┛┗┛┗┛┃
     11 ┓┏┓┏┓┃
     12 ┛┗┛┗┛┃
     13 ┓┏┓┏┓┃
     14 ┃┃┃┃┃┃
     15 ┻┻┻┻┻┻
     16 */
     17 #include <algorithm>
     18 #include <iostream>
     19 #include <iomanip>
     20 #include <cstring>
     21 #include <climits>
     22 #include <complex>
     23 #include <fstream>
     24 #include <cassert>
     25 #include <cstdio>
     26 #include <bitset>
     27 #include <vector>
     28 #include <deque>
     29 #include <queue>
     30 #include <stack>
     31 #include <ctime>
     32 #include <set>
     33 #include <map>
     34 #include <cmath>
     35 using namespace std;
     36 #define fr first
     37 #define sc second
     38 #define cl clear
     39 #define BUG puts("here!!!")
     40 #define W(a) while(a--)
     41 #define pb(a) push_back(a)
     42 #define Rlf(a) scanf("%llf", &a);
     43 #define Rint(a) scanf("%d", &a)
     44 #define Rll(a) scanf("%I64d", &a)
     45 #define Rs(a) scanf("%s", a)
     46 #define Cin(a) cin >> a
     47 #define FRead() freopen("in", "r", stdin)
     48 #define FWrite() freopen("out", "w", stdout)
     49 #define Rep(i, len) for(int i = 0; i < (len); i++)
     50 #define For(i, a, len) for(int i = (a); i < (len); i++)
     51 #define Cls(a) memset((a), 0, sizeof(a))
     52 #define Clr(a, x) memset((a), (x), sizeof(a))
     53 #define Full(a) memset((a), 0x7f7f, sizeof(a))
     54 #define lrt rt << 1
     55 #define rrt rt << 1 | 1
     56 #define pi 3.14159265359
     57 #define RT return
     58 #define lowbit(x) x & (-x)
     59 #define onenum(x) __builtin_popcount(x)
     60 typedef long long LL;
     61 typedef long double LD;
     62 typedef unsigned long long ULL;
     63 typedef pair<int, int> pii;
     64 typedef pair<string, int> psi;
     65 typedef map<string, int> msi;
     66 typedef vector<int> vi;
     67 typedef vector<LL> vl;
     68 typedef vector<vl> vvl;
     69 typedef vector<bool> vb;
     70 
     71 const int maxn = 5050;
     72 int n;
     73 int t[maxn];
     74 int vis[maxn];
     75 int cnt[maxn];
     76 
     77 int main() {
     78     // FRead();
     79     while(~Rint(n)) {
     80         Cls(vis); Cls(cnt);
     81         For(i, 1, n+1) Rint(t[i]);
     82         For(i, 1, n+1) {
     83             int curmax = 0, pos; Cls(vis);
     84             curmax = ++vis[t[i]];
     85             pos = t[i];
     86             cnt[pos]++;
     87             For(j, i+1, n+1) {
     88                 vis[t[j]]++;
     89                 if(curmax < vis[t[j]]) {
     90                     curmax = vis[t[j]];
     91                     pos = t[j];
     92                 }
     93                 else if(curmax == vis[t[j]]) pos = min(pos, t[j]);
     94                 cnt[pos]++;
     95             }
     96         }
     97         For(i, 1, n+1) printf("%d ", cnt[i]);
     98         printf("
    ");
     99     }
    100     RT 0;
    101 }
  • 相关阅读:
    局域网内其他主机如何访问运行在宿主机的虚拟机中的Django项目(转)
    python3脚本获取本机公网ip
    django之允许外部机器访问
    Mysql命令drop database:删除数据库
    CentOS和Windows下配置MySQL远程访问的教程
    Windows 下 MySql 5.7.20安装及data和my.ini文件的配置(转)
    远程登陆linux连接mysql root账号报错:2003-can't connect to MYSQL serve(转)
    Mysql创建用户并授权以及开启远程访问
    Android 之 自定义标签 和 自定义组件
    再探java基础——零碎基础知识整理
  • 原文地址:https://www.cnblogs.com/kirai/p/5551014.html
Copyright © 2011-2022 走看看