算法-C/C++杭电1501题Wooden sticks 求挑错

问题描述

C/C++杭电1501题Wooden sticks 求挑错
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 (49) (52) (21) (35) and (14) then the minimum setup time should be 2 minutes since there is a sequence of pairs (14) (35) (49) (21) (52).

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

#include
#include

using namespace std;

struct stick
{
int len;
int wei;
bool judge;
}s[10009];

int cmp(stick astick b)
{
if(a.len!=b.len)
return a.len else
return a.wei}
int main()
{
int Tnijtime;
cin>>T;
while(T--)
{
cin>>n;
for(i=0;i {
cin>>s[i].len>>s[i].wei;
s[i].judge=true;
}
sort(ss+ncmp);
time=0;
int flag_len=s[0].lenflag_wei=s[0].weinum;
for(i=0;i {
if(s[i].judge==false)continue;
for(j=inum=0;j {
if(s[j].len>=flag_len&&s[j].wei>=flag_wei)
{
s[j].judge=false;
num++;
}
}
if(num)time++;
for(j=i+1;j<n;j++)
{
if(s[j].judge==true)
{
flag_len=s[j].len;
flag_wei=s[j].wei;
break;
}
}
}
cout<<time<<endl;
}
return 0;
}

解决方案

http://blog.csdn.net/lishuhuakai/article/details/8117251

时间: 2024-08-04 05:38:36

算法-C/C++杭电1501题Wooden sticks 求挑错的相关文章

杭电oj2000题, c语言,我的程序不对,那应该是什么样子的

问题描述 杭电oj2000题, c语言,我的程序不对,那应该是什么样子的 #include "stdio.h" int main() { char max,x,y,z; scanf("%c%c%c",&x,&y,&z); while( scanf(%c%c%c,&x,&y,&z)!=EOF) { if( 'x'>'y' ) if( 'y'>'z') printf("%c %c %cn",

杭电3555题 为啥总是Output Limit Exceeded

问题描述 杭电3555题 为啥总是Output Limit Exceeded 3555 这是我的代码: #include #include #include #include #include #include #include #include #include #include using namespace std; long long f[20][3]; long long cal(long long n) { long long num[20],len=1,i,j,k,sum,flag

杭电53A题,实在不知道哪里错了,想让大神们帮忙看一下,代码错到11组

问题描述 杭电53A题,实在不知道哪里错了,想让大神们帮忙看一下,代码错到11组 #include <stdio.h>#include <string.h>#include <algorithm>using namespace std;struct xx{ char qq[101];}x[101];int cmp(const void *x const void *y){ struct xx x1 = *(struct xx *)x; struct xx y1 = *(

测试-杭电c入门简单问题 求指导一下

问题描述 杭电c入门简单问题 求指导一下 题目如下输入n(n<=100)个整数,按照绝对值从大到小排序后输出.题目保证对于每一个测试实例,所有的数的绝对值都不相等. Input输入数据有多组,每组占一行,每行的第一个数字为n接着是n个整数,n=0表示输入数据的结束,不做处理. Output对于每个测试实例,输出排序后的结果,两个数之间用一个空格隔开.每个测试实例占一行. Sample Input3 3 -4 24 0 1 2 -30 Sample Output-4 3 2-3 2 1 0 Aut

杭电oj第一题居然一直过不了

问题描述 杭电oj第一题居然一直过不了 #include "stdio.h" int main() { int a,b; scanf("%d%d",&a,&b); printf("%d ",a+b); return 0; } 运行不是好好的吗,怎么总是过不了 解决方案 杭电OJ第十五届ACM第一题 Hearthstone杭电第一题 解决方案二: 检查一下自己的输入输出格式 解决方案三: (a+b)呢,....

c-把我原来做的杭电AC代码改成C竟然出错了是怎么回事啊

问题描述 把我原来做的杭电AC代码改成C竟然出错了是怎么回事啊 今天又重新看了下之前做的杭电ACM题,遇到一个问题,求大神解决下.我原来是用C++做的,今天我只是把C++改成了C,就出错了,是怎么回事啊! 杭电2008 题目:http://acm.hdu.edu.cn/showproblem.php?pid=2008 C #include int main() { int n; while(scanf("%d",&n)) { if(n==0) break; double a[n

java-杭电acm1106为什么就是WA求解释,看了大牛的思想,结果输出正确

问题描述 杭电acm1106为什么就是WA求解释,看了大牛的思想,结果输出正确 排序 Problem Description 输入一行数字,如果我们把这行数字中的'5'都看成空格,那么就得到一行用空格分割的若干非负整数(可能有些整数以'0'开头,这些头部的'0'应该被忽略掉,除非这个整数就是由若干个'0'组成的,这时这个整数就是0). 你的任务是:对这些分割得到的整数,依从小到大的顺序排序输出. Input 输入包含多组测试用例,每组输入数据只有一行数字(数字之间没有空格),这行数字的长度不大于

c语言-杭电oj 2014题 代码不对 不知道哪里错了

问题描述 杭电oj 2014题 代码不对 不知道哪里错了 偶数求和 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 65195 Accepted Submission(s): 27929 Problem Description 有一个长度为n(n<=100)的数列,该数列定义为从2开始的递增有序偶数,现在要求你按照顺序每m个数求出一个平均值,

算法-最近点对问题,我用分治写的,和正确的基本一样为什么我的会超时?杭电1007

问题描述 最近点对问题,我用分治写的,和正确的基本一样为什么我的会超时?杭电1007 高手帮忙看看,已经弄了很长时间了还是看不出来哪里有问题,感觉写得和网上的一样呀. #include<iostream>#include<cmath>using namespace std;void kuaipai(double* double* int int);double zuijindian(double* double* int int);double x[100000] y[100000