实在看不明白题目的"ring road"和"The distance along the ring road is the length of the shortest way all points of which belongs to the ring road"是什么意思,只好根据样例猜一下了。
  感觉ring road就是一条直的路,然后终点那里有个传送点,会把人直接传送到起点。要求的东西就是这个人最后的位置跟起点的距离。
  L小数点后最多4位,可以把它乘以10000,变成整数,这样就可以用模运算了。
  Submit 1: WA on 2。s/10000应该改成s/10000.0,否则做的是整除。
  Submit 2: WA on 8。改了一下混乱的结构,没发现问题所在。明白为什么是"ring road"了,"起点"和"终点"是在一起的,所以最后求的是这个人的位置跟"起点"和"终点"的距离的较小值。
  Submit 3: WA on 4。求成较大值了。
  Submit 4: WA on 8。看了一下标程,发现他是这样将L转成整数的:(int)(l * 10000 + 0.5),很不明白"+0.5"是做什么用的,我在我的程序里+0.5,果然AC了。
  Submit 5: AC。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <cstdio>
using namespace std;
 
int main()
{
    int L,N,V,T;
    int s=0;
    double l;
    scanf("%lf %d",&l,&N);
    L=static_cast<int>(l*10000+0.5);
    for (int i=0;i<N;i++)
    {
        scanf("%d %d",&T,&V);
        s=(s+static_cast<long long>(V)*T*10000%L)%L;
    }
    if (L-s<s) s=L-s;
    printf("%.4lf\n",s/10000.0);
    return 0;
}