2017 Multi-University Training Contest - Team 6 1003 Inversion

27 篇文章 0 订阅

Inversion

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


Problem Description
Give an array A, the index starts from 1.
Now we want to know Bi=maxijAj , 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
 

题目描述

首先先普及一下’a|b’代表a是b的因子,即b%a=0,’a∤b’也就是b%a!=0
给定一个序列,求i从2开始不是i倍数的序列中的最大值,依次输出

解题思路

暴力大法好,首先用一个结构体数组保存值与下标。然后对值进行从大到小的排序,然后依此对每个下标i找出对i取余不为零的输出


/* ***********************************************
┆  ┏┓   ┏┓ ┆
┆┏┛┻━━━┛┻┓ ┆
┆┃       ┃ ┆
┆┃   ━   ┃ ┆
┆┃ ┳┛ ┗┳ ┃ ┆
┆┃       ┃ ┆
┆┃   ┻   ┃ ┆
┆┗━┓ 马 ┏━┛ ┆
┆  ┃ 勒 ┃  ┆      
┆  ┃ 戈 ┗━━━┓ ┆
┆  ┃ 壁     ┣┓┆
┆  ┃ 的草泥马  ┏┛┆
┆  ┗┓┓┏━┳┓┏┛ ┆
┆   ┃┫┫ ┃┫┫ ┆
┆   ┗┻┛ ┗┻┛ ┆
************************************************ */
#include <iostream>
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <bitset>
#include <string>
#include <vector>
#include <iomanip>
#include <cstring>
#include <algorithm>
#include <functional>
#define inf 0x3f3f3f3f
#define debug(x) cout<<"---"<<x<<"---"<<endl
typedef long long ll;
using namespace std;

struct node
{
    int pos;
    int val;
} a[100500];
bool cmp(node x, node y)
{
    return x.val > y.val;
}
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        for (int i = 1; i <= n; i++)
        {
            a[i].pos = i;
            cin >> a[i].val;
        }
        sort(a + 1, a + n + 1, cmp);
        for (int k = 2; k <= n; k++)
        {
            for (int i = 1; i <= n; i++)
            {
                if (a[i].pos % k)
                {
                    if (k == n)
                    {
                        cout << a[i].val << endl;
                    }
                    else
                    {
                        cout << a[i].val << " ";
                    }
                    break;
                }
            }
        }
    }
    return 0;
}
/************************************************
┆  ┏┓   ┏┓ ┆
┆┏┛┻━━━┛┻┓ ┆
┆┃       ┃ ┆
┆┃   ━   ┃ ┆
┆┃ ┳┛ ┗┳ ┃ ┆
┆┃       ┃ ┆
┆┃   ┻   ┃ ┆
┆┗━┓    ┏━┛ ┆
┆  ┃    ┃  ┆      
┆  ┃    ┗━━━┓ ┆
┆  ┃  AC代马   ┣┓┆
┆  ┃           ┏┛┆
┆  ┗┓┓┏━┳┓┏┛ ┆
┆   ┃┫┫ ┃┫┫ ┆
┆   ┗┻┛ ┗┻┛ ┆
************************************************ */


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值