国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

codeforces 725F

2019-11-08 02:38:31
字體:
來源:轉載
供稿:網友

F. Family Photos

time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Alice and Bonnie are sisters, but they don’t like each other very much. So when some old family photos were found in the attic, they started to argue about who should receive which photos. In the end, they decided that they would take turns picking photos. Alice goes first.

There are n stacks of photos. Each stack contains exactly two photos. In each turn, a player may take only a photo from the top of one of the stacks.

Each photo is described by two non-negative integers a and b, indicating that it is worth a units of happiness to Alice and b units of happiness to Bonnie. Values of a and b might differ for different photos.

It’s allowed to pass instead of taking a photo. The game ends when all photos are taken or both players pass consecutively.

The players don’t act to maximize their own happiness. Instead, each player acts to maximize the amount by which her happiness exceeds her sister’s. Assuming both players play optimal, find the difference between Alice’s and Bonnie’s happiness. That is, if there’s a perfectly-played game such that Alice has x happiness and Bonnie has y happiness at the end, you should PRint x?-?y.

Input The first line of input contains a single integer n (1?≤?n?≤?100?000) — the number of two-photo stacks. Then follow n lines, each describing one of the stacks. A stack is described by four space-separated non-negative integers a1, b1, a2 and b2, each not exceeding 109. a1 and b1 describe the top photo in the stack, while a2 and b2 describe the bottom photo in the stack.

Output Output a single integer: the difference between Alice’s and Bonnie’s happiness if both play optimally.

Examples input 2 12 3 4 7 1 15 9 1 output 1 input 2 5 4 8 8 4 12 14 0 output 4 input 1 0 10 0 10 output -10

題目大意:

有n對照片,A和B輪流取,獲得不同的喜悅值,每對照片只有當第一張照片被取走后才能取第二張,當輪到一個人時,他可以選擇不取,當所有照片都被取完或當連續兩個人都不取時,游戲結束。A和B都希望自己的喜悅值和對方的喜悅值差值最大,假設兩人都采用最佳策略,求A和B的喜悅值的差值。

解題思路:

分三種情況: 1.a1<=b2&&b1<=a2,負收益可忽略 2.a1>b2或b1>a2,且a1+b1<=a2+b2;保證正收益選擇先手 3.其余情況,物品價值a1+b1(第二輪a2+b2),優先隊列貪心

#include<iostream>#include<queue>using namespace std;typedef long long LL;int n;struct node{ int a1, b1, a2, b2; int tag;};bool Operator< (const node& a, const node& b){ return a.a1+a.b1<b.a1+b.b1;//大的先出隊}int main(){ ios::sync_with_stdio(false); cin.tie(0); priority_queue<node> pq; while(cin>>n) { while(!pq.empty()) pq.pop(); LL ans=0; int a1, b1, a2, b2; for(int i=1;i<=n;i++) { cin>>a1>>b1>>a2>>b2; if(a1<=b2&&b1<=a2) continue; else if(a1+b1<a2+b2) { if(a1>b2) ans+=a1-b2; else ans+=a2-b1; } else { node tmp; tmp.a1=a1, tmp.b1=b1, tmp.a2=a2, tmp.b2=b2; tmp.tag=1; pq.push(tmp); } } int cnt=0; while(!pq.empty()) { cnt++; node tmp=pq.top(); pq.pop(); if(cnt%2) { ans+=tmp.a1; } else ans-=tmp.b1; if(tmp.tag==1) { tmp.tag=2; tmp.a1=tmp.a2; tmp.b1=tmp.b2; tmp.a2=0; tmp.b2=0; pq.push(tmp); } } cout<<ans<<endl; } return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 贺兰县| 阿拉善右旗| 三河市| 长春市| 台中市| 奉化市| 尼勒克县| 寿宁县| 常熟市| 五峰| 静宁县| 赤壁市| 灵石县| 巩留县| 诸城市| 琼海市| 太仓市| 玉龙| 梅州市| 张家港市| 唐山市| 云阳县| 丹棱县| 太谷县| 南宁市| 叙永县| 正安县| 水城县| 大厂| 孟州市| 张北县| 木兰县| 齐河县| 芜湖县| 雷山县| 惠来县| 新建县| 深州市| 武城县| 哈巴河县| 右玉县|