"HKUST Xunfei Cup" 18th Shanghai University Programming League Spring Competition and College Network Friendly Match E. Delicious Sequence

E. Delicious sequence

Topic link-E. Delicious sequence
Insert picture description here
Insert picture description here
problem solving ideas

  • It is not difficult to find that the order of eating has no effect on the answer
  • Because every 1 second elapses, the taste of all uneaten portions will decrease by 1, so at the end subtract n × ( n 1 ) / 2 n×(n-1)/2 to
  • which is a n s = s u m i = 1 n ( n i ) ans=sum-\sum_{i=1}^n (n-i)

Attach the code

//#pragma GCC optimize("-Ofast","-funroll-all-loops")
#include<bits/stdc++.h>
#define int long long
#define lowbit(x) (x &(-x))
#define endl '\n'
using namespace std;
const int INF=0x3f3f3f3f;
const int dir[4][2]={-1,0,1,0,0,-1,0,1};
const double PI=acos(-1.0);
const double e=exp(1.0);
const double eps=1e-10;
const int M=1e9+7;
const int N=2e5+10;
typedef long long ll;
typedef pair<int,int> PII;
typedef unsigned long long ull;
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);

	int n,ans=0;
	cin>>n;
	for(int i=0;i<n;i++){
		int tmp;
		cin>>tmp;
		ans+=tmp; 
	}
	ans-=n*(n-1)/2;
	cout<<ans<<endl;
	return 0;
}

Published 183 original articles · praised 38 · 20,000+ views

Guess you like

Origin blog.csdn.net/Fiveneves/article/details/105609334