zoukankan      html  css  js  c++  java
  • 【例题 8-4 UVA

    【链接】 我是链接,点我呀:)
    【题意】

    在这里输入题意

    【题解】

    显然把问题分解成两个子问题。 x轴和y轴分别做。 即n个点要求第i个点在[li,ri]范围内。(ri<=n) 问是否可行.

    按左端点、右端点排。尽量取左边的方法是错的。
    hack数据:(1,1),(1,3),(2,2)
    在安排idx=2的时候,优先用了(1,3)这个区间。导致原本3可以放的。现在放不了了。

    所以我们的方法就是。
    对于第i个点。
    找一个能包含它。
    但是右端点又尽量小的区间。
    这样,能保证这个选取的区间尽量不影响到后面的点的选取。
    (而前面的点无所谓,因为已经安排完了
    O(N^2)的复杂度找这样的区间就可以了。

    如果数据大的话。
    可以考虑用set来处理:比如区间[li,ri]
    则可以在li的位置插入一个数据ri
    当ri<idx的时候,则在set中把ri去掉。
    否则每次都找set中最小的ri.把它删掉。

    【代码】

    /*
      	1.Shoud it use long long ?
      	2.Have you ever test several sample(at least therr) yourself?
      	3.Can you promise that the solution is right? At least,the main ideal
      	4.use the puts("") or putchar() or printf and such things?
      	5.init the used array or any value?
      	6.use error MAX_VALUE?
      	7.use scanf instead of cin/cout?
      	8.whatch out the detail input require
    */
    /*
        一定在这里写完思路再敲代码!!!
    */
    #include <bits/stdc++.h>
    using namespace std;
    
    const int N = 5000;
    
    vector < pair<int,pair<int,int> > > v1,v2;
    int n;
    int x[N+10],y[N+10];
    
    bool ok(vector<pair<int,pair<int,int> > > v,int ju){
        for (int i = 1;i <= n;i++){
            int mi = 100000;
            __typeof v.begin() idx;
            for (auto j = v.begin();j!=v.end();j++){
                auto temp = *j;
                if (temp.first<=i && i<=temp.second.first){
                    if (temp.second.first<mi){
                        mi = temp.second.first;
                        idx = j;
                    }
                }
            }
            if (mi==100000) return false;
            if (ju==0){
                x[(*idx).second.second] = i;
            }else{
                y[(*idx).second.second] = i;
            }
            v.erase(idx);
        }
        return true;
    }
    
    int main(){
    	#ifdef LOCAL_DEFINE
    	    freopen("rush_in.txt", "r", stdin);
    	#endif
    	ios::sync_with_stdio(0),cin.tie(0);
        while (cin >>n && n){
            v1.clear(),v2.clear();
            for (int i = 1;i <= n;i++){
                int xl,yl,xr,yr;
                cin >> xl >> yl >> xr >> yr;
                v1.push_back({xl,{xr,i}});
                v2.push_back({yl,{yr,i}});
            }
            if (ok(v1,0)&&ok(v2,1)){
                for (int i = 1;i <= n;i++)
                    cout << x[i] <<' '<<y[i]<<endl;
            }else{
                cout <<"IMPOSSIBLE"<<endl;
            }
        }
    	return 0;
    }
    
  • 相关阅读:
    JS正则改变字符之间文字
    MySQL 实现字符串换行
    日志AOP的实现
    mysql in和exists性能比较和使用
    【微服务】使用spring cloud搭建微服务框架,整理学习资料
    专注细节,回归本质,成败在微小之间
    【前端】 在前端利用数学函数知识+box-shadow解波浪图形
    互联网行业个人精进指南
    拒绝洗脑式广告,无限重复洗脑式广告应该受到谴责。怎么有效抵制这类广告?
    【redis】redis应用场景,缓存的各种问题
  • 原文地址:https://www.cnblogs.com/AWCXV/p/8182157.html
Copyright © 2011-2022 走看看