zoukankan      html  css  js  c++  java
  • ZOJ4104 Sequence in the Pocket

    题意 给出n个数 每次将一个数移到第一位 问最少多少次能使这n个数递增

    思维题 开一个数组排序为其最终状态 然后从后往前遍历 如果不相同的话 就说明调换到第一个位置去过 之后的话就要考虑之前移动的数对其的影响 举个例子 移动了第四个数到首位 那么 原来的第二个数就变成了第三个数

    AC代码:

     1 #include<bits/stdc++.h>
     2 #define pi acos(-1)
     3 #define INF 0x3f3f3f3f
     4 typedef long long ll;
     5 typedef unsigned long long ull;
     6 using namespace std;
     7 
     8 namespace io {
     9     const int SIZE = 1e7 + 10;
    10     char inbuff[SIZE];
    11     char *l, *r;
    12     inline void init() {
    13         l = inbuff;
    14         r = inbuff + fread(inbuff, 1, SIZE, stdin);
    15     }
    16     inline char gc() {
    17         if (l == r) init();
    18         return (l != r) ? *(l++) : EOF;
    19     }
    20     void read(int &x) {
    21         x = 0; char ch = gc();
    22         while(!isdigit(ch)) ch = gc();
    23         while(isdigit(ch)) x = x * 10 + ch - '0', ch = gc();
    24     }
    25 } using io::read;
    26 
    27 bool cmp(const int &a, const int &b){
    28     return a > b;
    29 }
    30 
    31 int t, n;
    32 int a[100005], b[100005];
    33 
    34 int main(){
    35     ios::sync_with_stdio(false);
    36     cin>>t;
    37     while (t--){
    38         cin>>n;
    39         memset(a, 0, sizeof(a));
    40         memset(b, 0, sizeof(b));
    41         for (int i = 1; i <= n; i++){
    42             cin>>a[i];
    43             b[i] = a[i];
    44         }
    45         sort(b + 1, b + n + 1);
    46         int ans = 0;
    47         for (int i = n; i >= 1; i--)
    48             if (a[i] != b[i + ans])
    49                 ans++;
    50         cout<<ans<<endl;
    51     }
    52     return 0;
    53 }
  • 相关阅读:
    013.Kubernetes认证授权
    012.Kubernetes的configmap和secret配置
    011.Kubernetes使用共享存储持久化数据
    010.kubernets的调度系统之daemonset
    009.kubernets的调度系统之污点和容忍
    008.kubernets的调度系统之标签选择器
    007.kubernets的headless service配置和ingress的简单配置
    Meterpreter初探
    渗透第一课:尝试渗透
    Metasploit漏洞扫描
  • 原文地址:https://www.cnblogs.com/Misuchii/p/10983677.html
Copyright © 2011-2022 走看看