zoukankan      html  css  js  c++  java
  • UPC-窗口

    题目描述
    在当今流行的操作系统中,我们要对许许多多的窗口进行操作,屏幕上的每个窗口都是由许多单位为 1 的小方块构成的矩形窗,较晚打开的窗口会将一些早期打开的窗口覆盖。我们可以用鼠标单击一个窗口的右上角的小方块将该窗口关闭,前提是该窗口的右上角的小方块必须是看得见的。
    写一个程序计算一下如果我们要关闭最早打开的那个窗口,最少需要按几下鼠标(关闭窗口的方法只能靠点击该窗口右上角的小方块实现)
    输入
    第一行,一个整数N,表示窗口的总数,其中1≤N≤100;
    在接下来的N行中每一行都有4个用空格隔开的整数R1、S1、R2、S2,其中1≤R1≤R2≤10000,1≤S1≤S2≤10000。R1,S1为窗口的左上角坐标,R2、S2为窗口的右下角坐标,窗口打开的次序就是数据给出的次序。
    输出
    仅一行,包含一个整数表示关闭第一个窗口需要的鼠标最少点击几次。
    样例输入
    3
    3 1 6 4
    1 2 4 6
    2 3 5 5
    样例输出
    3
    思路发源地:传送门
    这是一类递归的问题:
    要想关闭第一个窗口,就要关闭这个窗口上面的窗口,要想关闭上面的这个窗口就需要关闭覆盖这个窗口的窗口,以此类推,可见递归的特性

    #include <iostream>
    #include <algorithm>
    #include <map>
    #include <queue>
    #include <set>
    #include <stack>
    #include <string>
    #include <vector>
    using namespace std;
    #define wuyt main
    typedef long long ll;
    #define HEAP(...) priority_queue<__VA_ARGS__ >
    #define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > >
    template<class T> inline T min(T &x,const T &y){return x>y?y:x;}
    template<class T> inline T max(T &x,const T &y){return x<y?y:x;}
    ///#define getchar()(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
    ///char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
    ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();
    if(c == '-')Nig = -1,c = getchar();
    while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();
    return Nig*x;}
    #define read read()
    const ll inf = 1e15;
    const ll INF = 0x3f3f3f3f;
    const int maxn = 2e5 + 7;
    const int mod = 1e9 + 7;
    ll gcd(ll a,ll b)
    {
        ll t;
        while(b!=0)
        {
            t=a%b;
            a=b;
            b=t;
        }
        return a;
    }
    ll qPow(ll x, ll k)
    {
        ll res = 1;
        while(k) {
            if(k&1)
                res=(res*x);
            k>>=1;
            x=(x*x);
        }
        return res;
    }
    ll maxx=-1,n,flag;
    ll res,ans=1;
    struct node{
        int x1,y1;
        int x2,y2;
        int jud;
    }point[maxn];
    void DFS(int t){
    ///这里有点迷惑,左上角是x1,y1 右下角是x2,y2 那么右上角不应该是x2,y1?
    ///事实是x1,y2可以过x2,y1过不了
        int aimx=point[t].x1;
        int aimy=point[t].y2;///找到当前的横纵坐标
        for(int i=t+1;i<=n;i++){
            if(point[i].jud==1) continue;///已经关了
            int min_x,max_x,min_y,max_y;
            min_x=min(point[i].x1,point[i].x2);
            max_x=max(point[i].x1,point[i].x2);///找覆盖范围
            min_y=min(point[i].y1,point[i].y2);
            max_y=max(point[i].y1,point[i].y2);
            ///确定是否在范围内
            if(aimx>=min_x&&aimx<=max_x&&aimy>=min_y&&aimy<=max_y){
                ans++;
                point[i].jud=1;
                DFS(i);
            }
        }
    }
    int main()
    {
        n=read;
        /**for(int i=1;i<=n;i++){
            int x1=read,y1=read,x2=read,y2=read;
            point[i].x=x2;
            point[i].y=y1;
        }
        ans=1;
        for(int i=2;i<=n;i++){
            if(point[i].x>=point[1].x&&point[i].y>=point[1].y) ans++;
        }
        cout<<ans<<endl;**/
        for(int i=1;i<=n;i++){
            point[i].x1=read,point[i].y1=read;
            point[i].x2=read,point[i].y2=read;
        }
        DFS(1);
        cout<<ans<<endl;
        return 0;
    }
    
    
    
  • 相关阅读:
    基于python检测端口是否在使用
    一行CMD命令kill(杀)掉你的进程
    Python 线程与进程
    Linux07 文件查找(locate、find )及特殊权限(SUID、SGID、Sticky)
    Linux06 vim文本编辑器的使用
    Linux04 shell编程1
    Linux03 重定向,管道,文件查找(grep)
    Linux02(目录、文件、用户、用户组管理)
    Linux01
    pytest装饰器
  • 原文地址:https://www.cnblogs.com/PushyTao/p/13144149.html
Copyright © 2011-2022 走看看