| ||||||||||
| 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 | |||||||||
已经修改了,代码如下In Reply To:WA 了,好心人给帮测试一下,发现错误后请致函Happy_Baby_Me@163.com,谢谢 Posted by:123454321 at 2006-11-03 15:20:10 #include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
struct xxx
{
int a, b;
}task[10005], s1[10005], s2[10005];
bool cmp1(struct xxx u, struct xxx v)
{
if (u.a < v.a)
return true;
return false;
}
bool cmp2(struct xxx u, struct xxx v)
{
if (u.b > v.b)
return true;
return false;
}
int main()
{
int n, i, j, k;
while (scanf_s("%d", &n) && n)
{
j = 0, k = 0;
for (i = 0; i < n; i++)
{
scanf_s("%d%d", &task[i].a, &task[i].b);
if (task[i].a < task[i].b)
{
s1[j].a = task[i].a;
s1[j++].b = task[i].b;
}
else
{
s2[k].a = task[i].a;
s2[k++].b = task[i].b;
}
}
sort(s1, s1 + j, cmp1);
sort(s2, s2 + k, cmp2);
int restime = 0, sum = 0;
for (i = 0; i < j; i++)
{
if (i == 0)
{
sum += s1[i].a + s1[i].b;
restime = s1[i].b;
continue;
}
if (s1[i].a >= restime)
{
sum += (s1[i].a - restime) + s1[i].b;
restime = s1[i].b;
}
else if (s1[i].a < restime)
{
sum += s1[i].b;
restime = restime - s1[i].a + s1[i].b;
}
}
for (i = 0; i < k; i++)
{
if (s2[i].a >= restime)
{
sum += (s2[i].a - restime) + s2[i].b;
restime = s2[i].b;
}
else
{
restime = restime - s2[i].a + s2[i].b;
sum += s2[i].b;
}
}
printf("%d\n", sum);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator