Пожалуйста, подпишитесь на официальный канал Codeforces в Telegram по ссылке https://t.me/codeforces_official. ×

Блог пользователя ujjaldas223

Автор ujjaldas223, история, 7 лет назад, По-английски

Problem: Given an array which contains weights of given elements A = [W1, W2, .., Wn]. Unlimited sacks are available which has the limit to bear some weights say X.

It is always guaranteed that X >= Wi, 1 <= i <= n.

What is the minimum number of sacks need to fill all the elements in the array? Display the content of each sacks.

Test case 1:

X = 10, A = [5, 4, 2, 6, 7, 8, 3, 1]

Ans: Content of sacks: [8, 2], [7, 3], [6, 4], [5, 1]

Test case 2:

X = 15, A = [5, 1, 10, 9]

Ans: Content of sacks: [1, 5, 9], [10]

I have tried greedy method, which will pick elements from first to last and fill the sacks. But this solution is not optimal. Can you suggest any optimal solutions for the above problem?

Полный текст и комментарии »

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

Автор ujjaldas223, история, 9 лет назад, По-английски

I am using sets in c++. The below code is :

#include<bits/stdc++.h>
using namespace std;
int main(){
    set<int> s1({1, 2, 3}), s2({2, 3, 1});
    if(s1 == s2)
        cout << "Two sets are equal\n";
    else
        cout << "Two sets are different\n";
    return 0;
}

My question is — Given 2 sets both having n elements, when these 2 sets are compared using == operator, what is the time complexity for it?

Полный текст и комментарии »

  • Проголосовать: нравится
  • +5
  • Проголосовать: не нравится