版本比较
题解 P3114 【[USACO15JAN]Stampede S】
正文
增加 8 行删除 8 行
30 行未改动313233343535363738394041424243444545464748495047484950515253545556575858596061628 行未改动30 行未改动 rd(n) F(i,1,n) { rd(x)rd(y[i])rd(v) x++; x=-x;//将坐标转化为距离 x=-x;//将坐标转化为距离 st[i]=x*v; ed[i]=st[i]+v-1; t[++p]=st[i],t[++p]=ed[i]; t[++p]=ed[i]+1;//左闭右开 } memset(c,0x3f,sizeof(c)); sort(t+1,t+p+1);//先排序再离散化 sort(t+1,t+p+1);//先排序再离散化 long long cnt=unique(t+1,t+p+1)-t-1; F(i,1,n) { st[i]=lower_bound(t+1,t+cnt+1,st[i])-t;//离散化 st[i]=lower_bound(t+1,t+cnt+1,st[i])-t;//离散化 ed[i]=lower_bound(t+1,t+cnt+1,ed[i])-t; F(j,st[i],ed[i]){//暴力覆盖 if(c[j]>y[i]){//如果覆盖这一段时间的奶牛的 y 值大于现在的奶牛,就更新 c[j]=y[i];//c 模拟时间轴上奶牛的 y 值 d[j]=i;//d 记录时间轴上的奶牛编号 F(j,st[i],ed[i]){//暴力覆盖 if(c[j]>y[i]){//如果覆盖这一段时间的奶牛的 y 值大于现在的奶牛,就更新 c[j]=y[i];//c 模拟时间轴上奶牛的 y 值 d[j]=i;//d 记录时间轴上的奶牛编号 } } } int ans=0; F(i,1,n) { F(j,st[i],ed[i]) { if(d[j]==i){ ans++;//如果第 i 头奶牛经过 y 轴的时间内能被看到,答案+1 ans++;//如果第 i 头奶牛经过 y 轴的时间内能被看到,答案+1 break; } } }8 行未改动