zoukankan      html  css  js  c++  java
  • hdu 1394 水题

    本来以为是求逆序数,要用归并排序,而且还得用线段树动态维护神马的,睁大眼睛一看,我滴妈呀,n才5000,直接暴力过了~~

    /*
    * hdu1394/linux.cpp
    * Created on: 2011-9-6
    * Author : ben
    */
    #include
    <cstdio>
    #include
    <cstdlib>
    #include
    <cstring>
    #include
    <cmath>
    #include
    <algorithm>
    using namespace std;

    const int MAXN = 5010;
    int num[MAXN], reserve[MAXN];

    void work();
    int main() {
    #ifndef ONLINE_JUDGE
    freopen(
    "data.in", "r", stdin);
    #endif
    work();
    return 0;
    }

    void work() {
    int N, totalres, temp;
    while (scanf("%d\n", &N) == 1) {
    for (int i = 0; i < N; i++) {
    scanf(
    "%d", &num[i]);
    }
    totalres
    = 0;
    memset(reserve,
    0, sizeof(reserve));
    for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
    if (num[i] > num[j]) {
    reserve[i]
    ++;
    }
    }
    totalres
    += reserve[i];
    }
    temp
    = totalres;
    for (int i = 0; i < N; i++) {
    temp
    += N - 2 * reserve[i] - 1;
    if (temp < totalres) {
    totalres
    = temp;
    }
    for (int j = i + 1; j < N; j++) {
    if (num[j] > num[i]) {
    reserve[j]
    ++;
    }
    }
    }
    printf(
    "%d\n", totalres);
    }
    }
  • 相关阅读:
    函数的节流和函数的防抖
    微信小程序开发
    当后端人员未提供接口,前端人员该怎么测试 --mock
    vue之写发表评论思路
    vue之头像管理思路
    numpy 索引切片迭代
    numpy 通用函数
    numpy 数组运算
    numpy 创建数组
    numpy 数据类型
  • 原文地址:https://www.cnblogs.com/moonbay/p/2169095.html
Copyright © 2011-2022 走看看