HDU1051&&HDU1050

Wooden Sticks

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 9999    Accepted Submission(s): 4108




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 prepare processing a stick. The setup times are associated with cleaning operations and changing tools and shapes in the machine. The setup times of the woodworking machine are given as follows:

(a) The setup time for the first wooden stick is 1 minute.
(b) Right after processing a stick of length l and weight w , the machine will need no setup time for a stick of length l' and weight w' if l<=l' and w<=w'. Otherwise, it will need 1 minute for setup.

You are to find the minimum setup time to process a given pile of n wooden sticks. For example, if you have five sticks whose pairs of length and weight are (4,9), (5,2), (2,1), (3,5), and (1,4), then the minimum setup time should be 2 minutes since there is a sequence of pairs (1,4), (3,5), (4,9), (2,1), (5,2).
 

Input
The input consists of T test cases. The number of test cases (T) is given in the first line of the input file. Each test case consists of two lines: The first line has an integer n , 1<=n<=5000, that represents the number of wooden sticks in the test case, and the second line contains n 2 positive integers l1, w1, l2, w2, ..., ln, wn, each of magnitude at most 10000 , where li and wi are the length and weight of the i th wooden stick, respectively. The 2n integers are delimited by one or more spaces.
 

Output
The output should contain the minimum setup time in minutes, one per line.
 

Sample Input
  
  
3 5 4 9 5 2 2 1 3 5 1 4 3 2 2 1 1 2 2 3 1 3 2 2 3 1
 

Sample Output
  
  
2 1 3 大意:每做一个木棍要1分钟,但是当前你做的木棍的长度比后者要短且重量比后者要小,则可以不用再去花一分钟做那根木棍,否则就得继续加一分钟做,求给你N根木棍的 长和重,求最短时间。 思路:贪心,按照长度由小到大排序,相等者按照重量由小到大排序,然后顺序查一遍统计一次就O了。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;

struct node{
int l;
int w;
bool vis;
}s[100005];

bool cmp(node a,node b)
{
    if(a.l<b.l)
        return true;
        else
            if(a.l==b.l)
             return a.w<b.w;
    else
        return false;
}

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int ans=0;
        int i;
        for(i=0;i<n;i++)
        {
            cin>>s[i].l>>s[i].w;
            s[i].vis=0;
        }
        sort(s,s+n,cmp);
        for(i=0;i<n;i++)
        {
            if(s[i].vis==0)
            {
                s[i].vis=1;
                ans++;
                int weight=s[i].w;
                for(int j=i+1;j<n;j++)
                {
                    if(s[j].vis==0&&s[j].w>=weight)
                    {
                        s[j].vis=1;
                        weight=s[j].w;

                    }
                }
            }
        }
        cout<<ans<<endl;
    }



}

Moving Tables

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 16588    Accepted Submission(s): 5681


Problem Description
The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure.



The floor has 200 rooms each on the north side and south side along the corridor. Recently the Company made a plan to reform its system. The reform includes moving a lot of tables between rooms. Because the corridor is narrow and all the tables are big, only one table can pass through the corridor. Some plan is needed to make the moving efficient. The manager figured out the following plan: Moving a table from a room to another room can be done within 10 minutes. When moving a table from room i to room j, the part of the corridor between the front of room i and the front of room j is used. So, during each 10 minutes, several moving between two rooms not sharing the same part of the corridor will be done simultaneously. To make it clear the manager illustrated the possible cases and impossible cases of simultaneous moving.



For each room, at most one table will be either moved in or moved out. Now, the manager seeks out a method to minimize the time to move all the tables. Your job is to write a program to solve the manager’s problem.
 

Input
The input consists of T test cases. The number of test cases ) (T is given in the first line of the input. Each test case begins with a line containing an integer N , 1<=N<=200 , that represents the number of tables to move. Each of the following N lines contains two positive integers s and t, representing that a table is to move from room number s to room number t (each room number appears at most once in the N lines). From the N+3-rd line, the remaining test cases are listed in the same manner as above.
 

Output
The output should contain the minimum time in minutes to complete the moving, one per line.
 

Sample Input
     
     
3 4 10 20 30 40 50 60 70 80 2 1 3 2 200 3 10 100 20 80 30 50
 

Sample Output
     
     
10 20 30
 
题意:每从起点到终点搬一次东西要十分钟(和后面的过道没有重复的情况),然后求N次搬东西最少要多久,问题转化为求N次搬运的过程中,经过某个过道的最大值就O了。

第一份代码是我的- -第二份是DL的- -|||
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
    int a[405];
    int ans[205];
    int i,j=0;
    for(i=1;i<=400;i++)
    {
        if(i%2==1)
            j++;
        a[i]=j;
    }//预处理过道
    int t;
    cin>>t;
    while(t--)
    {
        memset(ans,0,sizeof(ans));
        int n;
        cin>>n;
        int s,t;
       while(n--)
        {
            cin>>s>>t;
            if(s>t)
                swap(s,t);
            for(i=a[s];i<=a[t];i++)
            {
                ans[i]++;
                //cout<<ans[i]<<endl;
            }
        }
        int sum=0;
        for(i=1;i<=200;i++)
        {
            if(sum<ans[i])
                sum=ans[i];
        }
        cout<<sum*10<<endl;
    }
    return 0;

}
/********************************************************************************************************************/
#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
    int T,n,s,t,m[1000],i,j,a;
    cin>>T;
    while(T--)
    {
        for(i=0;i<1000;i++)
        {
            m[i]=0;
        }
        a=0;
        cin>>n;
        for(i=0;i<n;i++)
        {
            cin>>s>>t;
            if(s>t)
                swap(s,t);//如果是从大房间搬到小房间 交换处理
            for(j=(s+1)/2;j<=((t+1)/2);j++)
            {
                m[j]+=1;//统计经过过道次数的数组
                if(m[j]>a)
                    a=m[j];
            }
        }

        cout<<a*10<<endl;
    }
    return 0;
}






评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值