zoukankan      html  css  js  c++  java
  • 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

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

  • 相关阅读:
    100篇论文
    Tengine vs openresty
    Dottrace跟踪代码执行时间
    Linux Server
    Linux+Apache+Mysql+Php
    linux+nginx+mysql+php
    tshark命令行的使用(转)
    tcpdump VS tshark用法(转)
    Lua语言在Wireshark中使用(转)
    doc-remote-debugging.html
  • 原文地址:https://www.cnblogs.com/FriskyPuppy/p/7340669.html
Copyright © 2011-2022 走看看