日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

GYM101933I - Intergalactic Bidding

發布時間:2023/12/3 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 GYM101933I - Intergalactic Bidding 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

GYM101933I - Intergalactic Bidding


題解:不考慮首先顯然是個背包,一開始直接用set模擬,然后map存方案,這樣會mle。發現物品的體積有的特殊性

only one participant was allowed to make a bid at a time,
each participant was only allowed to make one bid, and
a participant making a bid had to bid at least twice the amount of the highest
bid at the time.

于是,直接對物品排序貪心取最大即可,因為對于種題目給定的s,一定有唯一的方法組成。

#include <bits/stdc++.h> typedef long long ll; const int N = 1e3 + 7; using namespace std; struct Big {char x[1005]; int len;string s;bool operator == (const Big &A) const {if(A.len != len) return 0;for(int i = 0; i < len; ++i) if(A.x[i] != x[i]) return 0;return 1;}bool operator < (const Big &A) const {if(A.len != len) return len < A.len;for(int i = len-1; i >= 0; --i) if(A.x[i] != x[i]) return x[i] < A.x[i];return 0;}Big operator + (const Big &A) const {Big ans = *this;for(int i = 0; i < A.len; ++i) {ans.x[i] = ans.x[i] + A.x[i];}int mx = max(A.len, len), f = 0;for(int i = 0; i < mx+1; ++i) {if(ans.x[i] >= 10) {ans.x[i]-=10; ++ans.x[i+1];}if(ans.x[i]) ans.len = i+1, f = 1;}if(!f) ans.len = 1;return ans;}Big operator - (const Big &A) const {Big ans = *this; int f = 0;for(int i = 0; i < A.len; ++i) {ans.x[i] = ans.x[i] - A.x[i];}int mx = max(A.len, len);for(int i = 0; i < mx+1; ++i) {if(ans.x[i] < 0) {ans.x[i]+=10; --ans.x[i+1];}if(ans.x[i]) ans.len = i+1, f = 1;}if(!f) ans.len = 1;return ans;}void read() {cin >> s; len = s.size();for(int i = 0; i < len; ++i) x[len-i-1] = s[i]-'0';s.clear();}void write() {for(int i = len-1; i >= 0; --i) printf("%d",x[i]); putchar('\n');} } s, ZER;int n; struct node{string nm; Big A;bool operator < (const node & a) const {return A < a.A;} } a[N]; vector<int> ans; int main() {ZER.x[0] = 0; ZER.len = 1;scanf("%d",&n);s.read();for(int i = 1; i <= n; ++i) {cin >> a[i].nm; a[i].A.read();}sort(a+1,a+1+n);for(int i = n ; i >= 1; --i) {if( a[i].A < s || s == a[i].A) {ans.push_back(i);s = s - a[i].A;}}if(s == ZER) {printf("%d\n",(int)ans.size());for(int i = 0; i < ans.size(); ++i) {cout << a[ans[i]].nm << '\n';}}else puts("0");return 0; }

轉載于:https://www.cnblogs.com/RRRR-wys/p/9817446.html

總結

以上是生活随笔為你收集整理的GYM101933I - Intergalactic Bidding的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。