| ||||||||||
| 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 | |||||||||
Re:大家来探讨一下,这是我对这道题的看法。In Reply To:Re:大家来探讨一下,这是我对这道题的看法。 Posted by:306457592 at 2009-08-06 22:01:16 #include <iostream>
#include <fstream>
using namespace std;
int next (int k, int n, int c[]) {
if (k == n+1) return k;
for (int i=k+1; i <= n+1; i++) {
if (c[i] == 1)
return i;
}
return 0;
}
int main()
{
int t, n, i, j, tom, jack, count, current;
int a[210], b[210], c[210];
ifstream in("fu.txt");
in >> t;
while (t--) {
in >> n;
count=0;
for (i=1; i <= n; i++) {
in >> tom >> jack;
if (tom > jack)
swap (tom, jack);
if (tom%2 == 0) tom--;
if (jack%2 == 1) jack++;
a[i] = tom;
b[i] = jack;
c[i] = 1;
}
a[n+1] = 410;
b[n+1] = 440;
c[n+1] = 1;
for (i=2; i <= n; i++) {
for (j=i; j>1 && b[j]<b[j-1]; j--) {
swap(b[j], b[j-1]);
swap(a[j], a[j-1]);
}
}
current=1;
while (current != n+1) {
for (i=next(current, n, c); current != n+1; i=next(i, n, c)) {
if (a[i] > b[current]) {
c[current] = 0;
current = i;
}
}
count++;
for (i=1; i <= n+1; i++) {
if (c[i] == 1) {
current = i;
break;
}
}
}
printf("%d\n", count*10);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator