http://codeforces.com/contest/192/problem/A
水题,这题枚举+二分可以解决,k1*(k1+1) + k2*(k2+1) == 2* n ,枚举k1( k1>=1 ,k1 <= sqrt(2*n)+1 )二分查找k2
http://codeforces.com/contest/192/problem/B
dp水题
http://codeforces.com/contest/192/problem/C
看懂题意后就是就是dp水题,dp[start][end] 表示以字母start 开头的并且以end结尾的最大字符,每次加入一个字符,有两种选择 a1a2...an
1) 把它连在以a1结尾的字符后
2) 以a1为起点以an为终点更新 dp[a1][an]
ans=max(dp[i][i]); i>=1,i<=n;
http://codeforces.com/contest/192/problem/D
这题看懂题意后也就是水题,就不解释了,贪心即可
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef __int64 ll;
struct Node
{
ll cost;
int id;
bool operator<(Node dd) const
{
return cost > dd.cost;
}
}a[500010];
int main(int argc, char *argv[])
{
int n,k;
ll b,tot;
while(cin>>n>>k)
{
tot=0;
cin>>b;
for(int i=1;i<=n;i++)
cin>>a[i].cost,a[i].id=i;
sort(a+1,a+n);
for(int i=1;i<=k;i++)
tot+=a[i].cost;
b-=tot;
int ans=n;
if(b<0)
{
ll remain=b+a[k].cost;
for(int i=k;i<n;i++)
if(remain<a[i].cost&&ans>a[i].id)
ans=a[i].id;
}
cout<<ans<<endl;
}
// system("PAUSE");
return EXIT_SUCCESS;
}