Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

stl 大牛们看一下咯!这这题用multiset, 帮帮忙看哪儿出问题了 为什么WA??谢谢呀

Posted by yunhong at 2008-07-22 18:29:05 on Problem 2823
#include <iostream>
#include <set>
using namespace std;
const int N=1000010;

int f[N];
int ans[N][2];

int main()
{
	//freopen("c.in","r",stdin);
	int n, k;
	scanf("%d%d", &n, &k);
	int i;
	for (i=1; i<=n; i++)
		scanf("%d", &f[i]);

	multiset <int> MS;
	for (i=1; i<=k; i++)
		MS.insert(f[i]);

	ans[k][0] = * MS.begin();
	ans[k][1] = * MS.rbegin();

	for (i=k+1; i<=n; i++)
	{
		MS.insert(f[i]);
		MS.erase(f[i-k]);
		ans[i][0] = * MS.begin();
		ans[i][1] = * MS.rbegin();
	}
	printf("%d", ans[k][0]);
	for (i=k+1; i<=n; i++) printf(" %d", ans[i][0]);
	printf("\n%d", ans[k][1]);
	for (i=k+1; i<=n; i++) printf(" %d", ans[i][1]);
	printf("\n");

	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator