2 条题解

  • 0
    @ 2025-10-8 17:01:53

    by hansang:

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    const int N=1e4+10;
    double t[N], d[N];
    int main(){
        int n; scanf("%d", &n);
        int len1=0, len2=0;
        for(int i=1; i<=n; i++){
            char s[5]; double x;
            scanf("%s%lf", s, &x);
            if(s[0]=='T') t[++len1]=x;
            else d[++len2]=x;
        }
        sort(t+1, t+len1+1); sort(d+1, d+len2+1);
        double tmp=0, dis=0, sum=1; int p1=1, p2=1;
        while(p1<=len1 || p2<=len2){
            if((p2>len2) || ((t[p1]-tmp)<(d[p2]-dis)*sum && p1<=len1)){
                dis+=(t[p1]-tmp)/sum;
                tmp=t[p1]; p1++;
            }
            else{
                tmp+=(d[p2]-dis)*sum;
                dis=d[p2]; p2++;
            }
            sum++;
        }
        printf("%.0lf\n", tmp+(1000-dis)*(sum));
        return 0;
    }
    
    • 0
      @ 2025-10-8 17:01:41

      by hansang:

      #include<bits/stdc++.h>
      using namespace std;
      typedef long long LL;
      const int N=1e4+10;
      double t[N], d[N];
      int main(){
          int n; scanf("%d", &n);
          int len1=0, len2=0;
          for(int i=1; i<=n; i++){
              char s[5]; double x;
              scanf("%s%lf", s, &x);
              if(s[0]=='T') t[++len1]=x;
              else d[++len2]=x;
          }
          sort(t+1, t+len1+1); sort(d+1, d+len2+1);
          double tmp=0, dis=0, sum=1; int p1=1, p2=1;
          while(p1<=len1 || p2<=len2){
              if((p2>len2) || ((t[p1]-tmp)<(d[p2]-dis)*sum && p1<=len1)){
                  dis+=(t[p1]-tmp)/sum;
                  tmp=t[p1]; p1++;
              }
              else{
                  tmp+=(d[p2]-dis)*sum;
                  dis=d[p2]; p2++;
              }
              sum++;
          }
          printf("%.0lf\n", tmp+(1000-dis)*(sum));
          return 0;
      }
      • 1

      USACO(32)队列1:失误的滑雪P2338 [USACO14JAN] Bessie Slows Down S

      信息

      ID
      2629
      时间
      1000ms
      内存
      128MiB
      难度
      9
      标签
      递交数
      10
      已通过
      4
      上传者