2091: [Poi2010]The Minima Game
Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 577 Solved: 392
[Submit][Status][Discuss]
Description
給出N個正整數,AB兩個人輪流取數,A先取。每次可以取任意多個數,直到N個數都被取走。
每次獲得的得分爲取的數中的最小值,A和B的策略都是儘可能使得自己的得分減去對手的得分更大。
在這樣的情況下,最終A的得分減去B的得分爲多少。
Input
第一行一個正整數N (N <= 1,000,000),第二行N個正整數(不超過10^9)。
Output
一個正整數,表示最終A與B的分差。
Sample Input
1 3 1
Sample Output
HINT
第一次A取走3,第二次B取走兩個1,最終分差爲2。
Source
題解:維護一個******其實我也不咋會 好像是個dp 因爲題中兩個同學都很聰明,但我很sb啊他們每次都會選擇最利於自己的情況,所以符合最優子結構,可以做dpQAQ
貼上代碼:
#include<bits/stdc++.h>
#define M 1000010
#define ll long long
const int INF = 0x7fffffff;
const double eps = 1e-5;
using namespace std;
int read()
{
int x = 0 , f = 1; char ch = getchar();
while(ch<'0'||ch>'9') {if(ch=='-')f*=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+(ch-'0');ch=getchar();}
return x * f;
}
int a[M],f[M];
int main()
{
int n = read();
for(int i = 1 ; i <= n ; i++)
a[i] = read();1
sort(a+1,a+1+n);
int mx=a[1];
for(int i = 1; i <= n ;++i)
mx=max(mx,a[i+1]-mx);
printf("%d",mx);
return 0;
}