标签:stream algorithm using repr color 排序 map namespace end
题意:中文题;
思路:把k^2分解成首项为1,差的2的等差数列前n项和,然后对每天的糖果价格从小到大排序,依次+1,+3,+5。。。然后优先队列处理下;
代码:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<set>
#include<map>
#include<queue>
#include<vector>
#define ll long long int
#define mod 1000000007
#define me(a,b) memset(a,b,sizeof(a))
const
int
inf=0x7fffffff;
using
namespace
std;
int
main()
{
int
a[305][305];
int
n,m;
int
i,j;
int
cnt=1;
int
ans;
priority_queue<
int
,vector<
int
>,greater<
int
> >q;
ans=0;
cin>>n>>m;
for
(i=1;i<=n;i++)
for
(j=1;j<=m;j++)
cin>>a[i][j];
for
(i=1;i<=n;i++)
sort(a[i]+1,a[i]+1+m);
for
(i=1;i<=n;i++)
{
cnt=1;
for
(j=1;j<=m;j++)
{
a[i][j]+=cnt;
cnt+=2;
}
}
for
(i=1;i<=m;i++)
q.push(a[1][i]);
ans=q.top();
q.pop();
for
(i=2;i<=n;i++)
{
for
(j=1;j<=m;j++)
{
q.push(a[i][j]);
}
ans+=q.top();
q.pop();
}
cout<<ans<<endl;
return
0;
}
标签:stream algorithm using repr color 排序 map namespace end
原文地址:http://www.cnblogs.com/huangdao/p/7954336.html