HPU 1720: Thanksgiving Day KK Session--Interview problem greedy

Source: Internet
Author: User
Tags time limit
1720: Thanksgiving Day KK Session--Interview problemTime limit: 1 Sec memory limit: MB
Submissions: 303 Resolution: 44
Submitted State [Discussion Version] Title Description

There are n people to interview the student Union XX Department, the interview process to ask any two of the time between the interviewer can not overlap. It is known how many people can be interviewed by the time the N interviewers arrive and the time they need to interview. XX of the department is a good friend of KK, and now he is looking for KK to help. But KK is very busy, please help KK. Time overlaps such as [1, 3] [2, 4] or [1, 3][3, 4]. input

Given an integer t, indicates that there is a T (t<=100) Group of test data. Each set of test data has an integer n (0<=n<=1000), followed by two integers per line s[i],t[i], indicating the time of the first interview and the time required for the interview. Output

Each line outputs an integer that represents the maximum number of people that can be interviewed. Sample Input

1
1 
1 0
Sample Output
1
Tips

Source

Kk

Ac-code:

#include <cstdio>
#include <algorithm>
using namespace std;
struct node
{
	int st,e;
} S[1005];
BOOL CMP (node A,node b)
{
	return a.e<b.e;
}
int main ()
{
	int t,n,i,a,ans,b;
	scanf ("%d", &t);
	while (t--)
	{
		scanf ("%d", &n);
		if (n==0)
		{
			printf ("0\n");
			Continue;
		 } 
		for (i=0;i<n;i++)
		{
			scanf ("%d%d", &s[i].st,&b);
			s[i].e=s[i].st+b;
		}
		Sort (s,s+n,cmp);
		A=S[0].E;
		Ans=1;
		for (i=1;i<n;i++)
			if (s[i].st>a)
			{
				ans++;
				A=S[I].E;
			}
		printf ("%d\n", ans);
	}
	return 0;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.