HDU 6098 Inversion 思维

  题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6098

  题目描述: 给出一个序列, 让你求序列中所有不能整除i的最大值并输出  i  属于 2 ~ n

  解题思路: 这道题我犯蠢了......我想的是找规律, 所有质数先求出来再单独抠倍数, 其实只要排序就好了.....

  代码: 

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <map>
#include <cstring>
#include <iterator>
#include <cmath>
#include <algorithm>
#include <stack>
#include <deque>

#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
using namespace std;
const int maxn = 1e5 + 100;
int a[maxn];
int pos[maxn];

int cmp( int i, int j ) {
    return a[i] > a[j];
}

int main() {
    int t;
    scanf( "%d", &t );
    while( t-- ) {
        int n;
        scanf( "%d", &n );
        for( int i = 1; i <= n; i++ ) {
            scanf( "%d", a+i );
            pos[i] = i;
        }
        sort( pos+1, pos+n+1, cmp );
        int flag = 1;
        for( int i = 2; i <= n; i++ ) {
            int j;
            for( j = 1; j <= n; j++ ) {
                if(pos[j] % i != 0) break;
            }
            if( flag ) {
                flag = 0;
                printf( "%d", a[pos[j]] );
            }
            else {
                printf( " %d", a[pos[j]] );
            }
        }
        printf( "
" );
    }
    return 0;
}
View Code

  思考: 遇到取最大第一反应应该是排序的啊....

原文地址:https://www.cnblogs.com/FriskyPuppy/p/7340669.html