zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    百度脑图
    Bootstrap入门
    Tomcat热部署的三种方式
    There is a chart instance already initialized on the dom!警告
    Ubuntu14.04设置开机自启动脚本
    PRM路径规划算法
    A*算法
    V-rep学习笔记:串口操作
    V-rep学习笔记:机器人路径规划2
    V-rep学习笔记:机器人逆运动学解算
  • 原文地址:https://www.cnblogs.com/dishu/p/4302252.html
Copyright © 2011-2022 走看看