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

WHY FEW ACCEPTED FOR SUCH A EASY PROBLEM

Posted by khesoem at 2010-09-08 22:35:16 on Problem 3171
#include <cstdio>
#include <algorithm>
#include <iostream>
#define maxn (10000 + 10)
using namespace std;

const int inf = 1000000000;
int n, d[maxn], ans, m, e;
pair<pair<int, int>, int>p[maxn];

void init(){
	for(int i = 0; i < n; i++) d[i] = inf; ans = inf;
}

int main(){
	scanf("%d %d %d", &n, &m, &e);
	init();
	for(int i = 0; i < n; i++){
		scanf("%d %d %d", &p[i].first.first, &p[i].first.second, &p[i].second);
	}
	sort(p, p + n);
	for(int i = 0; i < n; i++) if(p[i].first.first == m) d[i] = 0;
	for(int i = 0; i < n; i++){
		int c = p[i].second, t = d[i], pl = p[i].first.second + 1;
		for(int j = i + 1; j < n && p[j].first.first <= pl; j++){
			d[j] = min(d[j], t + c);
		}
	}
	for(int i = 0; i < n; i++){
		if(p[i].first.second == e){
			ans = min(ans, d[i] + p[i].second);
		}
	}
	printf("%d\n", (ans != inf ? ans : -1));
	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