【待續】小米 OJ 編程比賽 04 月常規賽

3道題,2小時。

題目1

不一樣的排序https://code.mi.com/problem/list/view?id=128&cid=11
一般

我的題解

#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int yinzi(int x)
{
    int count = 0;
    int temp = (int)sqrt(x);
    for(int i = 1; i <= temp; i++)
    {
        if(x % i == 0)
            count++;
    }
    
    return count+1;
}

void sortA(int a[][2], int n)
{
	bool sorted  = false;
    while(!sorted)
    {
        sorted = true;
    	for(int i = 0; i < n-1; i++)
        {
        	if(a[i][1] > a[i+1][1])
            {
            	swap(a[i][1], a[i+1][1]);
                swap(a[i][0], a[i+1][0]);
                sorted = false;
            }
        }
        n--;
    }
}

int main()
{
    // please write your code here
    int k, n;
    cin >> k >> n;
    int a[n][2] = {0};
    for(int i = 0; i < n; i++)
        cin >> a[i][0];
    for(int i = 0; i < n; i++)
    {
    	a[i][1] = yinzi(a[i][0]);
    }
    sortA(a, n);
    cout << a[k-1][0] << endl;
    
    return 0;
}

結果:超時。

思路

題解

總結

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章