4 条题解
-
2
我不理,我还要发老八秘制小代码
#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
就是这样,AC过,求赞
#include<bits/stdc++.h> using namespace std; long long n,a[100001],m,p1,s1,s2,ans,sum1,sum2,ans1,ans2,pos; int main(void){ ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); cin>>n; for(int i=1;i<=n;i++)cin>>a[i]; cin>>m>>p1>>s1>>s2; a[p1]+=s1; for(int i=1;i<m;i++)sum1+=a[i]*(m-i); for(int i=m+1;i<=n;i++)sum2+=a[i]*(i-m); ans=1000000000000000000; for(int i=1;i<=n;i++){ if(i<m)ans1=sum1+s2*(m-i),ans2=sum2; else if(i>m)ans1=sum1,ans2=sum2+s2*(i-m); else ans1=sum1,ans2=sum2; if(abs(ans1-ans2)<ans)ans=abs(ans1-ans2),pos=i; } cout<<pos; }
-
0
#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> #define inf 1e18 #define ll long long using namespace std; const int N = 1e5 + 5; ll n, a[N], m, p1, s1, s2, ans; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } cin >> m >> p1 >> s1 >> s2; a[p1] += s1; ll sum1 = 0, sum2 = 0; for (int i = 1; i < m; i++) sum1 += a[i] * (m - i); for (int i = m + 1; i <= n; i++) sum2 += a[i] * (i - m); ll ans1 = 0, ans2 = 0; ans = inf; int pos; for (int i = 1; i <= n; i++) { if (i < m) { ans1 = sum1 + s2 * (m - i); ans2 = sum2; } else if (i > m) { ans1 = sum1; ans2 = sum2 + s2 * (i - m); } else { ans1 = sum1; ans2 = sum2; } if (abs(ans1 - ans2) < ans) { ans = abs(ans1 - ans2); pos = i; } } cout << pos; return 0; }
- 1
信息
- ID
- 1370
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 6
- 标签
- 递交数
- 266
- 已通过
- 82
- 上传者