Billionaires
来源:互联网 发布:服务器数据恢复 沈阳 编辑:程序博客网 时间:2024/05/22 17:13
Billionaires
.
.
题意:给出n个人所在的城市以及个人财富,接下来有k起事件,表示某天某人到达某个城市,问每个城市拥有的财富值最大的天数(比其他所有城市都多)。
.
.
解法:用stl直接模拟就行了
.
.
队友代码
#include <cstdio>#include <map>#include <string>#include <algorithm>#include <set>using namespace std;char c[200], d[200];struct peo { string name; long long wealth;} a[60010];struct event { int day; string who; string place;} b[60010];struct ss { int day; string p;} aaa[60010];struct pl { string name; long long num; bool operator <(const pl& other) const { if (num == other.num) return name < other.name; return num < other.num; }};bool cmp(ss a, ss b){ return a.p < b.p;}map<string,long long> peosw;map<string,long long> howmuch;map<string,string> whichplace;map<string,int> ans;set<pl> sett;long long s;int main(){ int n, m, k; scanf("%d", &n); for(int i = 1; i <= n; i++) { scanf("%s %s %I64d", c, d, &s); string aa(c), bb(d); whichplace[aa] = bb; a[i].name = aa; a[i].wealth = s; peosw[aa] = s; if (!howmuch[bb]) howmuch[bb] = s; else howmuch[bb] = howmuch[bb] + s; } map<string,long long>::iterator it; for (it = howmuch.begin(); it != howmuch.end(); it++) { pl newx; newx.name = it -> first; newx.num = it -> second; sett.insert(newx); } scanf("%d %d", &m, &k); for (int i = 1; i <= k; i++) { scanf("%d %s %s", &b[i].day, c, d); string aa(c), bb(d); b[i].who = aa; b[i].place = bb; } int pos = 1; for (int i = 1; i <= m; i++) { set<pl>::iterator it1, it2; if (sett.size() > 1) { it1 = sett.end(); it1--; it2 = it1; it2--; if (it1 -> num > it2 -> num) { if (!ans[it1 -> name]) ans[it1 -> name] = 1; else ans[it1 -> name] = ans[it1 -> name] + 1; } } else if (sett.size() == 1) { it1 = sett.end(); it1--; if (!ans[it1 -> name]) ans[it1 -> name] = 1; else ans[it1 -> name] = ans[it1 -> name] + 1; } while (i == b[pos].day && pos <= k) { pl oldp, newp1, newp2, oldp1; oldp.name = whichplace[b[pos].who]; oldp.num = peosw[b[pos].who]; newp1.name = b[pos].place; whichplace[b[pos].who] = b[pos].place; if (!howmuch[newp1.name]) { newp1.num = oldp.num; howmuch[newp1.name] = oldp.num; sett.insert(newp1); } else { newp1.num = howmuch[newp1.name] + oldp.num; oldp1.name = newp1.name; oldp1.num = howmuch[newp1.name]; howmuch[newp1.name] = howmuch[newp1.name] + oldp.num; sett.insert(newp1); sett.erase(oldp1); } if (howmuch[oldp.name] > oldp.num) { newp2.name = oldp.name; newp2.num = howmuch[oldp.name] - oldp.num; sett.insert(newp2); } long long tmp = oldp.num; oldp.num = howmuch[oldp.name]; howmuch[oldp.name] = howmuch[oldp.name] - tmp; sett.erase(oldp); pos++; } } map<string, int>::iterator itt; int cnt = 0; for (itt = ans.begin(); itt != ans.end(); itt++) { ss news; news.day = itt -> second; news.p = itt -> first; aaa[++cnt] = news; } sort(aaa + 1, aaa + cnt + 1, cmp); for (int i = 1; i <= cnt; i++) { printf("%s %d\n", aaa[i].p.c_str(), aaa[i].day); }}
0 0
- Billionaires
- URAL 1650. Billionaires(线段树)
- Is Li Ka-shing on the Billionaires' Charity Bandwagon?
- Billionaires' Tips For New Grads…
- eclipse 设置 @author @version等注释模板
- Android Binder机制理解
- leetcode 263. Ugly Number
- 最完美的ZoomImageView,可根据点击/多指触控 放大,放小的ImageVIew
- 零碎的小知识-最迟开始时间&最早开始时间
- Billionaires
- swift中模型Model的创建
- java学习之数组
- 遍历Map的四种方法
- iOS 沙盒的目录结构
- PHP的PSR-0标准利用namespace来做autoloading
- Linux vi/vim
- ios开发使用CoreData存储数据时,快速写下FetchRequest语句操作
- PHP中单引号和双引号的区别之PHP单双引号那些事