Codeforces Round #228 (Div. 1) C 貪心,

來源:互聯網
上載者:User

Codeforces Round #228 (Div. 1) C 貪心,

嘎嘎,今天被一些事耽誤了,但是還是A了幾個題目,這道題還不錯

題目連結:


題意:兩個人玩遊戲,有N堆紙牌,紙牌上有數字,A每次只能取N堆中的 其中一個的頂部的 紙牌,B只能取N堆中的其中一個底部 的紙牌,A,B都想讓自己取的和最大,問最後比分為多少


畫了一下,如果某一堆裡的 紙牌數量為偶數,發現其實是兩個人各分一半,因為如果對方想從這裡拿走本來屬於自己那半部分的 較大的牌,自己完全來得及阻止的,

接下來就是奇數了,奇數 其實先手者就搶到了中間的一張牌,另外兩半還是各自一半,所以 應該以每個奇數堆的 中間紙牌 的大小來進行貪心,


int n;typedef struct Node {int mid;int id;};Node node[100 + 55];int mp[100 + 55][100 + 55];int ss[100 + 55];void init() {memset(ss,0,sizeof(ss));memset(node,0,sizeof(node));}bool input() {while(cin>>n) {return false;}return true;}bool cmp(Node x,Node y) {return x.mid > y.mid;}void cal() {int ans1 = 0;int ans2 = 0;int cnt = 0;for(int i=0;i<n;i++) {scanf("%d",&ss[i]);if(ss[i]&1) {for(int j=1;j<=ss[i];j++) {scanf("%d",&mp[i][j]);if(j == (ss[i] + 1)/2) {node[cnt].id = i;node[cnt++].mid = mp[i][j];}}}else {for(int j=1;j<=ss[i];j++) {int x;scanf("%d",&x);if(j <= ss[i]/2) ans1 += x;else ans2 += x;}}}sort(node,node + cnt,cmp);int mark = 1;for(int i=0;i<cnt;i++) {if(mark > 0) {int k = node[i].id;for(int j=1;j<=(ss[k] + 1)/2;j++)ans1 += mp[k][j];for(int j=(ss[k] + 1)/2 + 1;j<=ss[k];j++)ans2 += mp[k][j];}else {int k = node[i].id;for(int j=1;j<=ss[k]/2;j++)ans1 += mp[k][j];for(int j=(ss[k] + 1)/2;j<=ss[k];j++)ans2 += mp[k][j];}mark *= -1;}cout<<ans1<<" "<<ans2<<endl;}void output() {}int main() {while(true) {init();if(input())return 0;cal();output();}return 0;}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.