2 条题解
-
2
就说这道题有什么区别? 再发一个
#include <bits/stdc++.h> using namespace std; long long n; long long s[100005]; long long m,p,s1,s2,p2; long long minn=1e19; long long sum1,sum2; long long t1,t2; struct T{ long long ju; long long re; long long he; }a[100005];//结构体是真好用 inline long long bijiao(long long x,long long y){ if (x>=y){ return x-y; } else{ return y-x; } }//计算距离 int main(){ cin>>n; for (long long i=1;i<=n;i++){ cin>>s[i]; } cin>>m>>p>>s1>>s2; for (long long i=1;i<=n;i++){ a[i].re=s[i];//人数 a[i].ju=max(m,i)-min(m,i);//距离 a[i].he=a[i].ju*a[i].re;//气势和 } a[p].he+=(s1*a[p].ju); for (long long i=1;i<=n;i++){ if (i<m){ sum1+=a[i].he; } else{ sum2+=a[i].he; }//计算两方的气势和 } for (long long i=1;i<=n;i++){ t1=sum1; t2=sum2; if (i<m){ t1+=(m-i)*s2; } else if(i>m){ t2+=(i-m)*s2; }//枚举每个点,如果是左t1加,如果是右t2加 long long tmp=bijiao(t1,t2);//调用 if (minn>tmp){ minn=tmp; p2=i; }//判断,因为这里是下标,不能用min() } cout<<p2; return 0; }
-
0
老八秘制小代码
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int N=1e5+10; LL a[N],n,m,p1,s2,s1,r,r1=0,r2=0,mi; int main(){ //freopen(" .in","r",stdin); //freopen(" .out","w",stdout); scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d",&a[i]); } scanf("%d%d%d%d",&m,&p1,&s1,&s2); a[p1]+=s1; for(int i=1;i<=n;i++){ if(i<m){ r1+=(m-i)*a[i]; }else if(i>m){ r2+=(i-m)*a[i]; } } mi=abs(r1-r2); r=m; for(int i=1;i<=n;i++){ if(i<m){ if(abs(r1+(m-i)*s2-r2)<mi){ mi=abs(r1+(m-i)*s2-r2); r=i; } }else if(i>m){ if(abs(r2-r1+(i-m)*s2)<mi){ mi=abs(r2-r1+(i-m)*s2); r=i; } } } printf("%d",r); //fclose(stdin); //fclose(stdout); return 0; }
- 1
信息
- ID
- 434
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 1
- 标签
- 递交数
- 27
- 已通过
- 24
- 上传者