uva live-2322 - Wooden Sticks

首先排个序,然后找一次0花费,然后再找一次0花费,然后再找一次0花费,然后再找一次0花费.........

最后看找了几次,+1就是答案

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<vector>
using namespace std;
struct node
{
    int l,w;
    friend istream & operator >>(istream &is,node &a)
    {
        is>>a.l>>a.w;
        return is;
    }
};
bool cmp(node a,node b)
{
    return a.l!=b.l?a.l<b.l:a.w<b.w;
}
bool operator <=(node a,node b)
{
    return a.l<=b.l&&a.w<=b.w;
}
int main()
{
    //freopen("in","r",stdin);
    node box[5010];
    bool vis[5010];
    int ans,i,n,j,T;
    node p;
    cin>>T;
    while(T--)
    {
        cin>>n;
        for(i=0;i<n;i++)
            cin>>box[i];
        ans=1;
        memset(vis,0,sizeof(vis));
        sort(box,box+n,cmp);
        p=box[0];
        for(i=0;i<n;i++)
        {
            if(vis[i])
                continue;
            if(!(p<=box[i]))
                ans++;
            p=box[i];
            for(j=i+1;j<n;j++)
            {
                if(vis[j])
                    continue;
                if(p<=box[j])
                {
                    p=box[j];
                    vis[j]=1;
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}
时间: 2024-10-15 23:57:33

uva live-2322 - Wooden Sticks的相关文章

HDU 1051:Wooden Sticks

Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 11605    Accepted Submission(s): 4792 Problem Description There is a pile of n wooden sticks. The length and weight of each stick a

Wooden Sticks POJ - 1065

There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a woodworking machine in one by one fashion. It needs some time, called setup time, for the machine to prepare processing

HDU 1051 Wooden Sticks 贪心||DP

Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 22000    Accepted Submission(s): 8851 Problem Description There is a pile of n wooden sticks. The length and weight of each stick ar

HDU 1051 Wooden Sticks (贪心)

Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 11249    Accepted Submission(s): 4629 Problem Description There is a pile of n wooden sticks. The length and weight of each stick a

ZOJ 1025. Wooden Sticks 贪心 结构体排序

Wooden Sticks Time Limit: 2 Seconds      Memory Limit: 65536 KB There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a woodworking machine in one by one fashion. It needs some

HDOJ 1051. Wooden Sticks 贪心 结构体排序

Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 15564    Accepted Submission(s): 6405 Problem Description There is a pile of n wooden sticks. The length and weight of each stick a

(hdu step 1.3.6)Wooden Sticks(求长度和重量都严格递增的数列的个数)

题目: Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2374 Accepted Submission(s): 921   Problem Description There is a pile of n wooden sticks. The length and weight of each stick are

POJ1065 Wooden Sticks

Wooden Sticks Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 23403   Accepted: 10053 Description There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a woodworki

1051 Wooden Sticks(贪心-3)

Problem Description There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a woodworking machine in one by one fashion. It needs some time, called setup time, for the machine to

SPOJ MSTICK. Wooden Sticks 贪心 结构体排序

MSTICK - Wooden Sticks There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a woodworking machine in one by one fashion. It needs some time, called setup time, for the machine