zoukankan      html  css  js  c++  java
  • [Codeforces137B]Permutation(贪心?思路?,水题)

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

    给n个数字,要求修改成1~n的全排列数中的一个,修改的次数尽可能少,问最少需要修改几个数。

    记下数组里出现的数字都是什么,之后处理的时候,遇到出现大于1次的说明要修改。有一个trick那就是ai<=5000,也就是会超出n,所以要特别注意一下,在这里WA了一次。

     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 Fuint(a) memset((a), 0x7f7f, 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 onenum(x) __builtin_popcount(x)
    59 typedef long long LL;
    60 typedef long double LD;
    61 typedef unsigned long long Uint;
    62 typedef pair<int, int> pii;
    63 typedef pair<string, int> psi;
    64 typedef map<string, int> msi;
    65 typedef vector<int> vi;
    66 typedef vector<int> vl;
    67 typedef vector<vl> vvl;
    68 typedef vector<bool> vb;
    69 
    70 const int maxn = 5050;
    71 int n;
    72 int a[maxn];
    73 int vis[maxn];
    74 
    75 int main() {
    76     // FRead();
    77     while(~Rint(n)) {
    78         Cls(vis);
    79         For(i, 1, n+1) {
    80             Rint(a[i]);
    81             vis[a[i]]++;
    82         }
    83         int ret = 0;
    84         For(i, 1, n+1) {
    85             if(a[i] <= n) {
    86                 if(vis[a[i]] > 1) {
    87                     vis[a[i]]--;
    88                     ret++;
    89                 }
    90             }
    91             else {
    92                 vis[a[i]]--;
    93                 ret++;
    94             }
    95         }
    96         printf("%d
    ", ret);
    97     }
    98     RT 0;
    99 }
  • 相关阅读:
    用Python完成一个汇率转换器
    鸿蒙如何用JS开发智能手表App
    鸿蒙如何用JS开发智能手表App
    SAP Spartacus SplitViewComponent Migration 的一个具体例子
    SAP Spartacus B2B 页面 Popover Component 的条件显示逻辑
    SAP Spartacus 升级时关于 schematics 的更新
    SAP Spartacus B2B 页面 Disable 按钮的显示原理
    SAP Spartacus B2B 页面 Disable Confirmation 对话框的显示原理
    通过 Feature Level 动态控制 SAP Spartacus 的页面显示
    SAP Commerce Cloud Build Manifest Components
  • 原文地址:https://www.cnblogs.com/kirai/p/5547190.html
Copyright © 2011-2022 走看看