zoukankan      html  css  js  c++  java
  • 走路——我真傻,真的

    走路

     

    in

    3

    3 2 4

    4 3 4

    3 6 4

     out

    2 2 2

    一个人在t[i]之前不存在, 在走到f[i]之后消失.

    分析:

    我真傻,真的。我一开始分了速度方向相同与不同两种方案,而相同的方案有bug,不同的方案我打的时候却考虑了方向,也就是说,我打的不同的方案的代码就已经覆盖了相同的方案,我对着代码研究了半天,人快傻掉了。。。

    代码:

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<queue>
     6 #include<algorithm>
     7 #include<vector>
     8 using namespace std;
     9 #define debug printf("zjyvegetable
    ")
    10 #define int long long
    11 inline int read(){
    12     int a=0,b=1;char c=getchar();
    13     while(!isdigit(c)){if(c=='-')b=-1;c=getchar();}
    14     while(isdigit(c)){a=a*10+c-'0';c=getchar();}
    15     return a*b;
    16 }
    17 const int N=1e3+50;
    18 struct node{
    19     int t,s,f,flag;
    20 }p[N];
    21 int n,ans[N];
    22 signed main(){
    23     //freopen("walk.in","r",stdin);
    24     //freopen("walk.out","w",stdout);
    25     n=read();
    26     for(int i=1;i<=n;i++){
    27         p[i].t=read();p[i].s=read();
    28         p[i].f=read();p[i].flag=(p[i].f-p[i].s>0?1:-1);
    29     }
    30     int s1,f1,s2,f2,t1,t2;
    31     for(int i=1;i<=n;i++){
    32         for(int j=i+1;j<=n;j++){
    33             t1=max(p[i].t,p[j].t);
    34             t2=min(p[i].t+abs(p[i].f-p[i].s),p[j].t+abs(p[j].f-p[j].s));
    35             if(t1>t2)continue;
    36             if(t1==p[i].t)s1=p[i].s,s2=p[j].s+p[j].flag*(t1-p[j].t);
    37             else s2=p[j].s,s1=p[i].s+p[i].flag*(t1-p[i].t);
    38             f1=s1+p[i].flag*(t2-t1);f2=s2+p[j].flag*(t2-t1);
    39             if((f2>=f1&&s2<=s1)||(f2<=f1&&s2>=s1))ans[i]++,ans[j]++;
    40         }
    41     }
    42     for(int i=1;i<=n;i++){
    43     printf("%lld ",ans[i]);
    44     }
    45     return 0;
    46 }
  • 相关阅读:
    D
    hdu2376 Average distance (树形dp)
    hdu2376 Average distance (树形dp)
    选拔赛——旅游
    选拔赛——旅游
    cf 990c(思维+括号匹配)
    cf 990c(思维+括号匹配)
    Garland CodeForces
    Garland CodeForces
    Sherlock and his girlfriend CodeForces
  • 原文地址:https://www.cnblogs.com/zjy1412/p/13386051.html
Copyright © 2011-2022 走看看