Editorial for Trò chơi với những viên bi
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Lưu ý: Các code mẫu dưới đây chỉ mang tính tham khảo và có thể không AC được bài tập này
Code mẫu của flashmt
var i,n,s,k,m,x,j:longint; a:array[1..500000] of longint; begin read(n,k); x:=0; for i:=1 to n do begin read(m); s:=s+m; for j:=1 to m do a[x+j]:=i; x:=x+j; end; m:=s div k; for i:=1 to m do begin for j:=0 to k-1 do write(a[j*m+i],' '); writeln; end; end.
Code mẫu của happyboy99x
#include<cstdio> #include<algorithm> using namespace std; #define N 500000 pair<int, int> a[N+1]; int n, s, m; int main() { scanf("%d%d", &n, &m); for(int i = 0; i < n; ++i) { scanf("%d", &a[i].first); a[i].second = i + 1; s += a[i].first; } for(int x = s/m; x > 0; --x) { sort(a, a+n); for(int i = n - m; i < n; ++i) { printf("%d ", a[i].second); --a[i].first; } putchar(10); } return 0; }
Code mẫu của ladpro98
program cnmarble; uses math; const maxn=500005; fi=''; var a,v:array[1..maxn] of longint; inp:text; n,m,i,j,t,u,s:longint; begin assign(inp,fi);reset(inp); readln(inp,n,m); j:=1;i:=1; for t:=1 to n do begin read(inp,v[t]); inc(s,v[t]); end; for t:=1 to n do begin for u:=1 to v[t] do begin a[(i-1)*m+j]:=t; if i=s div m then begin i:=1; inc(j); end else inc(i); end; end; for i:=0 to s div m-1 do begin for j:=i*m+1 to i*m+m do write(a[j],' '); writeln; end; end.
Code mẫu của RR
var x,i,j,n,m,s:longint; u,a:array[1..500111] of longint; begin read(n,m); for i:=1 to n do read(u[i]); s:=0; for i:=1 to n do for j:=1 to u[i] do begin inc(s); a[s]:=i; end; x:=s div m; for i:=1 to x do begin for j:=1 to m do write(a[i+(j-1)*x],' '); writeln; end; end.
Code mẫu của hieult
#include <stdio.h> //#include <conio.h> main() { int n,m,a[500001],S[500001],s=0,t; scanf("%d %d",&n,&m); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); s=s+a[i]; } t=s/m; int T=1; for(int i=1;i<=n;i++) { for(int j=T;j<T+a[i];j++) S[j]=i; T=T+a[i]; } for(int i=1;i<=t;i++) { for(int j=1;j<=m;j++) printf("%d ",S[i+(j-1)*t]); printf("\n"); } //getch(); }
Code mẫu của ll931110
#include <iostream> #include <queue> using namespace std; struct rec { int val,pos; bool operator<(const rec& r) const { return val < r.val; }; }; int main() { int n,m,x; rec tmp; rec r[200001]; priority_queue <rec> heap; // freopen("cn.in","r",stdin); // freopen("cn.ou","w",stdout); scanf("%d%d", &n, &m); int sum = 0; for (int i = 0; i < n; i++) { scanf("%d", &x); tmp.val = x; tmp.pos = i; heap.push(tmp); sum += x; }; for (int i = 0; i < sum/m; i++) { int count = 0; for (int j = 0; j < m; j++) { r[count] = heap.top(); heap.pop(); printf("%d ", r[count].pos + 1); r[count].val--; if (r[count].val > 0) count++; }; for (int j = 0; j < count; j++) heap.push(r[j]); printf("\n"); }; };
Comments