首页 > ACM题库 > HDU-杭电 > HDU 3650-Hot Expo[解题报告]HOJ
2014
11-30

HDU 3650-Hot Expo[解题报告]HOJ

Hot Expo

问题描述 :

Sunny wants to go to the Shanghai Expo this month and he intends to visit n (1 <= n <= 100 ) country pavilions. As we all know, in each pavilion, there is always a wonderful performance every day. Every performance will always be played only one time each day. And performance i begins at beg[i] second and ends at end[i] second (0<=beg[i], end[i] <24 * 3600). Sunny can not visit more than one country pavilion at the same time. Sunny wouldn’t like to miss any performance in the country pavilions that he plans to visit. However, it’s also well known that getting accommodation in Shanghai is a little expensive, so he has to make a good arrangement to make his staying time (in days) there minimum.

输入:

The input contains several test cases. Each test case begins with an integer number n. Then n lines follow and each contains two integers representing the begin time and end time of the performance in the corresponding day.
Input is terminated by a value of zero (0) for n.

输出:

The input contains several test cases. Each test case begins with an integer number n. Then n lines follow and each contains two integers representing the begin time and end time of the performance in the corresponding day.
Input is terminated by a value of zero (0) for n.

样例输入:

2
1 4
4 5
2
2 3
4 6
0

样例输出:

2 
1

#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;

int n, i, now, ans, j, s[24 * 3605], a, b;
int main(){
 while (scanf("%d", &n) == 1 && n){
 memset(s, 0, sizeof(s));
 for (i = 1; i <= n; i++){
 scanf("%d%d", &a, &b);
 s[a]++; s[b + 1]--;
 }
 now = ans = 0;
 for (i = 0; i < 24 * 3600; i++){
 now += s[i];
 ans = max(ans, now);
 }
 printf("%d\n", ans);
 }

}

  1. #!/usr/bin/env python
    def cou(n):
    arr =
    i = 1
    while(i<n):
    arr.append(arr[i-1]+selfcount(i))
    i+=1
    return arr[n-1]

    def selfcount(n):
    count = 0
    while(n):
    if n%10 == 1:
    count += 1
    n /= 10
    return count

  2. #include <cstdio>

    int main() {
    //answer must be odd
    int n, u, d;
    while(scanf("%d%d%d",&n,&u,&d)==3 && n>0) {
    if(n<=u) { puts("1"); continue; }
    n-=u; u-=d; n+=u-1; n/=u;
    n<<=1, ++n;
    printf("%dn",n);
    }
    return 0;
    }