两个程序的不同:
double t(car a,car b){ return double(a.k-b.k)/(b.v-a.v);}
double t(car a,car b){ return double((a.k-b.k)/(b.v-a.v));}
这一对括号的影响是什么?
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e5+2;
inline int re(){
int k=0;
char c=getchar();
while(c<'0'||c>'9'){ c=getchar();}
while(c>='0'&&c<='9'){
k=(k<<3)+(k<<1)+(c^48);
c=getchar();}
return k;}
struct car{int v,k,num;}c[N];
int s[N],top,n;
bool cmp1(car a,car b){ return a.v==b.v? a.k<b.k:a.v<b.v;}
bool cmp2(int a,int b){ return c[a].num<c[b].num;}
double t(car a,car b){ return double(a.k-b.k)/(b.v-a.v);}
bool ct(car a,car b,car c){
if(b.v==c.v || a.v==b.v || top<=1) return 0;
return t(a,b)>t(b,c);
}
signed main(){
n=re();
for(int i=1;i<=n;i++) c[i].k=re(),c[i].num=i;
for(int i=1;i<=n;i++) c[i].v=re();
sort(c+1,c+1+n,cmp1);
s[++top]=1;
for(int i=2;i<=n;i++){
while(top&&(c[s[top]].k<c[i].k || ct(c[s[top-1]],c[s[top]],c[i]))){
top--;
}
s[++top]=i;}
sort(s+1,s+1+top,cmp2);
printf("%d \n",top);
for(int i=1;i<=top;i++) printf("%d ",c[s[i]].num);
return 0;}
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e5+2;
inline int re(){
int k=0;
char c=getchar();
while(c<'0'||c>'9'){ c=getchar();}
while(c>='0'&&c<='9'){
k=(k<<3)+(k<<1)+(c^48);
c=getchar();}
return k;}
struct car{int v,k,num;}c[N];
int s[N],top,n;
bool cmp1(car a,car b){ return a.v==b.v? a.k<b.k:a.v<b.v;}
bool cmp2(int a,int b){ return c[a].num<c[b].num;}
double t(car a,car b){ return double((a.k-b.k)/(b.v-a.v));}
bool ct(car a,car b,car c){
if(b.v==c.v || a.v==b.v || top<=1) return 0;
return t(a,b)>t(b,c);
}
signed main(){
n=re();
for(int i=1;i<=n;i++) c[i].k=re(),c[i].num=i;
for(int i=1;i<=n;i++) c[i].v=re();
sort(c+1,c+1+n,cmp1);
s[++top]=1;
for(int i=2;i<=n;i++){
while(top&&(c[s[top]].k<c[i].k || ct(c[s[top-1]],c[s[top]],c[i]))){
top--;
}
s[++top]=i;}
sort(s+1,s+1+top,cmp2);
printf("%d \n",top);
for(int i=1;i<=top;i++) printf("%d ",c[s[i]].num);
return 0;}
谢谢指点