TOJ 2988.PLMM

来源:互联网 发布:网络的利与弊征文1000 编辑:程序博客网 时间:2024/06/05 05:48

题目链接 : http://acm.tju.edu.cn/toj/showp2988.html

WCM and ZHC like watching PLMM (beautiful girl). One day they are going to FengHua dining-room for lunch from the second teaching building. You know, there is a straight road lined by many beautiful ginkgos between FengHua dining-room and the second teaching building. WCM and ZHC will not miss this good chance for watching PLMM.
Now they want to know how many PLMM on the road they can meet before they reach FengHua dining-room namely, the end of the road. Assume that they know the position and walking speed of every PLMM on the road at the moment they start.
They think they meet a PLMM if and only if at some time, they and the PLMM are at the same position of the road.
······

这个题虽然很水,但是却很有意思,一方面读题的时候起先以为PLMM是个什么美女相关的节目,继续往下读发现这道题就是两个猥琐男在去食堂的路上看美女,求看了多少美女,于是也恍然大悟,明白了PLMM什么意思。。。又联想到好多同学也有相似的癖好,不禁笑了笑。
言归正传,这道题就是一个相遇问题,很简单,自己写的特别繁琐,其实看了大神的代码发现:
1. 不需要开数组,因为每个美女计算一次就好
2. 所有的情况都可以归结为一条判断if(p*w<=l*(w-s)),也就是说做题时最好先考虑一般情况,然后再进行边界测试,这样可能代码稍短一些,当然,我是先考虑各种可能情况,一一排除,如果不严谨可能导致没有必要的判断。

#include <stdio.h>using namespace std;int main(){    int cast,sum;    double n,l,w,s[10002],p[10002];    scanf("%d",&cast);    for(int k=0;k<cast;k++){        sum=0;        scanf("%lf%lf%lf",&n,&l,&w);        for(int i=0;i<n;i++)            scanf("%lf%lf",&p[i],&s[i]);        for(int i=0;i<n;i++){            if(s[i]<=0){                sum++;                continue;               }            else if(p[i]==0){                sum++;                continue;            }            else if(p[i]*s[i] <= (l-p[i])*(w-s[i])){                sum++;                continue;            }        }        printf("%d\n",sum);    }}
0 0
原创粉丝点击