Problem A
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1088 Accepted Submission(s): 244
Total Submission(s): 1088 Accepted Submission(s): 244
Problem Description
HDU hosts sporting meeting every year. One of the most exciting events is the 10000M-running.During the match many students are running on the track. So, how about the rank list now?
As we know, in a running , we rank the player according to the length everyone has passed . So if one player run 400M(one lap) farther than another player , it looks like they are running at the same position on the track , but the rank of the former is much better than the latter. Now given everyone’s position on the track , and one rank list , can you tell me whether the rank list is possible.
As we know, in a running , we rank the player according to the length everyone has passed . So if one player run 400M(one lap) farther than another player , it looks like they are running at the same position on the track , but the rank of the former is much better than the latter. Now given everyone’s position on the track , and one rank list , can you tell me whether the rank list is possible.
Input
The first line of input gives the number of cases, T (at most 110). the first line of each case has two intergers, n,m. (1 <= n <= 100,1 <= m <= 40000,n <= m),represents there’re n players in the m-meter running.
then n lines describe every player.
Each line have two intergers , Xi , Ri .Representing the i-th player is running at xi[0 , 399] meter in his recent lap, and ranks Ri in the ranklist .And the data make sure that no pair of the students have the same Xi or Ri. And the start point is at 0 in their first lap.
then n lines describe every player.
Each line have two intergers , Xi , Ri .Representing the i-th player is running at xi[0 , 399] meter in his recent lap, and ranks Ri in the ranklist .And the data make sure that no pair of the students have the same Xi or Ri. And the start point is at 0 in their first lap.
Output
If the rank list is possible, output “YES” ,output “NO” otherwise.
SampleInput
2 3 400 100 1 49 2 28 3 3 800 100 1 150 2 154 3
SampleOutput
YES NO
题意:
跑圈 套圈之后合不合法~
第一行为人数和一圈的米数
接下来的几行为以起点为基准相对于起点的位置(米数) 和各个人的名次
题解:先拿名次进行排序(从第一名往后第二名这样依次向后排序) 然后如果前一个名次的人的米数大于第二个的米数 则表示合法 继续向后查找 如果小于前一个人的米数 则后一个人的套圈数加1
最后看最后一个人的套圈数是否大于总可套圈数
代码:
#include <iostream>
#include <algorithm>
using namespace std;
class runner
{
public:
int meter;
int rank;
};
bool cmp(runner n1,runner n2)
{
return n1.rank<n2.rank;
}
int taoquanshu;
int main()
{
int testcase;
cin>>testcase;
while(testcase--)
{
runner pack[115];
int maxroute,yu;
int athlete,distance;
cin>>athlete>>distance;
maxroute=(distance/400)-1;
yu=distance%400;
for(int i=0;i<athlete;i++)
{
cin>>pack[i].meter>>pack[i].rank;
taoquanshu=0;
}
sort(pack,pack+athlete,cmp);
for(int j=0;j<athlete-1;j++)
{
if(pack[j].meter>pack[j+1].meter)
{
continue;
}
else
{
taoquanshu++;
}
}
if((taoquanshu*400+pack[athlete-1].meter)>distance)
{
cout<<"NO"<<endl;
}
else
{
cout<<"YES"<<endl;
}
}
return 0;
}