zoj1029 Moving Tables

来源:互联网 发布:知乎怎么发表文章 编辑:程序博客网 时间:2024/05/21 17:32
  1. //zoj1029 Moving Tables
  2. //Accepted 1029 C++ 00:00.01 436K
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <algorithm>
  6. using namespace std;
  7. struct room{ int s; int t; } r[200];
  8. int sort_function(const void *a, const void *b)
  9. {
  10.        return (*(int *)a - *(int *)b);
  11. }
  12. void solve()
  13. {
  14.        int i,j,n;
  15.        scanf ("%d",&n);
  16.        for (i=0; i<n; ++i) {
  17.               int s,t;
  18.               scanf ("%d %d",&s,&t);
  19.               if (s > t) swap(s,t);
  20.               r[i].s = (s+1)/2;
  21.               r[i].t = (t+1)/2;
  22.        }
  23.        qsort (r,n,sizeof(r[0]),sort_function);
  24.        int max = 0;
  25.        for (i=0; i<n; ++i) {
  26.               int cnt = 1, from = r[i].s, to = r[i].t;
  27.               for (j=0; j<n; ++j) {
  28.                      if (i == j) continue;
  29.                      if (r[j].s<=to && r[j].t>=from) {
  30.                             if (from < r[j].s) from = r[j].s;
  31.                             if (to > r[j].t) to = r[j].t;
  32.                             cnt++;
  33.                      }
  34.               }
  35.               if (cnt > max) max = cnt;
  36.        }
  37.        printf ("%d/n",10*max);
  38. }
  39. int main()
  40. {
  41. #ifndef ONLINE_JUDGE
  42.        freopen("1029.txt","r",stdin);
  43. #endif
  44.        int test;
  45.        while (scanf ("%d",&test) != EOF)
  46.               while (test--)
  47.                      solve();
  48. #ifndef ONLINE_JUDGE
  49.        fclose(stdin);
  50. #endif
  51.        return 0;
  52. }