Untitled
unknown
plain_text
14 days ago
3.8 kB
5
Indexable
Never
#include <unordered_map> #include <string> #include <vector> #include <algorithm> using namespace std; struct Product { int id, price; bool bought; Product(int id, int price) { this->id = id; this->price = price; this->bought = false; } } *products[30001]; int pId; unordered_map<string, vector<int>> tags; void init(int N) { pId = 0; tags.clear(); } vector<string> tmp; void addProduct(int mPrice, int tagNum, char tagName[][10]) { products[pId] = new Product(pId, mPrice); tmp.clear(); for (int i = 0; i < tagNum; i++) tmp.push_back(tagName[i]); sort(tmp.begin(), tmp.end()); for (int i = 0; i < tagNum; i++) { tags[tagName[i]].push_back(pId); for (int j = i+1; j < tagNum; j++) { for (int k = j+1; k < tagNum; k++) { tags[tmp[i]+tmp[j]+tmp[k]].push_back(pId); } } } pId++; } int buyProduct(char tag1[], char tag2[], char tag3[]) { int buyId = -1; tmp.clear(); tmp.push_back(tag1); tmp.push_back(tag2); tmp.push_back(tag3); sort(tmp.begin(), tmp.end()); for (auto&id:tags[tmp[0]+tmp[1]+tmp[2]]) { if (!products[id]->bought && (buyId == -1 || products[buyId]->price > products[id]->price)) { buyId = id; } } if (buyId == -1) return -1; products[buyId]->bought = true; return products[buyId]->price; } void adjustPrice(char tag1[], int changePrice) { for (auto&id:tags[tag1]) { products[id]->price += changePrice; } } // #ifndef _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_WARNINGS #endif #include <stdio.h> extern void init(int N); extern void addProduct(int mPrice, int tagNum, char tagName[][10]); extern int buyProduct(char tag1[], char tag2[], char tag3[]); extern void adjustPrice(char tag1[], int changePrice); ///////////////////////////////////////////////////////////////////////// #define INIT 0 #define ADD 1 #define BUY 2 #define ADJ 3 static void mstrcpy(char dst[], const char src[]) { int c = 0; while ((dst[c] = src[c]) != '\0') ++c; } static int mstrcmp(const char str1[], const char str2[]) { int c = 0; while (str1[c] != '\0' && str1[c] == str2[c]) ++c; return str1[c] - str2[c]; } static bool run() { int N, cmd, ans, ret, tnum, price; char tag[5][10]; int Q = 0; bool okay = false; ret = ans = 0; okay = false; scanf("%d", &Q); for (int i = 0; i < Q; ++i) { scanf("%d", &cmd); switch (cmd) { case INIT: scanf("%d", &N); init(N); okay = true; break; case ADD: scanf("%d %d", &price, &tnum); for (int m = 0; m < tnum; m++) { scanf("%s", tag[m]); } addProduct(price, tnum, tag); break; case BUY: scanf("%d", &ans); for (int m = 0; m < 3; m++) { scanf("%s", tag[m]); } ret = buyProduct(tag[0], tag[1], tag[2]); if (ans != ret) { okay = false; } break; case ADJ: scanf("%s %d", tag[0], &price); adjustPrice(tag[0], price); break; default: okay = false; } } return okay; } int main() { setbuf(stdout, NULL); //freopen("sample_input.txt", "r", stdin); int T, MARK; scanf("%d %d", &T, &MARK); for (int tc = 1; tc <= T; tc++) { int score = run() ? MARK : 0; printf("#%d %d\n", tc, score); } return 0; } // 25 100 15 0 5 2 -1 white black red 1 50 3 red white black 1 35 4 blue red green white 1 50 3 black red green 1 45 5 red black white green blue 3 blue 7 2 50 white black red 1 80 3 green white black 2 52 red white black 3 blue -4 1 33 4 green white black blue 2 38 blue red white 2 -1 red blue white 2 33 green white black
Leave a Comment