首页 > 代码库 > hdu1896 bjfu1268 水题
hdu1896 bjfu1268 水题
很简单的模拟,我是用的优先队列。不多说,上代码(这是bjfuoj的,hdu的要稍改一下):
/* * Author : ben */#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <ctime>#include <iostream>#include <algorithm>#include <queue>#include <set>#include <map>#include <stack>#include <string>#include <vector>#include <deque>#include <list>#include <functional>#include <numeric>#include <cctype>using namespace std;typedef struct Stone { int p, d; Stone(int pp, int dd) { p = pp; d = dd; }} Stone;inline bool operator<(const Stone &s1, const Stone &s2) { if (s1.p != s2.p) { return s1.p > s2.p; } return s1.d > s2.d;}//输入非负整数,用法int a = get_int();int get_int() { int res = 0, ch; while (!((ch = getchar()) >= ‘0‘ && ch <= ‘9‘)) { if (ch == EOF) return -1; } res = ch - ‘0‘; while ((ch = getchar()) >= ‘0‘ && ch <= ‘9‘) res = res * 10 + (ch - ‘0‘); return res;}int main() { int n, p, d, ans; bool flag; while ((n = get_int()) > 0) { priority_queue<Stone> pq; for (int i = 0; i < n; i++) { p = get_int(); d = get_int(); pq.push(Stone(p, d)); } ans = 0; flag = true; while (!pq.empty()) { Stone s = pq.top(); ans = s.p; pq.pop(); if (flag) { s.p += s.d; pq.push(s); } flag = !flag; } printf("%d\n", ans); } return 0;}
hdu1896 bjfu1268 水题
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。