牛客提高D5t1 deco的abs
作者:互联网
分析
傻子题?
对d取模后随便贪心即可
代码
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> #include<cctype> #include<cmath> #include<cstdlib> #include<queue> #include<ctime> #include<vector> #include<set> #include<map> #include<stack> using namespace std; #define int long long int Ans,n,d,a,ai; signed main(){ int i,j,k; scanf("%lld%lld",&n,&d); for(i=1;i<=n;i++){ scanf("%lld",&a); a%=d; if(i>1){ k=abs(a-ai); Ans+=min(k,d-k); } ai=a; } printf("%lld\n",Ans); return 0; }
标签:deco,D5t1,long,牛客,int,Ans,include,ai,lld 来源: https://www.cnblogs.com/yzxverygood/p/11405798.html