HDOJ1050 Moving Tables

来源:互联网 发布:公司数据部门职责 编辑:程序博客网 时间:2024/06/10 19:30

原题链接

更新后:

#include <stdio.h>#include <string.h>#include <algorithm>#define maxn 402using std::max_element;using std::swap;int arr[maxn];int main(){int t, n, a, b;scanf("%d", &t);while(t--){scanf("%d", &n);memset(arr, 0, sizeof(arr));while(n--){scanf("%d%d", &a, &b);if(!(a & 1)) --a;if(!(b & 1)) --b;if(a > b) swap(a, b);while(a <= b) ++arr[a++];}printf("%d\n", *max_element(arr, arr + 400) * 10);}return 0;}


更新前:

#include <stdio.h>struct Node{int begin, end;};Node a[201];int p[401];int main(){int t, n, i, temp, count, j;scanf("%d", &t);while(t--){scanf("%d", &n);for(i = 0; i != n; ++i){scanf("%d%d", &a[i].begin, &a[i].end);if(a[i].begin > a[i].end){temp = a[i].begin;a[i].begin = a[i].end;a[i].end = temp;}if(a[i].begin & 1 == 0) --a[i].begin; //调整门口占用if(a[i].end & 1) ++a[i].end;}for(i = 0; i != n; ++i)for(j = a[i].begin; j <= a[i].end; ++j)++p[j];for(i = count = 0; i != 401; ++i)if(p[i] > count) count = p[i];printf("%d\n", count * 10);for(i = 0; i != 401; ++i)p[i] = 0;}return 0;}


0 0