zoukankan      html  css  js  c++  java
  • hdu 6098 Inversion

    Inversion

    Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 339    Accepted Submission(s): 230

    Problem Description
    Give an array A, the index starts from 1.
    Now we want to know Bi=max {  A |  ij  }, i2.
     
    Input
    The first line of the input gives the number of test cases T; T test cases follow.
    Each case begins with one line with one integer n : the size of array A.
    Next one line contains n integers, separated by space, ith number is Ai.

    Limits
    T20
    2n100000
    1Ai1000000000
    n700000
    Output
    For each test case output one line contains n-1 integers, separated by space, ith number is Bi+1.
     
     
    Sample Input
    2
    4
    1 2 3 4
    4
    1 4 2 3
     
    Sample Output
    3 4 3
    2 4 4
    Source
     
    Recommend
    liuyiding   |   We have carefully selected several similar problems for you:  6107 6106 6105 6104 6103 
     

    题目大意:

    给你一个数组 a ,让你求出数组 b 。b[ i ] 表示 a 数组中下标不能被 i 整除的数里面的最大值。

    题解:

    把a数组开个结构体,存入值和标号,按值从大到小排序,然后从最大的开始询问起,如果a[i].id 此时的下标不能被b的下标 j 整除,则给 b[j] 赋值a[i].k

    #include <iostream>
    #include<cstdio>
    #include<algorithm>
    #include<queue>
    #include<map>
    #include<vector>
    #include<cmath>
    #include<cstring>
    #include<bits/stdc++.h>
    
    using namespace std;
    
     long long b[100005];
     int T,n;
    
    struct node
    {
        long long k;
        int id;
    }a[100005];
    bool cmp(node a,node b)
    {
        return a.k>b.k;
    }
    
    int main()
    {
        scanf("%d",&T);
        while(T--)
        {
            scanf("%d",&n);
            memset(b,0,sizeof(b));
            for(int i=1;i<=n;i++)
            {
                scanf("%lld",&a[i].k);
                a[i].id=i;
            }
            sort(a+1,a+n+1,cmp);
            int tmp=n-1;
            for(int i=1;i<=n && tmp>0;i++)
            {
                for(int j=2;j<=n && tmp>0;j++)
                {
                    if (b[j]==0 && a[i].id%j!=0)
                        b[j]=a[i].k,tmp--;
                }
            }
            for(int i=2;i<=n;i++)
            {
                if (i-2) printf(" ");
                printf("%d",b[i]);
            }
            printf("
    ");
        }
        return 0;
    }
  • 相关阅读:
    Spring@Profile注解
    day 32 子进程的开启 及其用法
    day 31 udp 协议SOCK_DGRAM
    day 30 客户端获取cmd 命令的步骤
    day 29 socket 理论
    day 29 socket 初级版
    有关 组合 继承
    day 27 多态 接口 类方法 静态方法 hashlib 摘要算法模块
    新式类和经典类的区别
    day 28 hasattr getattr serattr delattr 和带__内置__ 类的内置方法
  • 原文地址:https://www.cnblogs.com/stepping/p/7344215.html
Copyright © 2011-2022 走看看