215 条题解
-
0gxz LV 8 @ 2013-11-15 19:09:13
#include <stdio.h>
int a[1000];
int main()
{
int sum = 0 , i , ans = 0 , n , temp = 0;scanf("%d" , &n);
for(i = 0 ; i < n ; i ++ )
{
scanf("%d" , &a[i]);
sum += a[i];
}
sum /= n;for(i = 0 ; i < n ; i ++ )
{
temp = a[i] + temp - sum;
if(temp != 0)
{
ans ++ ;
}
}
printf("%d\n" , ans);return 0;
} -
02013-10-25 22:16:29@
var i,j,k:longint;
num:array[0..101] of longint;
ans:longint;
fin:text;
begin
readln(k);
for i:=1 to k do begin read(num[i]);j:=j+num[i];end;
j:=j div k;ans:=k-1;
for i:=1 to k-1 do if num[i]<>j then inc(num[i+1],num[i]-j) else dec(ans);
writeln(ans);
end. -
02013-10-24 09:07:00@
12行- =
评测结果
编译成功测试数据 #0: Accepted, time = 0 ms, mem = 536 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 540 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 536 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 544 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 540 KiB, score = 10
Accepted, time = 0 ms, mem = 544 KiB, score = 50
代码
#include<cstdio>
int n,a[110],r=0;
int main(){
scanf("%d",&n);
for (int i=1; i<=n; i++) {
scanf("%d",&a[i]);
a[i] += a[i - 1] ;
} a[n] /= n ;
for (int i=1; i< n; i++)
if (a[i] != a[n]*i) r++;
printf("%d",r);
} -
02013-10-15 14:31:34@
测试数据 #0: Accepted, time = 0 ms, mem = 824 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 820 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 824 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 824 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 820 KiB, score = 10
Accepted, time = 0 ms, mem = 824 KiB, score = 50
极短代码:
var
n,i,sum,ans:longint;
a:array[0..101]of longint;
begin
readln(n);
for i:=1 to n do
begin
read(a[i]);
sum:=sum+a[i];
end;
sum:=sum div n; ans:=n-1;
for i:=1 to n-1 do
if a[i]<>sum then inc(a[i+1],a[i]-sum) else dec(ans);
writeln(ans);
end. -
02013-10-04 08:45:57@
编译成功
测试数据 #0: Accepted, time = 0 ms, mem = 732 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 732 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 732 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 728 KiB, score = 10
测试数据 #4: Accepted, time = 3 ms, mem = 732 KiB, score = 10
Accepted, time = 3 ms, mem = 732 KiB, score = 50
个人觉得此代码比较容易理解,先算出平均个数再移动;
program junfen;
var n,i:longint;
a:array[1..101] of longint;
x,sum,num:longint;
begin
readln(n);
for i:=1 to n do read(a[i]);
readln;
sum:=0;
num:=0;
for i:=1 to n do sum:=sum+a[i];
x:=sum div n;
for i:=1 to n do begin
if a[i]>x then begin
a[i+1]:=a[i+1]+a[i]-x;
a[i]:=x;
num:=num+1;
end;
if a[i]<x then begin
a[i+1]:=a[i+1]-(x-a[i]);
a[i]:=x;
num:=num+1;
end;
if a[i]=x then
continue;
end;
writeln(num);
end. -
02013-08-13 15:25:58@
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define maxn 100using namespace std;
int n,a[maxn+1];
int main()
{
int i,j,k,t,y,head,tial,ans,maxx;
while(~scanf("%d",&n))
{
k=0;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
k+=a[i];
}
k/=n;
for(i=0;i<n;i++)
a[i]-=k;
ans=0;
for(i=0;i<n;i++)
if(a[i]!=0)
{
a[i+1]+=a[i];
a[i]=0;
ans++;
}
else continue;
printf("%d\n",ans);
}
return 0;
} -
02012-10-06 17:45:59@
同志们,遇到超时一定要镇定。我提交一次第五个数据TLE,不修改再次提交第一个数据TLE,不修改第三次提交AC。评测机有可能自己爆TLE,虽然不知道怎么回事……
-
02012-08-02 15:14:00@
点击查看代码
-
02010-07-07 22:01:27@
是数据弱吗 - -
#include
using namespace std;int a[101];
int main(){
int n,s,t,i;
cin>>n;
for(i=1;i>a[i];
s+=a[i];
}
s/=n;
t=0;
for(i=1;is) {a+=a[i]-s;a[i]=s;}
if(a[i] -
02010-04-06 21:41:17@
var a:array[-100..100]of integer;
b,n,x,i:integer;
begin
read(n);
for i:=1 to n do read(a[i]);
x:=0;
for i:= 1 to n do
begin
x:=x+a[i];
end;
x:=x div n;
for i:= 1 to n do a[i]:=a[i]-x;
i:=1;
while (i -
02010-03-28 21:57:18@
var n, k, i, j,x, sum : longint;
a : array[1..110] of longint;
begin
sum:=0;
readln(n);
for i:=1 to n do begin read(a[i]);
inc(sum,a[i]);
end;
k:=sum div n;
j:=0;
x:=0;
repeat
for i:=1 to n do begin j:=a[i]-k+j ;
if j0 then
x:=x+1;end;
until j=0;
writeln(x);
end. -
02009-11-11 19:50:45@
program p1123;
var n:longint;
a:array[1..1000] of longint;
procedure init;
var i,pj:longint;
begin
pj:=0;
readln(n);
for i:=1 to n do begin read(a[i]); inc(pj,a[i]); end;
pj:=pj div n;
for i:=1 to n do a[i]:=a[i]-pj;
for i:=1 to n do writeln(a[i]);
end;
procedure work;
var k,total:longint;
begin
k:=1; total:=0;
repeat
if a[k]=0 then inc(k)
else begin a[k+1]:=a[k+1]+a[k]; a[k]:=0; inc(total); inc(k); end;
until k>=n;
writeln(total);
end;
begin
init;
work;
end. -
02009-11-08 14:19:29@
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
├ 测试数据 05:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:0msprogram cmove;
var
a:array[1..100] of integer;
n,m,i,j,t:longint;
begin
t:=0;
m:=0;
readln(n);
for i:=1 to n do begin read(a[i]); t:=t+a[i]; end;
t:=t div n;
for i:=2 to n do begin
if a-t0 then begin a[i]:=a[i]-(t-a);
inc(m);
end;
end;
writeln(m);
end.Flag Accepted
题号 P1123
类型(?) 模拟
通过 5426人
提交 11060次
通过率 49%
难度 1提交 讨论 题解
终于对了十题!纪念!!!
-
02009-11-08 09:31:28@
program a1;
var a:array[1..100000] of longint;
n,i,z,pj,c,g:longint;
begin
readln(n);
for i:=1 to n do
begin
read(a[i]);
z:=a[i]+z;
end;
pj:=z div n;
for i:=1 to n do
begin
if a[i]pj then
begin
c:=pj-a[i];
a[i]:=a[i]+c;
a:=a-c;
g:=g+1;
end;
end;
writeln(g);
end. -
02009-11-02 18:05:02@
program jfzp;
var
a:array[1..100] of longint;
n,i,ave,s:longint;
procedure dayin;
begin
writeln(s);
end;
procedure duru;
begin
readln(n);
for i:=1 to n do
begin
read(a[i]);
inc(ave,a[i]);
end;
ave:=ave div n;
end;
procedure chushihua;
begin
ave:=0;
s:=0;
end;
procedure junfen;
begin
for i:=1 to n do
if a[i]ave then
begin
a:=a+a[i]-ave;
inc(s);
end;
end;
begin
chushihua;
duru;
junfen;
dayin;
end.
多帅的过程!!!
还有个问题:
为什么有人过不了第五个数据? -
02009-11-02 14:55:22@
program aa;
var
a:array[1..100]of longint;
n,i,j:integer;
sum,k:longint;
begin
readln(n); sum:=0; j:=0;
for i:=1 to n do begin
read(a[i]); sum:=sum+a[i];
k:=sum div n;
for i:=1 to n-1 do
if a[i]k then
begin
a:=a+a[i]-k;
j:=j+1;
end;
writeln(j);
end. -
02009-11-02 13:29:16@
var
n:longint;
a:array[1..100] of longint;
i,j,k,s,ans:longint;
begin
readln(n);
s:=0;ans:=0;
for i:=1 to n do begin read(a[i]);s:=s+a[i]; end;
k:=s div n;
for i:=1 to n-1 do
if a[i]k then
begin
a:=a+a[i]-k;
inc(ans);
end;
writeln(ans);
end. -
02009-11-01 23:20:48@
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
├ 测试数据 05:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:0ms -
02009-10-31 16:54:26@
var
s,n,i,m,j:longint;
a:array[1..100] of longint;
begin
readln(n);
s:=0;
for i:= 1 to n do
begin
read(a[i]);
s:=s+a[i];
end;
m:= s div n;
j:=0;
for i:= 1 to n-1 do
begin
if a[i]m then
begin
a:=a+(m-a[i]);
j:=j+1;
end;
if a[i]=m then
begin
a[i]:=m;
end;
end;
write(j);
end. -
02009-10-30 01:29:34@
显然,当一堆达到平均值之后再改变,需要的步数必然增加,即只需要将前i-1调整成平均值就可以保证解的最优。。所以,只要将不足平均值的用后面的补,超过平均值的把多余的加到后面,这样就可以完成上述操作的模拟。。