Wooden Sticks(贪心)

Wooden Sticks.

win the wooden spoon:成为末名。

题目地址:http://poj.org/problem?id=1065

There is a pile of n wooden sticks.

a woodworking machine:木工机器。

setup time:启动时间。

my codes:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int t,n;
struct stick
{
	int l,w;
}sti[5100];
bool used[5100];
bool cmp(stick a,stick b)
{
	return (a.l<b.l)||(a.l==b.l && a.w<b.w);
}

int main()
{
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		for(int i=0;i<n;i++) scanf("%d%d",&sti[i].l,&sti[i].w);
		sort(sti,sti+n,cmp);

		memset(used,false,sizeof(used));
		int ans=0;
		for(int i=0;i<n;i++)
		{
			if(!used[i])
			{
				ans++;
				int tempW=sti[i].w;
				for(int j=i+1;j<n;j++)
				{
					if(!used[j] && sti[j].w>=tempW)
						used[j]=true,tempW=sti[j].w;
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Ref:https://blog.csdn.net/u012278856/article/details/32914859

原文地址:https://www.cnblogs.com/dragondragon/p/11372378.html

时间: 2024-11-08 23:19:04

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): 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

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

POJ 1065. Wooden Sticks 贪心 结构体排序

Wooden Sticks Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19992   Accepted: 8431 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 woodworkin

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 Wooden Sticks (贪心)

Wooden Sticks Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 19   Accepted Submission(s) : 7 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description There is a pile of n woo

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> #

POJ 1065 Wooden Sticks#贪心+qsort用法

(- ̄▽ ̄)-* 这道题用到了cstdlib库的qsort()函数: 用法链接:http://www.cnblogs.com/syxchina/archive/2010/07/29/2197382.html #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cstdlib> using namespace std; struct s