Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Problema{
- private double dificultate;
- public Problema(){
- dificultate=Math.random();
- }
- public double getDific(){
- return dificultate;
- }
- }
- abstract class Concurent{
- protected int nrProbleme=0;
- protected int timpTotal=0;
- protected double gradPregatire;
- public Concurent(){
- gradPregatire=Math.random();
- }
- public void rezolvaProblema(Problema p){
- if(gradPregatire>=p.getDific())
- {
- this.nrProbleme++;
- if(p.getDific()>=0.5) this.timpTotal+=((int)(1-gradPregatire)*2000);
- else this.timpTotal+=((int)(1-gradPregatire)*1000);
- }
- }
- }
- class ConcurentIncepator extends Concurent{
- public ConcurentIncepator(){
- super();
- }
- public void rezolvaProblema(Problema p){
- super.rezolvaProblema(p);
- }
- }
- class ConcurenExperimentat extends Concurent{
- Concurs[] concursuri=new Concurs[100];
- public ConcurenExperimentat(Concurs[] conc){
- super();
- concursuri=new Concurs[2*conc.length];
- this.concursuri=conc;
- }
- public void rezolvaProblema(Problema p){
- for(int i=0;i<concursuri.length;i++)
- for(int j=0;j<concursuri[i].probl.length;j++)
- if(p.equals(concursuri[i].probl[i])) this.timpTotal=this.timpTotal;
- else rezolvaProblema(p);
- }
- }
- class Concurs{
- protected Concurent[] conc=new Concurent[100];
- protected Problema[] probl=new Problema[100];
- protected int nrProbl;
- public Concurs(int nrProbl){
- if(nrProbl>100) probl=new Problema[2*nrProbl];
- this.nrProbl=nrProbl;
- for(int i=0;i<nrProbl;i++)
- probl[i]=new Problema();
- }
- public Concurent getCastigator(){
- int maxP=0;
- int cnt1=-1;
- int cnt2=-1;
- for(int i=0;i<conc.length;i++)
- if(conc[i].nrProbleme>maxP) {
- cnt2=cnt1;
- maxP=conc[i].nrProbleme;
- cnt1=i;
- }
- if(cnt1==cnt2) {
- if(conc[cnt1].timpTotal<conc[cnt2].timpTotal) return conc[cnt1];
- else return conc[cnt2];
- }
- else return conc[cnt1];
- }
- public void start(){
- for(int i=0;i<conc.length;i++)
- {
- for(int j=0;j<nrProbl;j++)
- conc[i].rezolvaProblema(probl[j]);
- }
- }
- public int nrConc(){
- return conc.length;
- }
- }
- class ConcursSimplu extends Concurs{
- public ConcursSimplu(Concurent[] conc,int probleme){
- super(probleme);
- if(conc.length>100) super.conc=new Concurent[2*conc.length];
- super.conc=conc;
- }
- }
- class ConcursRegional extends Concurs{
- Concurs[] subConcurs=new Concurs[100];
- public ConcursRegional(Concurs[] sub,int probleme){
- super(probleme);
- if(sub.length>100) subConcurs=new Concurs[sub.length];
- this.subConcurs=sub;
- }
- public void start(){
- int x;
- for(int i=0;i<subConcurs.length;i++)
- {
- super.start();
- x=super.nrConc();
- conc[x++]=subConcurs[i].getCastigator();
- }
- super.start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement