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

100MS——21行——精简&不排序代码

Posted by fA1sEr at 2015-02-10 10:41:28 on Problem 2376
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int N, T, M[1000050];
int main()
{
	cin >> N >> T;int a, b;
	for (int i = 0; i < N; i++) { scanf("%d%d", &a, &b); if (M[a] == 0)M[a] = b; else M[a] = max(M[a], b); }
	int nows = 1, cnt = 0, t, pre = 1, i;
	while (nows - 1 < T)
	{
		t = 0; i = pre;
		for ( ; i <= nows; i++)
			if (M[i] > t) { t = M[i]; pre = i; }
		if (t + 1 == nows) { cout << -1 << endl; return 0; }
		nows = t + 1;cnt++;
	}
	cout << cnt << endl;
	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