• poj 1065 Wooden Sticks 贪心


    题目链接:http://poj.org/problem?id=1065

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1051

    贪心 先按l升序再按w稳定升序

    然后从头扫到尾取可以取的

    然后再从头 直到全部取完

    一年前第一次写这道题的时候写了两百行Orz 其中有70行归并排序自己手敲 

    刚刚翻看老代码真是感慨...

    #include <cstdio>
    #include <cstdlib>
    #include <ctime>
    #include <iostream>
    #include <cmath>
    #include <cstring>
    #include <algorithm>
    #include <stack>
    #include <set>
    #include <queue>
    #include <vector>
    
    using namespace std;
    
    typedef long long ll;
    
    const int maxn = 5100;
    const double eps = 1e-7;
    
    struct Node
    {
        int x, y;
        bool operator < (const Node &s) const
        {
            if(x == s.x)
                return y < s.y;
            else
                return x < s.x;
        }
    }a[maxn];
    
    int flag[maxn];
    
    int main()
    {
        //freopen("in.txt", "r", stdin);
    
        int T;
        scanf("%d", &T);
        while(T--)
        {
            int ans = 0;
            memset(flag, 0, sizeof(flag));
    
            int n;
            scanf("%d", &n);
            for(int i = 0; i < n; i++)
                scanf("%d%d", &a[i].x, &a[i].y);
    
            sort(a, a + n);
    
            int cnt = 0;
            while(cnt < n)
            {
                ans++;
                int pre_x = -1000000;
                int pre_y = -1000000;
                for(int i = 0; i < n; i++)
                {
                    if(!flag[i])
                    {
                        if(a[i].x >= pre_x && a[i].y >= pre_y)
                        {
                            pre_x = a[i].x;
                            pre_y = a[i].y;
                            cnt++;
                            flag[i] = 1;
                        }
                    }
                }
            }
    
            printf("%d
    ", ans);
        }
    
        return 0;
    }
  • 相关阅读:
    java多线程
    异常处理
    mabits
    梦想改造家之全世界最治愈的家浅析
    Activity
    java基础终稿
    Visual Studio Codes配置vs2017编译
    2017-2018-2 20179216 《网络攻防与实践》SM234算法
    2017-2018-2 20179216 《网络攻防与实践》 免杀技术
    2017-2018-2 20179216 《网络攻防与实践》 SQL注入攻击
  • 原文地址:https://www.cnblogs.com/dishu/p/4302252.html
Copyright © 2020-2023  润新知