Codeforces Round #228 (Div. 1) C. Fox and Card Game
題目大意:給你n組數,每組有m個,有兩個人第一個人只能從開頭開始取,第二個人只能從最後一個取,第一個人先手,每個人都足夠聰明,問你他們最後的最大的得分為多少。
解題思路:顯然如果每組都可以對稱著取數,不會影響總得分,影響的分的是個數為奇數的那幾組,他們大小的先後就和先手有關,先手取掉最大的,後手取掉次大的,依次類推。。
Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.
The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom of any non-empty pile. Each player wants to maximize the total sum of the cards he took. The game ends when all piles become empty.
Suppose Ciel and Jiro play optimally, what is the score of the game?
The first line contain an integer n (1 ≤ n ≤ 100). Each of the next n lines contains a description of the pile: the first integer in the line is si(1 ≤ si ≤ 100) — the number of cards in the i-th pile; then follow si positive integers c1, c2, ..., ck, ..., csi (1 ≤ ck ≤ 1000) — the sequence of the numbers on the cards listed from top of the current pile to bottom of the pile.
Print two integers: the sum of Ciel's cards and the sum of Jiro's cards if they play optimally.
2 1 100 2 1 10
101 10
1 9 2 8 6 5 9 4 7 1 3
30 15
3 3 1 3 2 3 5 4 6 2 8 7
18 18
3 3 1000 1000 1000 6 1000 1000 1000 1000 1000 1000 5 1000 1000 1000 1000 1000
7000 7000
In the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10.
In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3.
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <ctime>
#include <map>
#include <set>
#define eps 1e-9
///#define M 1000100
///#define LL __int64
#define LL long long
///#define INF 0x7ffffff
#define INF 0x3f3f3f3f
#define PI 3.1415926535898
#define zero(x) ((fabs(x)<eps)?0:x)
#define mod 1000000007
#define Read() freopen("autocomplete.in","r",stdin)
#define Write() freopen("autocomplete.out","w",stdout)
#define Cin() ios::sync_with_stdio(false)
using namespace std;
const int maxn = 110;
int mp[maxn][maxn];
int num[maxn];
int main()
{
int n;
while(cin >>n)
{
int lsum = 0;
int rsum = 0;
for(int i = 1; i <= n; i++)
{
scanf("%d",&mp[i][0]);
for(int j = 1; j <= mp[i][0]; j++)
scanf("%d",&mp[i][j]);
}
int ans = 0;
for(int i = 1; i <= n; i++)
{
int x = mp[i][0]/2;
///cout<<"x == "<<x<<endl;
for(int j = 1; j <= x; j++) lsum += mp[i][j];
if(mp[i][0]%2)
{
num[ans++] = mp[i][x+1];
x++;
}
for(int j = x+1; j <= mp[i][0]; j++) rsum += mp[i][j];
}
sort(num, num+ans);
int cnt = 0;
for(int i = ans-1; i >= 0; i--)
{
if(cnt%2) rsum += num[i];
else lsum += num[i];
cnt++;
}
cout<<lsum<<" "<<rsum<<endl;
}
}
相關文章
- Codeforces Round #228 (Div. 2) A. Fox and Number GameGAM
- Codeforces Round #228 (Div. 2) B. Fox and CrossROS
- Codeforces Round #646 (Div. 2)【C. Game On Leaves 題解】GAM
- Codeforces Round #407 (Div. 1) C. The Great Mixing(bfs)
- Codeforces Round #446 (Div. 2) C. PrideIDE
- Codeforces Round #242 (Div. 2) C. Magic FormulasORM
- Codeforces Round #373 (Div. 1) C. Sasha and Array 線段樹
- Codeforces Round #245 (Div. 2) B - Balls GameGAM
- C. Lose it!(思維)Codeforces Round #565 (Div. 3)
- Codeforces Round #215 (Div. 2) C. Sereja and AlgorithmGo
- Codeforces Round #243 (Div. 2) C. Sereja and Swaps
- Codeforces Round 934 (Div. 1)
- Codeforces Round #251 (Div. 2) C. Devu and Partitioning of the Arraydev
- Codeforces Round 947 (Div. 1 + Div. 2)
- Codeforces C. Colored Rooks 構造 (Codeforces Round #518 (Div. 2) )
- Codeforces Round 709 (Div. 1)
- Codeforces Round #688 (Div. 2) C. Triangles(思維,數學)
- C. Dominant Piranha(思維) Codeforces Round #677 (Div. 3)NaN
- Codeforces Round 969 (Div. 1) 記錄
- Codeforces Round #228 div1前三題
- Codeforces Round #406 (Div. 1) C. Till I Collapse(可持久化線段樹)持久化
- C. MEX Game 1GAM
- Codeforces Beta Round #6 (Div. 2 Only) C. Alice, Bob and Chocolate 水題
- Codeforces Round 959 sponsored by NEAR (Div. 1 + Div. 2)
- 【Codeforces Round #499 (Div. 1) B】Rocket
- Codeforces Round #371 (Div. 2) C. Sonya and Queries[Map|二進位制]
- Card GameGAM
- Codeforces Beta Round #76 (Div. 1 Only) A. Frames
- Codeforces Round 943 (Div. 3)(C-G1)
- Codeforces Round #207 (Div. 2)C. Knight Tournament(SET也可以搞定)
- Educational Codeforces Round 165 (Rated for Div. 2) C. Minimizing the Sum題解
- Codeforces Round #639 (Div. 2)
- Codeforces Round #541 (Div. 2)
- Codeforces Round #690 (Div. 3)
- Codeforces Round #682 (Div. 2)
- Codeforces Round #678 (Div. 2)
- Codeforces Round #747 (Div. 2)
- Codeforces Round #673 (Div. 2)