Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

WA了一下午了,实在是觉得不可能有问题了还是WA,哪位帮忙看看,谢谢了

Posted by newpoo at 2007-04-18 17:28:41 on Problem 1634
#include <set>
#include <algorithm>
#include <functional>

using namespace std;

const int MAXN = 30000;

struct Person
{
  int ID, salary, height;
};


struct CompSalary : public binary_function<bool, const Person &, const Person &>
{
  bool operator()(const Person & p1, const Person & p2)
  {
    return p1.salary < p2.salary;
  }
};

struct CompID : public binary_function<bool, const Person &, const Person &>
{
  bool operator()(const Person & p1, const Person & p2)
  {
    return p1.ID < p2.ID;
  }
};

Person persons[MAXN];
Person personsT[MAXN];

int main(void)
{
  int n, m, q, i, num, id;
  Person t, * p, * p1, * p2;
  scanf("%d", &n);



  while(n--)
    {
      scanf("%d%d", &m, &q);
      for(i = 0; i < m; ++i)
	{
	  scanf("%d%d%d", &persons[i].ID, &persons[i].salary, &persons[i].height);
	  personsT[i] = persons[i];
	}
      sort(persons, persons+m, CompID());
      sort(personsT, personsT+m, CompSalary());

      while(q--)
	{
	  scanf("%d", &t.ID);
	  p = lower_bound(persons, persons+m, t, CompID());
	  t.salary = p->salary;
	  p = lower_bound(personsT, personsT+m, t, CompSalary());
	  num = id = 0;
	  for(p1 = personsT; p1 != p; ++p1)
	    {
	      if(p1->height <= p->height)
		++num;
	    }
	  if(p != personsT + m - 1)
	    {
	      for(p1 = p + 1; true; ++p1)
		if(p1->height >= p->height)
		  {
		    id = p1->ID;
		    break;
		  }
	    }
	  printf("%d %d\n", id, num);
	}
    }
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator