Uvalive 3971 Assemble (analog + binary)

Source: Internet
Author: User

Uvalive 3971

Test instructions: B money, want to assemble a computer, give the type of n accessories, name, price, quality factor. If all kinds of accessories buy one, the total price <=b, to find the worst quality accessories of the maximum quality factor.

Ideas:

The maximum minimum value is usually divided into two methods.

In (0,MAXQ), it is possible to determine whether Q is the worst quality factor in two points.

Big Baishou problem, compare Test Code Foundation.


Code

/** @author novicer* language:c++/c*/#include <iostream> #include <sstream> #include <fstream># include<vector> #include <list> #include <deque> #include <queue> #include <stack># include<map> #include <set> #include <bitset> #include <algorithm> #include <cstdio># include<cstdlib> #include <cstring> #include <cctype> #include <cmath> #include <ctime># Include<iomanip>using namespace Std;const double eps (1e-8); typedef long LONG lint;const int MAXN = + 5;map< String,int> id;int N,b;int cnt = 0;struct comp{int price;int quality;}; Vector<comp> Comp[maxn];int ID (string s) {if (!id.count (s)) {id[s] = cnt++;} return id[s];} bool OK (int q) {int sum = 0;//cout << q << endl;for (int i = 0; i < cnt; i++) {int cheapest = B + 1;for (int j = 0; J < Comp[i].size (); J + +) {//cout << comp[i][j].price << endl;if (q <= comp[i][j].quality) cheapest = min (cheapest, COMP[I][J].P Susan);} if (cheapest = = b+1) return false;sum + = Cheapest;//cout << "Q:" << q << "sum:" << sum <&lt ; Endl;if (sum > B) return false;} return true;} int solve (int l, int r) {while (L < r) {int m = L + (r-l + 1)/2;if (OK (m)) L = m;else r = m-1;//cout << m <& Lt Endl;} return l;} int main () {//freopen ("Input.txt", "R", stdin), int t;cin >> t;while (t--) {cnt = 0;cin >> n >> b;for (int i = 0; I < n; i++) comp[i].clear (); int maxq = 0;for (int i = 1; I <= n; i++) {string type,name;int p,q;cin >> type >> nam E >> p >> q;//cout << type << name << p << q << endl;maxq = max (MAXQ, q); Comp tmp;tmp.price = p; tmp.quality = Q;comp[id (type)].push_back (TMP);} cout << maxq << endl;int L = 0, R = maxq;int ans = solve (l,r); cout << ans << endl;} return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Uvalive 3971 Assemble (analog + binary)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.