Procházet zdrojové kódy

Löst några saker.

Jonatan Gezelius před 6 roky
rodič
revize
d60c22aea6
3 změnil soubory, kde provedl 312 přidání a 0 odebrání
  1. 180 0
      p10205/p10205.cpp
  2. 25 0
      p10469/p10469.cpp
  3. 107 0
      p11968/p11968.cpp

+ 180 - 0
p10205/p10205.cpp

@@ -0,0 +1,180 @@
+#include <algorithm>
+#include <array>
+#include <iostream>
+#include <map>
+#include <utility>
+#include <vector>
+#include <iomanip>
+#include <sstream>
+#include <climits>
+#include <queue>
+#include <list>
+#include <map>
+#include <string>
+
+using namespace std;
+
+typedef unsigned int nat;
+
+class Card;
+class Deck;
+ostream &operator <<(ostream &s, Card const &c);
+ostream &operator <<(ostream &s, Deck const &d);
+
+enum Suit
+{
+    CLUBS,
+    DIAMONDS,
+    HEARTS,
+    SPADES
+};
+
+map<Suit, string> suit_name =  {{CLUBS, "Clubs"},
+                                {DIAMONDS, "Diamonds"},
+                                {HEARTS, "Hearts"},
+                                {SPADES, "Spades"}};
+
+map<nat, string> value_names = {{11, "Jack"},
+                                {12, "Queen"},
+                                {13, "King"},
+                                {14, "Ace"}};
+
+class Card
+{
+public:
+    Card(nat value, Suit suit) : value{value}, suit{suit} {}
+
+private:
+    nat value;
+    Suit suit;
+
+    friend ostream &operator <<(ostream &s, Card const &c);
+};
+
+class Deck
+{
+public:
+    Deck()
+    {
+        for(auto s : suit_name)
+        {
+            for(nat v = 2; v < 15; ++v)
+            {
+                cards.push_back( Card{v, s.first} );
+            }
+        }
+    }
+
+
+    void add_shuffle_method(vector<nat> const &method) { shuffle_methods.push_back( vector<nat>(method)); }
+
+    void shuffle(nat method)
+    {
+        vector<Card> new_order;
+        for(nat i : shuffle_methods[method-1])
+        {
+            new_order.push_back(cards[i-1]);
+        }
+
+        cards.swap(new_order);
+    }
+
+private:
+    vector<Card> cards;
+
+    vector<vector<nat>> shuffle_methods;
+
+    friend ostream &operator <<(ostream &s, Deck const &d);
+};
+
+
+
+ostream &operator <<(ostream &s, Card const &c)
+{
+    if(c.value < 11)
+    {
+        cout << c.value;
+    }
+    else
+    {
+        cout << value_names.find(c.value)->second;
+    }
+
+    cout << " of " << suit_name.find(c.suit)->second;
+    return s;
+}
+
+ostream &operator <<(ostream &s, Deck const &d)
+{
+    for(auto c : d.cards)
+    {
+        cout << c << endl;
+    }
+    return s;
+}
+
+
+int main()
+{
+    nat num_tests;
+
+    cin >> num_tests;
+
+    for(nat test = 0; test < num_tests; ++test)
+    {
+        nat num_shuffle_methods;
+        cin >> num_shuffle_methods;
+
+        Deck d;
+
+        for(nat met = 0; met < num_shuffle_methods; ++met)
+        {
+            vector<nat> method(52);
+
+            for(nat m = 0; m < 52; ++m)
+            {
+                cin >> method[m];
+            }
+
+            d.add_shuffle_method(method);
+        }
+
+        string str;
+        cin.ignore(1);
+        getline(cin, str);
+        while(!str.empty())
+        {
+            d.shuffle(stoul(str));
+            getline(cin, str);
+        }
+
+        cout << d;
+
+        if(test != (num_tests-1))
+        {
+            cout << endl;
+        }
+
+    }
+
+
+    return 0;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 25 - 0
p10469/p10469.cpp

@@ -0,0 +1,25 @@
+#include <algorithm>
+#include <array>
+#include <iostream>
+#include <map>
+#include <utility>
+#include <vector>
+#include <iomanip>
+#include <sstream>
+#include <climits>
+#include <queue>
+#include <list>
+
+using namespace std;
+
+int main()
+{
+    unsigned int a, b;
+
+    while(cin >> a >> b)
+    {
+        cout << (a^b) << endl;
+    }
+
+    return 0;
+}

+ 107 - 0
p11968/p11968.cpp

@@ -0,0 +1,107 @@
+#include <algorithm>
+#include <array>
+#include <iostream>
+#include <map>
+#include <utility>
+#include <vector>
+#include <iomanip>
+#include <sstream>
+#include <climits>
+#include <queue>
+#include <list>
+#include <cmath>
+
+using namespace std;
+
+typedef long long int nat;
+
+int main()
+{
+    nat num_tests, num_items, num_cakes, num_drinks;
+
+    cin >> num_tests;
+
+    for(nat test = 0; test < num_tests; ++test)
+    {
+        cin >> num_items >> num_cakes >> num_drinks;
+
+        nat sum_prices = 0;
+        vector<nat> cake_price(num_cakes);
+        vector<nat> drink_price(num_drinks);
+
+        for(nat i = 0; i < num_items; ++i)
+        {
+            nat price;
+            cin >> price;
+            sum_prices += price;
+            if(i < num_cakes)
+            {
+                cake_price[i] = price;
+            }
+            else if(i < num_cakes+num_drinks)
+            {
+                drink_price[i-num_cakes] = price;
+            }
+        }
+
+//        for(auto i : cake_price)
+//        {
+//            cout << "Cake price: " << i << endl;
+//        }
+//
+//        for(auto i : drink_price)
+//        {
+//            cout << "Drink price: " << i << endl;
+//        }
+
+        const unsigned int FIXED_PRECISION = 3;
+        double avg = (double)sum_prices / num_items;
+        long long int avg_fixed_point = round(avg*(1<<FIXED_PRECISION));
+
+//        cout << "Average: " << avg << endl;
+//        cout << "Average fixed: " << (avg_fixed_point) << endl;
+
+        pair<nat, nat> cake(0,LLONG_MAX), drink(0,LLONG_MAX);
+
+
+        for(nat i = 0; i < num_cakes+num_drinks; ++i)
+        {
+            if(i < num_cakes)
+            {
+                //cout << abs((cake_price[i]<<FIXED_PRECISION)-avg_fixed_point) << " < " << abs(cake.second-avg_fixed_point) << " && " << (cake_price[i]<<FIXED_PRECISION) << " < " << cake.second << endl;
+                if(abs((cake_price[i]<<FIXED_PRECISION)-avg_fixed_point) < abs(cake.second-avg_fixed_point))
+                {
+                    // Found closer cake!
+                    cake.first = i;
+                    cake.second = (cake_price[i]<<FIXED_PRECISION);
+                }
+                else if(abs((cake_price[i]<<FIXED_PRECISION)-avg_fixed_point) == abs(cake.second-avg_fixed_point) && (cake_price[i]<<FIXED_PRECISION) < cake.second)
+                {
+                    // Found cheaper cake!
+                    cake.first = i;
+                    cake.second = (cake_price[i]<<FIXED_PRECISION);
+                }
+            }
+            else
+            {
+                //cout << "i: " << i << endl << abs((drink_price[i-num_cakes]<<FIXED_PRECISION)-avg_fixed_point) << " < " << abs(drink.second-avg_fixed_point) << " && " << (drink_price[i-num_cakes]<<FIXED_PRECISION) << " < " << drink.second << endl;
+                if(abs((drink_price[i-num_cakes]<<FIXED_PRECISION)-avg_fixed_point) < abs(drink.second-avg_fixed_point))
+                {
+                    // Found closer drink!
+                    drink.first = i-num_cakes;
+                    drink.second = (drink_price[i-num_cakes]<<FIXED_PRECISION);
+                }
+                else if(abs((drink_price[i-num_cakes]<<FIXED_PRECISION)-avg_fixed_point) == abs(drink.second-avg_fixed_point) && (drink_price[i-num_cakes]<<FIXED_PRECISION) < drink.second)
+                {
+                    // Found cheaper drink!
+                    drink.first = i-num_cakes;
+                    drink.second = (drink_price[i-num_cakes]<<FIXED_PRECISION);
+                }
+            }
+        }
+        cout << "Case #" << test+1 << ": " << (cake.second>>FIXED_PRECISION) << " " << (drink.second>>FIXED_PRECISION) << endl;
+
+    }
+
+    return 0;
+}