zoukankan      html  css  js  c++  java
  • [CF430B] Balls Game(暴力,模拟)

    题目链接:http://codeforces.com/contest/430/problem/B

    题意:祖玛,消除游戏。给你一个颜色,问你往现有的串里插,最多消除多少个。

    枚举所有插入点,while(1)循环模拟消除就行了。这题眼熟

      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 Rint(a) scanf("%d", &a)
     43 #define Rll(a) scanf("%I64d", &a)
     44 #define Rs(a) scanf("%s", a)
     45 #define Cin(a) cin >> a
     46 #define FRead() freopen("in", "r", stdin)
     47 #define FWrite() freopen("out", "w", stdout)
     48 #define Rep(i, len) for(int i = 0; i < (len); i++)
     49 #define For(i, a, len) for(int i = (a); i < (len); i++)
     50 #define Cls(a) memset((a), 0, sizeof(a))
     51 #define Clr(a, x) memset((a), (x), sizeof(a))
     52 #define Full(a) memset((a), 0x7f7f7f, sizeof(a))
     53 #define lrt rt << 1
     54 #define rrt rt << 1 | 1
     55 #define pi 3.14159265359
     56 #define RT return
     57 #define lowbit(x) x & (-x)
     58 #define onecnt(x) __builtin_popcount(x)
     59 typedef long long LL;
     60 typedef long double LD;
     61 typedef unsigned long long ULL;
     62 typedef pair<int, int> pii;
     63 typedef pair<string, int> psi;
     64 typedef pair<LL, LL> pll;
     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 = 110;
     72 int n, k, x;
     73 int c[maxn];
     74 
     75 int get(int pos) {
     76     vector<int> p;
     77     For(i, 0, n+2) {
     78         if(i >= 1 && i <= n) p.push_back(c[i]);
     79         if(pos == i) p.push_back(x);
     80     }
     81     bool flag;
     82     vector<int> tmp;
     83     bool vis[maxn];
     84     while(1) {
     85         flag = 0;
     86         Cls(vis); tmp.clear();
     87         if(p.size() == 0) break;
     88         For(i, 1, p.size()-1) {
     89             if(p[i] == p[i-1] && p[i] == p[i+1]) {
     90                 vis[i-1] = vis[i] = vis[i+1] = 1;
     91                 flag = 1;
     92             }
     93         }
     94         Rep(i, p.size()) {
     95             if(!vis[i]) {
     96                 tmp.push_back(p[i]);
     97             }
     98         }
     99         p.clear();
    100         Rep(i, tmp.size()) {
    101             p.push_back(tmp[i]);
    102         }
    103         if(flag == 0) break;
    104     }
    105     return n - p.size();
    106 }
    107 
    108 int main() {
    109     // FRead();
    110     // FWrite();
    111     while(~scanf("%d%d%d",&n,&k,&x)) {
    112         For(i, 1, n+1) Rint(c[i]);
    113         int ret = 0;
    114         For(i, 0, n+2) {
    115             ret = max(ret, get(i));
    116         }
    117         printf("%d
    ", ret);
    118     }
    119     RT 0;
    120 }
  • 相关阅读:
    多态与封装
    [Vue] karme/jasmine/webpack/vue搭建测试环境
    [Vue] vue中setInterval的问题
    hosts文件的作用
    [Nodejs] node写个helloworld
    [JavaScript] Cookie,localStorage,sessionStorage概述
    [Vue] vuex进行组件间通讯
    常用工具网站(记事,图表等)
    npm安装github包的方式
    常用的练习网站
  • 原文地址:https://www.cnblogs.com/kirai/p/5801316.html
Copyright © 2011-2022 走看看