215 条题解
-
0lxy1374030943 LV 8 @ 2016-09-01 20:29:17
评测结果
编译成功测试数据 #0: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 564 KiB, score = 10
测试数据 #3: Accepted, time = 15 ms, mem = 556 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 556 KiB, score = 10
Accepted, time = 15 ms, mem = 564 KiB, score = 50
代码
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
int n,m,x,y,ans,a[101];
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
m+=a[i];
}
m/=n;
for(int i=1;i<=n;++i) a[i]-=m;
x=1;
for(int i=1;i<=n;++i)
if(a[i]==0) x++;
else break;
y=n;
for(int i=n;i>0;--i)
if(a[i]==0) y--;
else break;
for(int i=x;i<=y;++i)
{
a[i+1]+=a[i];
a[i]=0;
ans++;
while(a[i+1]==0) i++;
}
cout<<ans<<endl;
return 0;
} -
02016-08-22 15:26:03@
模拟:var
n,i,sum,ans:longint;
a:array[1..10000] of longint;
begin
readln(n);
for i:=1 to n do begin
read(a[i]);
sum:=sum+a[i];
end;
sum:=sum div n;
for i:=1 to n-1 do begin
if a[i]>sum then begin
a[i+1]:=a[i+1]+a[i]-sum;
a[i]:=sum;
inc(ans);
end;
if a[i]<sum then begin
a[i+1]:=a[i+1]-sum+a[i];
a[i]:=sum;
inc(ans);
end;
if a[i]=sum then begin
ans:=ans;
end;
end;
writeln(ans);
end. -
02016-08-11 10:24:31@
评测结果 编译成功 测试数据 #0: Accepted, time = 0 ms, mem = 504 KiB, score = 10 测试数据 #1: Accepted, time = 0 ms, mem = 508 KiB, score = 10 测试数据 #2: Accepted, time = 0 ms, mem = 508 KiB, score = 10 测试数据 #3: Accepted, time = 0 ms, mem = 508 KiB, score = 10 测试数据 #4: Accepted, time = 0 ms, mem = 508 KiB, score = 10 Accepted, time = 0 ms, mem = 508 KiB, score = 50 代码 #include <cstdio> int a[101],ans = 0,n; int main() { scanf("%d",&n); int sum = 0; for (int i = 1;i <= n;i++) { scanf("%d",&a[i]); sum += a[i]; } int ave = sum/n; for (int i = 1;i < n;i++) if (a[i] != ave) { ans++; a[i+1] += a[i]-ave; } printf("%d",ans); return 0; }
-
02016-07-22 16:56:38@
#include<iostream> #include<cstdio> using namespace std; const int maxn = 100 + 5; int L, R, n, N, ans; int tr[maxn], sum[maxn], k[maxn]; void solve () { while (tr[L] == N && L <= n) { L++; R++;} while ((R - L + 1) * N != sum[R] - sum[L-1] && R <= n) R++; ans += R - L; R = L = R + 1; } int main() { // freopen("in.txt", "r", stdin); cin >> n; for (int i = 1; i <= n; i++) { cin >> tr[i]; sum[i] = sum[i-1] + tr[i]; } N = sum[n] / n; ans = 0; L = R = 1; while (L <= n) solve(); cout << ans; return 0; }
-
02016-07-15 14:54:12@
水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水
轻松ACvar a:array[1..100]of longint; n,i,t,s:longint; begin readln(n); for i:=1 to n do begin read(a[i]); t:=t+a[i]; end; t:=t div n;s:=0; for i:=1 to n-1 do if a[i]>t then begin a[i+1]:=a[i+1]+a[i]-t;inc(s);end else if a[i]<t then begin a[i+1]:=a[i+1]-t+a[i];inc(s);end; writeln(s); end.
-
02016-07-14 11:02:05@
#include <cstdio>
int main(){
int n,a[200],sum=0,count=0;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
sum+=a[i];
}
sum/=n;
for(int i=1;i<=n;i++){
if(a[i]==sum)
continue;
if(a[i]>sum)
a[i+1]+=a[i]-sum;
if(a[i]<sum)
a[i+1]-=sum-a[i];
count++;
}
printf("%d",count);
return 0;
} -
02016-05-17 19:27:24@
太水了,要注意real和readln不要打错了!!!(pascal)
-
02016-03-11 17:02:21@
贪心!
白皮书例题
无聊的太简单了!!!#include <iostream> #define ref(i,x,y) for(int i=x;i<=y;i++) using namespace std; int n,a[10001],sum,ans; int main() { cin>>n; ref(i,1,n){cin>>a[i];sum+=a[i];} sum/=n; ref(i,1,n)a[i]-=sum; ref(i,1,n-1)if(a[i])a[i+1]+=a[i];else ans++; cout<<n-1-ans; }
-
02016-02-19 12:15:04@
/* *********************************************** Author :guanjun Created Time :2016/2/19 12:08:30 File Name :vijosp1123.cpp ************************************************ */ #include <iostream> #include <cstring> #include <cstdlib> #include <stdio.h> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <iomanip> #include <list> #include <deque> #include <stack> #define ull unsigned long long #define ll long long #define mod 90001 #define INF 0x3f3f3f3f #define maxn 10000+10 #define cle(a) memset(a,0,sizeof(a)) const ull inf = 1LL << 61; const double eps=1e-5; using namespace std; priority_queue<int,vector<int>,greater<int> >pq; struct Node{ int x,y; }; struct cmp{ bool operator()(Node a,Node b){ if(a.x==b.x) return a.y> b.y; return a.x>b.x; } }; bool cmp(int a,int b){ return a>b; } int a[110]; int main() { #ifndef ONLINE_JUDGE // freopen("in.txt","r",stdin); #endif //freopen("out.txt","w",stdout); int n; while(cin>>n){ int sum=0,m; for(int i=1;i<=n;i++){ cin>>a[i];sum+=a[i]; } m=sum/n; int ans=0; for(int i=1;i<=n;i++){ if(a[i]<m){ a[i+1]-=(m-a[i]);ans++; a[i]=m; } if(a[i]>m){ a[i+1]+=(a[i]-m);ans++; a[i]=m; } } cout<<ans<<endl; } return 0; }
-
02015-09-12 18:15:37@
#include<cstdio>
using namespace std;
const int MAXN = 100 + 10;int num[MAXN];
int main()
{
int n, ans = 0, sum = 0;
scanf("%d", &n);
for(int i=1; i<=n; i++){
scanf("%d", &num[i]);
sum += num[i];
}
sum /= n;
for(int i=1; i<n; i++)
if(num[i] != sum){
num[i+1] -= sum - num[i];
ans++;
}
printf("%d", ans);
return 0;
}
贪心 水一发~ -
02015-09-05 21:15:02@
吴迪马,潮水
var pj,i,j,ans,n:longint;
a:array[0..10000] of longint;
begin
readln(n);
for i:=1 to n do begin read(a[i]); pj:=pj+a[i]; end;
pj:=pj div n;
for i:=1 to n-1 do
if a[i]<>pj then begin
a[i+1]:=a[i]-pj+a[i+1];
a[i]:=pj;inc(ans);
end;
writeln(ans);
end. -
02015-08-22 16:01:55@
#include <iostream>
using namespace std;
int a[10001];
int main(){
int i,j,k,n,m;
int ans=0,sum=0;
cin>>n;
for(i=1;i<=n;i++){cin>>a[i];sum+=a[i];}
sum/=n;
int change=0;
for(i=1;i<n;i++){
change=sum-a[i];
if(change==0) continue;
a[i]+=change;
a[i+1]-=change;
ans++;
}
cout<<ans<<endl;
return 0;
} -
02015-05-26 19:33:11@
#include <iostream>
using namespace std;int main(){
int n;
cin >> n;
int table[101];
for(int i = 1; i <= n; i++)
cin >> table[i];
int sum = 0;
for(int i = 1; i <= n; i++)
sum += table[i];
int idel = sum / n;
int result = 0;
for(int i = 1; i < n; i++){
int change = idel - table[i];
if(change == 0) continue;
table[i] += change;
table[i + 1] -= change;
result++;
}
cout << result << endl;
} -
02015-01-31 08:07:03@
求平均数罢了,20行秒杀
-
02014-12-20 16:06:22@
#include<iostream>
using namespace std;
int main()
{
int a[101],n,tot=0,sum=0,b;
cin>>n;
for(int i=1;i<=n;++i)
cin>>a[i];
for(int i=1;i<=n;++i)
sum=sum+a[i];
b=sum/n;
for(int i=1;i<n;++i)
{
if(a[i]!=b)
{
a[i+1]=a[i+1]+a[i]-b;
tot=tot+1;
}
}
cout<<tot;
return 0;
} -
02014-11-04 18:59:48@
###block code
program ex;
var data:array[0..101] of longint;
n,num,a,i,j,sum,avg,step:longint;
begin
fillchar(data,sizeof(data),0);
sum:=0; avg:=0; step:=0;
read(n);for i:=1 to n do
begin
read(num);
data[i]:=num;
sum:=sum+num;
end;avg:=sum div n;
for i:=1 to n do
begin
if data[i]<avg then
begin
step:=step+1;
data[i+1]:=data[i+1]-(avg-data[i]);
data[i]:=avg;
end;
if data[i]>avg then
begin
step:=step+1;
data[i+1]:=data[i+1]+(data[i]-avg);
data[i]:=avg;
end;
if data[i]=avg then
continue;
end;write(step);
end.没什么好讲的贪心,自己看吧
-
02014-10-05 20:38:24@
#include <cstdio>
size_t n;
int value[105];
unsigned int ans(0);unsigned int every(0);
int main()
{
using namespace std;scanf("%u", &n);
for (size_t index = 0;index != n;++index)
{
scanf("%d", value + index);
every += value[index];
}every /= n;
for (size_t index = 0;index != n - 1;++index)
if (value[index] < every)
{
value[index + 1] -= every - value[index];
value[index] = every;
++ans;
}
else
if (value[index] > every)
{
value[index + 1] += value[index] - every;
value[index] = every;
++ans;
}printf("%u", ans);
return 0;
} -
02014-08-04 15:08:43@
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int t=0,n,a[101]={0},sum=0,num=0;
cin>>n;
for (int i=1;i<=n;i++)
{
cin>>a[i];
sum+=a[i];
}
sum/=n;
for (int i=1;i<=n;i++)
{
t=a[i]+t-sum;
if (t!=0)
num++;
}
cout<<num;
} -
02013-11-27 21:49:52@
超短
var
pj,i,j,ans,n:longint;
a:array[0..10000] of longint;
begin
readln(n);
for i:=1 to n do begin read(a[i]); pj:=pj+a[i]; end;
pj:=pj div n;
for i:=1 to n-1 do if a[i]<>pj then begin
a[i+1]:=a[i]-pj+a[i+1];
a[i]:=pj;
inc(ans);
end;
writeln(ans);
end. -
02013-11-27 21:49:07@
超短
var
pj,i,j,ans,n:longint;
a:array[0..10000] of longint;
begin
readln(n);
for i:=1 to n do begin read(a[i]); pj:=pj+a[i]; end;
pj:=pj div n;
for i:=1 to n-1 do if a[i]<>pj then begin
a[i+1]:=a[i]-pj+a[i+1];
a[i]:=pj;
inc(ans);
end;
writeln(ans);
end.