Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
救救我把,wa啦好多次了。就是不知道哪里错了#include <iostream> #include <algorithm> using namespace std; #pragma warning(disable:4996) const int MAX_N = 25002; pair<int, int>via[MAX_N]; int N, T; void solve(){ sort(via, via + N); //如果到达不到T直接return if (via[N - 1].second < T){ printf("%d\n", -1); return; } int ans = 0; int t = 1, i = 0; while (i < N){ //选初始的1 while (via[i].first == 1){ t = via[i].second + 1; i++; } //拼接并选择结束时间最大的一个 if (t >= via[i].first){ int temp = t; //在循环的过程中t在变化 while (i < N&&temp >= via[i].first){ t = max(t, via[i].second + 1); i++; } ans++; } //不能拼接return else{ printf("%d\n", -1); return; } } printf("%d\n", ans + 1); } int main() { #ifndef ONLINE_JUDGE freopen("E:\\in.txt", "r", stdin); #endif // !ONLINE_JUDGE scanf("%d %d", &N, &T); int a, b; for (int i = 0; i < N; ++i){ scanf("%d %d", &a, &b); via[i] = make_pair(a, b); } solve(); #ifndef ONLINE_JUDGE fclose(stdin); #endif // !ONLINE_JUDGE return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator