• 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 (B,F,L,M)


    B. Train Seats Reservation

    You are given a list of train stations, say from the station 1 to the station 100.

    The passengers can order several tickets from one station to another before the train leaves the station one. We will issue one train from the station 1 to the station 100 after all reservations have been made. Write a program to determine the minimum number of seats required for all passengers so that all reservations are satisfied without any conflict.

    Note that one single seat can be used by several passengers as long as there are no conflicts between them. For example, a passenger from station 1 to station 10 can share a seat with another passenger from station 30 to 60.

    Input Format

    Several sets of ticket reservations. The inputs are a list of integers. Within each set, the first integer (in a single line) represents the number of orders, nnn, which can be as large as 1000. After nnn, there will be nnn lines representing the nnn reservations; each line contains three integers s,t,ks, t, ks,t,k, which means that the reservation needs kkk seats from the station sss to the station ttt .These ticket reservations occur repetitively in the input as the pattern described above. An integer n=0n = 0n=0 (zero) signifies the end of input.

    Output Format

    For each set of ticket reservations appeared in the input, calculate the minimum number of seats required so that all reservations are satisfied without conflicts. Output a single star '*' to signify the end of outputs.

    样例输入

    2
    1 10 8
    20 50 20
    3
    2 30 5
    20 80 20
    40 90 40
    0

    样例输出

    20
    60
    *

    简单模拟

    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <cstdlib>
    #include <iomanip>
    #include <cmath>
    #include <cassert>
    #include <ctime>
    #include <cstdlib>
    #include <map>
    #include <set>
    using namespace std;
    #pragma comment(linker, "/sTACK:1024000000,1024000000")
    #define lowbit(x) (x&(-x))
    #define max(x,y) (x>=y?x:y)
    #define min(x,y) (x<=y?x:y)
    #define MAX 100000000000000000
    #define MOD 1000000007
    #define pi acos[j](-1.0)
    #define ei exp(1)
    #define PI 3.1415926535
    #define ios() ios[j]::sync_with_stdio(true)
    #define INF 1044266558
    #define mem(a) (memset(a,0,sizeof(a)))
    typedef long long ll;
    ll a[105],n,s,t,w;
    int main()
    {
        while(scanf("%lld",&n))
        {
            if(n==0) break;
            memset(a,0,sizeof(a));
            for(ll i=0;i<n;i++)
            {
                scanf("%lld%lld%lld",&s,&t,&w);
                for(ll j=s;j<t;j++)
                {
                    a[j]+=w;
                }
            }
            ll ans=0;
            for(ll i=1;i<=100;i++)
            {
                ans=max(ans,a[i]);
            }
            printf("%lld
    ",ans);
        }
        printf("*
    ");
        return 0;
    }

    F. Overlapping Rectangles

    There are nnn rectangles on the plane. The problem is to find the area of the union of these rectangles. Note that these rectangles might overlap with each other, and the overlapped areas of these rectangles shall not be counted more than once. For example, given a rectangle AAA with the bottom left corner located at (0,0) and the top right corner at (2,2), and the other rectangle BBB with the bottom left corner located at (1,1) and the top right corner at (3,3), it follows that the area of the union of A and B should be7 , instead of 8.

    Although the problem looks simple at the first glance, it might take a while to figure out how to do it correctly. Note that the shape of the union can be very complicated, and the intersected areas can be overlapped by more than two rectangles.

    Note:

    (1) The coordinates of these rectangles are given in integers. So you do not have to worry about the floating point round-off errors. However, these integers can be as large as 1,000,000.

    (2) To make the problem easier, you do not have to worry about the sum of the areas exceeding the long integer precision. That is, you can assume that the total area does not result in integer overflow.

    Input Format

    Several sets of rectangles configurations. The inputs are a list of integers. Within each set, the first integer (in a single line) represents the number of rectangles, n, which can be as large as 1000. After n, there will be n lines representing the n rectangles; each line contains four integers <a,b,c,d> , which means that the bottom left corner of the rectangle is located at (a,b), and the top right corner of the rectangle is located at (c,d). Note that integers a, b, c, d can be as large as 1,000,000.

    These configurations of rectangles occur repetitively in the input as the pattern described above. An integer n=0n = 0n=0 (zero) signifies the end of input.

    Output Format

    For each set of the rectangles configurations appeared in the input, calculate the total area of the union of the rectangles. Again, these rectangles might overlap each other, and the intersecting areas of these rectangles can only be counted once. Output a single star '*' to signify the end of outputs.

    样例输入

    2
    0 0 2 2
    1 1 3 3
    3
    0 0 1 1
    2 2 3 3
    4 4 5 5
    0

    样例输出

    7
    3
    *

    求多矩形面积,可能存在重合 扫描线
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <cstdlib>
    #include <iomanip>
    #include <cmath>
    #include <cassert>
    #include <ctime>
    #include <cstdlib>
    #include <map>
    #include <set>
    using namespace std;
    #pragma comment(linker, "/sTACK:1024000000,1024000000")
    #define lowbit(x) (x&(-x))
    #define max(x,y) (x>=y?x:y)
    #define min(x,y) (x<=y?x:y)
    #define MAX 100000000000000000
    #define MOD 1000000007
    #define pi acos[j](-1.0)
    #define ei exp(1)
    #define PI 3.1415926535
    #define ios() ios[j]::sync_with_stdio(true)
    #define INF 1044266558
    #define mem(a) (memset(a,0,sizeof(a)))
    typedef long long ll;
    #define pr(x) cout << #x << " = " << x << "  "
    #define prln(x) cout << #x << " = " << x << endl
    const int N = 3000;
    int n;
    struct Seg 
    {
        double l,r,h;
        int d;
        Seg(){}
        Seg(double l,double r,double h,int d):l(l),r(r),h(h),d(d){}
        bool operator<(const Seg& rhs) const {return h<rhs.h;}
    }a[N];
    int cnt[N<<2];
    double sum[N<<2],all[N];
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    void push_up(int l,int r,int rt) 
    {
        if(cnt[rt]) sum[rt]=all[r+1]-all[l];
        else if(l==r) sum[rt]=0;
        else sum[rt]=sum[rt<<1]+sum[rt<<1|1];
    }
    
    void update(int L,int R,int v,int l,int r,int rt) 
    {
        if(L<=l && r<=R) {
            cnt[rt]+=v;
            push_up(l,r,rt);
            return;
        }
        int m = l + r >> 1;
        if(L<=m) update(L,R,v,lson);
        if(R>m) update(L,R,v,rson);
        push_up(l,r,rt);
    }
    int main()
    {
        ios_base::sync_with_stdio(0);
        int kase = 0;
        while(scanf("%d",&n))
        {
            if(n==0) break;
            for(int i=1;i<=n;++i) 
            {
                double x1,y1,x2,y2;
                scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
                a[i]=Seg(x1,x2,y1,1);
                a[i+n]=Seg(x1,x2,y2,-1);
                all[i]=x1;all[i+n]=x2;
            }
            n<<=1;
            sort(a+1, a+1+n);
            sort(all + 1, all+1+n);
            int m=unique(all+1,all+1+n)-all-1;
            memset(cnt,0,sizeof(cnt));
            memset(sum,0,sizeof(sum));
            double ans=0;
            for(int i=1;i<n;++i) 
            {
                int l=lower_bound(all+1, all+1+m, a[i].l)-all;
                int r=lower_bound(all+1, all+1+m, a[i].r)-all;
                if(l<r) update(l,r-1,a[i].d,1,m,1);
                ans+=sum[1]*(a[i+1].h-a[i].h);
            }
            printf("%.lf
    ",ans);
        }
        printf("*
    ");
        return 0;
    }

    L. The Heaviest Non-decreasing Subsequence Problem

    Let S be a sequence of integers s1s_{1}s1​​, s2s_{2}s2​​, ........., sns_{n}sn​​ Each integer is is associated with a weight by the following rules:

    (1) If is is negative, then its weight is 0.

    (2) If is is greater than or equal to 10000, then its weight is 5. Furthermore, the real integer value of sis_{i}si​​ is si−10000s_{i}-10000si​​10000 . For example, if sis_{i}si​​ is 101011010110101, then is is reset to 101101101 and its weight is 555.

    (3) Otherwise, its weight is 1.

    A non-decreasing subsequence of SSS is a subsequence si1s_{i1}si1​​, si2s_{i2}si2​​, ........., siks_{ik}sik​​, with i1<i2 ... <iki_{1}<i_{2} ... <i_{k}i1​​<i2​​ ... <ik​​, such that, for all 1≤j<k1 leq j<k1j<k, we have sij<sij+1s_{ij}<s_{ij+1}sij​​<sij+1​​.

    A heaviest non-decreasing subsequence of SSS is a non-decreasing subsequence with the maximum sum of weights.

    Write a program that reads a sequence of integers, and outputs the weight of its

    heaviest non-decreasing subsequence. For example, given the following sequence:

    80 75 73 93 73 73 10101 97 −1 −1 114 −1 10113 118

    The heaviest non-decreasing subsequence of the sequence is <73, 73, 73, 101, 113, 118> with the total weight being 1+1+1+5+5+1=14. Therefore, your program should output 141414 in this example.

    We guarantee that the length of the sequence does not exceed 2∗1052*10^{5}2105​​

    Input Format

    A list of integers separated by blanks:s1s_{1}s1​​, s2s_{2}s2​​,.........,sns_{n}sn​​

    Output Format

    A positive integer that is the weight of the heaviest non-decreasing subsequence.

    样例输入

    80 75 73 93 73 73 10101 97 -1 -1 114 -1 10113 118

    样例输出

    14
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <cstdlib>
    #include <iomanip>
    #include <cmath>
    #include <cassert>
    #include <ctime>
    #include <cstdlib>
    #include <map>
    #include <set>
    using namespace std;
    #pragma comment(linker, "/sTACK:1024000000,1024000000")
    #define lowbit(x) (x&(-x))
    #define max(x,y) (x>=y?x:y)
    #define min(x,y) (x<=y?x:y)
    #define MAX 100000000000000000
    #define MOD 1000000007
    #define pi acos[j](-1.0)
    #define ei exp(1)
    #define PI 3.1415926535
    #define ios() ios[j]::sync_with_stdio(true)
    #define INF 1044266558
    #define mem(a) (memset(a,0,sizeof(a)))
    typedef long long ll;
    int dp[1000006],a[1000006],x;
    int main()
    {
        int n=0;
        while(scanf("%d",&x)!=EOF)
        {
            if(x>=10000)
            {
                for(int i=0;i<5;i++)
                    a[++n]=x-10000;
            }
            else if(x>=0) a[++n]=x;
        }
        memset(dp,62,sizeof(dp));
        for(int i=1;i<=n;i++)
            dp[upper_bound(dp,dp+1000000,a[i])-dp]=a[i];
        printf("%d
    ",lower_bound(dp,dp+1000000,INF)-dp);
        return 0;
    }

    M. Frequent Subsets Problem

     

    Output Format

    The number of αalphaα-frequent subsets.

    样例输入

    15 0.4
    1 8 14 4 13 2
    3 7 11 6
    10 8 4 2
    9 3 12 7 15 2
    8 3 2 4 5

    样例输出

    11


    暴力枚举子集

    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <cstdlib>
    #include <iomanip>
    #include <cmath>
    #include <cassert>
    #include <ctime>
    #include <cstdlib>
    #include <map>
    #include <set>
    using namespace std;
    #pragma comment(linker, "/sTACK:1024000000,1024000000")
    #define lowbit(x) (x&(-x))
    #define max(x,y) (x>=y?x:y)
    #define min(x,y) (x<=y?x:y)
    #define MAX 100000000000000000
    #define MOD 1000000007
    #define pi acos[j](-1.0)
    #define ei exp(1)
    #define PI 3.1415926535
    #define ios() ios[j]::sync_with_stdio(true)
    #define INF 1044266558
    #define mem(a) (memset(a,0,sizeof(a)))
    typedef long long ll;
    int n,val[55],x,k;
    double f;
    char ch;
    int main()
    {
        scanf("%d%lf",&n,&f);
        k=0;
        while(~scanf("%d%c",&x,&ch))
        {
            val[k]+=(1<<(x-1));
            if(ch=='
    ') k++;
        }
        int ans=0,cnt;
        int pos=ceil(f*k);
        for(int i=1;i<(1<<n);i++)
        {
            cnt=0;
            for(int j=0;j<k;j++)
            {
                if((i&val[j])==i) printf("%d %d
    ",i,val[j]),cnt++;
            }
            ans+=cnt>=pos?1:0;
        }
        printf("%d
    ",ans);
        return 0;
    }
  • 相关阅读:
    简单验证码实现(Ajax)
    JS获取地址栏参数
    【转】将datatable数据转化成list
    【转】 GridView 72般绝技
    【转】AspNetPager分页控件用法
    【转】 js怎么区分出点击的是鼠标左键还是右键?
    Django~Databases
    Django~static files
    Python—>Mysql—>Dbvisualizer
    含中文数字的名称排序
  • 原文地址:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/7591655.html
Copyright © 2020-2023  润新知