Hướng dẫn giải của Giải bóng đá
Chỉ dùng lời giải này khi không có ý tưởng, và đừng copy-paste code từ lời giải này. Hãy tôn trọng người ra đề và người viết lời giải.
Nộp một lời giải chính thức trước khi tự giải là một hành động có thể bị ban.
Nộp một lời giải chính thức trước khi tự giải là một hành động có thể bị ban.
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
const fi=''; fo=''; maxn=1010; var a:array[1..maxn,1..maxn] of char; re:array[1..maxn] of longint; n:longint; procedure rf; var i,j:longint; begin assign(input,fi); reset(input); readln(n); for i:=1 to n do begin for j:=1 to n do read(a[i,j]); readln; end; close(input); end; procedure wf; var i:longint; begin assign(output,fo); rewrite(output); for i:=1 to n do write(re[i],' '); close(output); end; procedure insert(i,j:longint); var p:longint; begin for p:=i downto j+1 do re[p]:=re[p-1]; re[j]:=i; end; procedure pr; var i,j:longint; kt:boolean; begin fillchar(re,sizeof(re),0); re[1]:=1; for i:=2 to n do begin kt:=false; for j:=1 to i-1 do if a[i,re[j]]='1' then begin insert(i,j); kt:=true; break; end; if not kt then re[i]:=i; end; end; begin rf; pr; wf; end.
Code mẫu của happyboy99x
#include <algorithm> #include <bitset> #include <cctype> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<vii> vvii; typedef vector<int> vi; typedef vector<vi> vvi; #define sz(a) int((a).size()) #define fi first #define se second #define pb push_back #define mp make_pair #define all(c) (c).begin(), (c).end() #define tr(c,i) for(typeof((c).begin()) i = (c).begin(), _e = (c).end(); i != _e; ++i) #define present(c,x) ((c).find(x) != (c).end()) #define cpresent(c,x) (find(all(c),x) != (c).end()) #define rep(i,n) for(int i = 0, _n = (n); i < _n; ++i) #define repd(i,n) for(int i = (n)-1; i >= 0; --i ) #define fo(i,a,b) for(int i = (a), _b = (b); i <= _b; ++i) #define fod(i,a,b) for(int i = (a), _b = (b); i >= _b; --i) #define INF 1000000000 #define N 1005 char a[N][N]; int n, x[N]; int cmp( const int & x, const int & y ) { return a[x][y] - 0x30; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); #endif scanf("%d",&n); rep(i,n) { scanf("%s",a[i]); x[i]=i; } sort(x,x+n,cmp); bool ok = true; fo(i,1,n-1) if(a[x[i-1]][x[i]] == 0x30) { ok = false; break; } if(!ok) printf("-1\n"); else { printf("%d",x[0]+1); fo(i,1,n-1) printf(" %d",x[i]+1); putchar(10); } return 0; }
Code mẫu của ladpro98
program NKLEAGUE; uses math; const maxn=1000; fi=''; var topo:array[1..maxn] of longint; a:array[1..maxn,1..maxn] of longint; chk:array[1..maxn] of boolean; i,j,n,time:longint; c:char; inp:text; procedure dfs(i:longint); var j:longint; begin chk[i]:=true; for j:=1 to n do if (a[i,j] = 0) and (not chk[j]) then dfs(j); inc(time); topo[time]:=i; end; begin assign(inp,fi);reset(inp); readln(inp,n); for i:=1 to n do begin for j:=1 to n do begin read(inp,c); a[i,j]:=ord(c)-48; end; readln(inp); end; for i:=1 to n do if not chk[i] then dfs(i); for i:=1 to time do write(topo[i],' '); end.
Code mẫu của RR
{$R+,Q+} const FINP=''; FOUT=''; MAXN=1000; type list=^node; node=record data:longint; next:list; end; var c:array[1..MAXN,1..MAXN] of byte; n:longint; first:list; procedure inp; var f:text; i,j:longint; ch:char; begin assign(f,FINP); reset(f); readln(f,n); for i:=1 to n do begin for j:=1 to n do begin read(f,ch); if ch='1' then c[i,j]:=1; end; readln(f); end; close(f); new(first); first^.data:=1; first^.next:=nil; end; procedure ans; var f:text; begin assign(f,FOUT); rewrite(f); while first<>nil do with first^ do begin write(f,data,' '); first:=next; end; close(f); end; procedure solve; var i:longint; p,q,u:list; begin for i:=2 to n do if c[i,first^.data]=1 then begin new(p); p^.data:=i; p^.next:=first; first:=p; end else begin p:=first; while p^.next<>nil do begin if c[i,p^.next^.data]=1 then begin q:=p^.next; new(u); u^.data:=i; u^.next:=q; p^.next:=u; break; end; p:=p^.next; end; if p^.next=nil then begin new(u); u^.data:=i; u^.next:=nil; p^.next:=u; end; end; end; begin inp; solve; ans; end.
Code mẫu của hieult
#include <stdio.h> //#include <conio.h> main() { long n,a[1002]; char s[1002][1002]; scanf("%ld",&n); for(long i=1;i<=n;i++) scanf("%s",s[i]); a[1]=1; for(long i=2;i<=n;i++) { for(long j=1;j<=i;j++) { if(j==i) a[i]=i; else if(s[i][a[j]-1]=='1') { for(long k=i;k>j;k--) a[k]=a[k-1]; a[j]=i; break; } } //for(long j=1;j<=i;j++) //printf("%ld ",a[j]); //printf("\n"); } for(long i=1;i<=n;i++) printf("%ld ",a[i]); //getch(); }
Code mẫu của ll931110
Program NKLEAGUE; Const input = ''; output = ''; Var F: array[1..1000,1..1000] of boolean; a: array[1..1000] of integer; n: integer; Procedure init; Var fi: text; ch: char; i,j: integer; Begin Assign(fi, input); Reset(fi); Readln(fi, n); For i:= 1 to n do Begin For j:= 1 to n do Begin Read(fi, ch); If ch = '1' then F[i,j]:= true else if ch = '0' then F[i,j]:= false; End; Readln(fi); End; Close(fi); End; Procedure solve; Var fo: text; i,j,k: integer; Begin For i:= 1 to n do a[i]:= i; For i:= 2 to n do Begin j:= 1; While not F[i,a[j]] and (j < i) do inc(j); If j < i then Begin For k:= i - 1 downto j do a[k + 1]:= a[k]; a[j]:= i; End else a[i]:= i; End; Assign(fo, output); Rewrite(fo); For i:= 1 to n do write(fo, a[i], ' '); Close(fo); End; Begin init; solve; End.
Code mẫu của khuc_tuan
#include <rope.h> #define I int I n,i;char a[1010];vector<I>r(2); I e(I u,I v){return a[u]-49&&a[v]-48;} main(){ scanf("%d", &n); a[0]=48;a[r[i=1]=1008]=49; gets(a); for(int t=0;t<n;++t) { gets(a+1); r.insert(adjacent_find(r.begin(),r.end(),e)+1,i++); } copy(r.begin()+1,r.end()-1,ostream_iterator<I>(cout," ")); return 0;}
Bình luận
include <bits/stdc++.h>
using namespace std; int n; const int maxN = 1e3 + 5; vector<int> g[maxN]; stack<int> topo; int ans[maxN],check[maxN]; void dfs(int u) { check[u] = 1; for(auto v:g[u]) { if(!check[v]) dfs(v); } check[u] = 2; topo.push(u); } int main() { iosbase::syncwithstdio(false);cin.tie(NULL);cout.tie(NULL); cin >> n; char x; for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { cin >> x; if (x=='1') g[i].pushback(j); } } for(int i=1;i<=n;i++) { if (!check[i]) dfs(i); } int cnt = 0; while(!topo.empty()) { ans[++cnt] = topo.top(); topo.pop(); } for(int i=1;i<=n;i++) cout << ans[i] << " "; }