Editorial for Majstor


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.

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 n,m:byte;cur,re:integer;a:array[0..50,1..50] of byte;r:array[0..2] of integer;
procedure rf;Var i,j:byte; c:char;begin readln(n);for i:=1 to n do begin read(c);case c of 'S':a[0,i]:=0;'R':a[0,i]:=1;'P':a[0,i]:=2;end end;readln;readln(m);for i:=1 to m do begin
for j:=1 to n do begin read(c);case c of 'S':a[i,j]:=0;'R':a[i,j]:=1;'P':a[i,j]:=2;end end;readln;end;end;
function max(a,b,c:integer):integer;begin if (a>b) and (a>c) then max:=a else begin if b>c then max:=b else max:=c;end;end;
procedure pr;var i,j:byte;begin cur:=0; re:=0;for j:=1 to n do begin fillchar(r,sizeof(r),0);for i:=1 to m do begin if a[0,j]=a[i,j] then cur:=cur+1 else begin if (a[0,j]+2) mod 3 = a[i,j] then cur:=cur+2;
end;
inc(r[a[i,j]]);
inc(r[(a[i,j]+1) mod 3],2);
end;
re:=re+max(r[0],r[1],r[2]);
end;
end;
procedure wf;
begin writeln(cur);write(re);end;
begin rf;pr;wf;end.

Code mẫu của ladpro98

uses    math;
const   q:array[1..3] of char=('P','R','S');
var     inp:text;
        r,n,i,j,k,t,res,rmax:longint;
        c:array[1..99,'A'..'Z'] of longint;
        win:array['A'..'Z'] of char;
        s,a:string;
begin
        assign(inp,'');reset(inp);
        readln(inp,r);
        readln(inp,s);
        readln(inp,n);
        win['S']:='P';
        win['R']:='S';
        win['P']:='R';
        for i:=1 to n do
        begin
                readln(inp,a);
                for j:=1 to r do inc(c[j,a[j]]);
        end;
        for j:=1 to r do
        begin
                inc(res,c[j,s[j]]+2*c[j,win[s[j]]]);
                t:=0;
                for k:=1 to 3 do t:=max(t,c[j,q[k]]+2*c[j,win[q[k]]]);
                inc(rmax,t);
        end;
        writeln(res);writeln(rmax);
end.

Code mẫu của RR

uses math;
const
FINP='';
FOUT='';
var
f1,f2:text;
round,n:longint;
s:string;
a:array[1..50] of string;
procedure openF;
begin
assign(f1,FINP); reset(f1);
assign(f2,FOUT); rewrite(f2);
end;
procedure closeF;
begin
close(f1);close(f2);
end;
procedure inp;
var
i:longint;
begin
readln(f1,round);
readln(f1,s);
readln(f1,n);
for i:=1 to n do
  readln(f1,a[i]);
end;
function cal(c1,c2:char):longint;
begin
if c1=c2 then exit(1);
if c1='S' then if c2='P' then exit(2) else exit(0);
if c1='P' then if c2='R' then exit(2) else exit(0);
if c1='R' then if c2='S' then exit(2) else exit(0);
end;
procedure solve;
var
i,j,sum,x,y,z:longint;
begin
sum:=0;
for i:=1 to round do
for j:=1 to n do
sum+=cal(s[i],a[j,i]);
writeln(f2,sum);
sum:=0;
for i:=1 to round do
begin
x:=0; y:=0; z:=0;
for j:=1 to n do
begin
x+=cal('S',a[j,i]);
y+=cal('P',a[j,i]);
z+=cal('R',a[j,i]);
end;
sum+=max(max(x,y),z);
end;
writeln(f2,sum);
end;
begin
openF;
inp;
solve;
closeF;
end.

Code mẫu của hieult

#include <stdio.h>
//#include <conio.h>
#include <string.h>
int Maxx(int a,int b,int c)
  {
  int T=a;
  if(b>T) T=b;
  if(c>T) T=c;
  return T;
  }  
main()
{
int N,c[4][52],T,KQ=0,max=0;
char a[52],b[52][52];
scanf("%d",&N);
  scanf("%s",a);
//for(int j=0;j<N;j++)   
//printf("%c",a[j]);  
scanf("%d",&T);
for(int i=1;i<=T;i++)
  scanf("%s",b[i]);
for(int i=1;i<=T;i++)
  for(int j=0;j<N;j++)        
      {   
      if((b[i][j]=='S'&&a[j]=='R')||(b[i][j]=='R'&&a[j]=='P')||(b[i][j]=='P'&&a[j]=='S'))
        KQ+=2;
      if(b[i][j]==a[j])
        KQ+=1;   
      }    
for(int i=1;i<=3;i++)
  for(int j=0;j<N;j++)
    c[i][j]=0;    
for(long i=0;i<N;i++)
  {
  for(int j=1;j<=T;j++)
    {
    if(b[j][i]=='S')
    c[1][i]++;
    else if(b[j][i]=='R')
    c[2][i]++;
    else if(b[j][i]=='P')
    c[3][i]++;
    }
  max+=Maxx(2*c[1][i]+c[2][i],2*c[2][i]+c[3][i],2*c[3][i]+c[1][i]);
  }
printf("%d\n%d\n",KQ,max);
//getch();
}

Code mẫu của ll931110

Var s,p,r: array[1..50] of byte;
      n,k: byte;
  q,i,j,m: integer;
      x,y: string;
Function calc(i: byte): byte;
         Begin
             If x[i] = y[i] then exit(1);
             If ((x[i] = 'S') and (y[i] = 'R')) or ((x[i] = 'R') and (y[i] = 'P')) or ((x[i] = 'P') and (y[i] = 'S')) then exit(0);
             calc:= 2;
         End;
Function max(d,e,f: byte): byte;
         Begin
             max:= d;
             If max < e then max:= e;
             If max < f then max:= f;
         End;
Begin
  q:= 0;
  Fillchar(s, sizeof(s), 0);
  Fillchar(p, sizeof(p), 0);
  Fillchar(r, sizeof(r), 0);
  Readln(k); Readln(x); Readln(n);
  For i:= 1 to n do
  Begin
    Readln(y);
    For j:= 1 to k do
     Begin
       q:= q + calc(j);
       If y[j] = 'S' then inc(s[j])
       else if y[j] = 'R' then inc(r[j])
       else inc(p[j]);
     End;
  End;
  m:= 0;
  For i:= 1 to k do
   m:= m + max(2 * p[i] + s[i],2 * s[i] + r[i],2 * r[i] + p[i]);
  Writeln(q); Writeln(m);
End.

Code mẫu của skyvn97

#include<stdio.h>
#define MAX   55
int m,n;
char a[MAX];
char e[MAX][MAX];
int max(int x,int y,int z) {
    int m=x;
    if (m<y) m=y;
    if (m<z) m=z;
    return (m);
}
int score(char x,char y) {
    if (x==y) return (1);
    if (x=='S') return (2*(y=='P'));
    if (x=='P') return (2*(y=='R'));
    if (x=='R') return (2*(y=='S'));
}
void init(void) {
    int i,j;
    int s=0;
    scanf("%d",&m);
    scanf("%s",a);
    scanf("%d",&n);
    for (i=1;i<=n;i=i+1) {
        scanf("%s",e[i]);
        for (j=1;j<=m;j=j+1)
            s=s+score(a[j-1],e[i][j-1]);
    }
    printf("%d\n",s);
}
void process(void) {
    int s,p,r,best,i,j; 
    best=0;
    for (i=1;i<=m;i=i+1) {
        s=0;
        r=0;
        p=0;
        for (j=1;j<=n;j=j+1) {
            if (e[j][i-1]=='S') s++;
            if (e[j][i-1]=='P') p++;
            if (e[j][i-1]=='R') r++;
        }           
        best+=max(s+2*p,p+2*r,r+2*s);
    }
    printf("%d",best);
}
int main(void) {
    init();
    process();
}

Code mẫu của khuc_tuan

#include <iostream>
#include <cstdio>
using namespace std;

#define R(i,n) for(i=0;i<n;++i)
#define M(a,b) ((a)==(b)?1:((a)==((b)+1)%3?2:0))
int r, n, i, j, f[99], sum, best, z, t;
char s[55],a[55][55];

int main() {
    f['S']=0;f['R']=1;f['P']=2;
    cin>>r;
    gets(s);gets(s);
    R(i,r)s[i]=f[s[i]];
    cin>>n;
    gets(a[0]);
    R(i,n){gets(a[i]);R(j,r)a[i][j]=f[a[i][j]];
        R(j,r)sum+=M(s[j],a[i][j]);
    }
    cout<<sum<<endl;
    sum=0;
    R(i,r){
        best=0;
        R(t,3){
            z=0;
            R(j,n)z+=M(t,a[j][i]);
            if(best<z)best=z;
        }
        sum+=best;
    }
    cout<<sum<<endl;
    return 0;
}

Comments

Please read the guidelines before commenting.


There are no comments at the moment.