Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. class Problema{
  2. private double dificultate;
  3.  
  4. public Problema(){
  5. dificultate=Math.random();
  6. }
  7.  
  8. public double getDific(){
  9. return dificultate;
  10. }
  11. }
  12.  
  13. abstract class Concurent{
  14. protected int nrProbleme=0;
  15. protected int timpTotal=0;
  16. protected double gradPregatire;
  17.  
  18. public Concurent(){
  19. gradPregatire=Math.random();
  20. }
  21.  
  22. public void rezolvaProblema(Problema p){
  23. if(gradPregatire>=p.getDific())
  24. {
  25. this.nrProbleme++;
  26. if(p.getDific()>=0.5) this.timpTotal+=((int)(1-gradPregatire)*2000);
  27. else this.timpTotal+=((int)(1-gradPregatire)*1000);
  28. }
  29. }
  30. }
  31.  
  32. class ConcurentIncepator extends Concurent{
  33. public ConcurentIncepator(){
  34. super();
  35. }
  36.  
  37. public void rezolvaProblema(Problema p){
  38. super.rezolvaProblema(p);
  39. }
  40. }
  41.  
  42. class ConcurenExperimentat extends Concurent{
  43. Concurs[] concursuri=new Concurs[100];
  44.  
  45. public ConcurenExperimentat(Concurs[] conc){
  46. super();
  47. concursuri=new Concurs[2*conc.length];
  48. this.concursuri=conc;
  49. }
  50.  
  51. public void rezolvaProblema(Problema p){
  52. for(int i=0;i<concursuri.length;i++)
  53. for(int j=0;j<concursuri[i].probl.length;j++)
  54. if(p.equals(concursuri[i].probl[i])) this.timpTotal=this.timpTotal;
  55. else rezolvaProblema(p);
  56. }
  57.  
  58. }
  59.  
  60. class Concurs{
  61. protected Concurent[] conc=new Concurent[100];
  62. protected Problema[] probl=new Problema[100];
  63. protected int nrProbl;
  64.  
  65. public Concurs(int nrProbl){
  66. if(nrProbl>100) probl=new Problema[2*nrProbl];
  67. this.nrProbl=nrProbl;
  68. for(int i=0;i<nrProbl;i++)
  69. probl[i]=new Problema();
  70. }
  71.  
  72. public Concurent getCastigator(){
  73. int maxP=0;
  74. int cnt1=-1;
  75. int cnt2=-1;
  76. for(int i=0;i<conc.length;i++)
  77. if(conc[i].nrProbleme>maxP) {
  78. cnt2=cnt1;
  79. maxP=conc[i].nrProbleme;
  80. cnt1=i;
  81. }
  82. if(cnt1==cnt2) {
  83. if(conc[cnt1].timpTotal<conc[cnt2].timpTotal) return conc[cnt1];
  84. else return conc[cnt2];
  85. }
  86. else return conc[cnt1];
  87. }
  88.  
  89. public void start(){
  90. for(int i=0;i<conc.length;i++)
  91. {
  92. for(int j=0;j<nrProbl;j++)
  93. conc[i].rezolvaProblema(probl[j]);
  94. }
  95. }
  96.  
  97. public int nrConc(){
  98. return conc.length;
  99. }
  100. }
  101.  
  102. class ConcursSimplu extends Concurs{
  103. public ConcursSimplu(Concurent[] conc,int probleme){
  104. super(probleme);
  105. if(conc.length>100) super.conc=new Concurent[2*conc.length];
  106. super.conc=conc;
  107. }
  108. }
  109.  
  110. class ConcursRegional extends Concurs{
  111. Concurs[] subConcurs=new Concurs[100];
  112.  
  113. public ConcursRegional(Concurs[] sub,int probleme){
  114. super(probleme);
  115. if(sub.length>100) subConcurs=new Concurs[sub.length];
  116. this.subConcurs=sub;
  117. }
  118.  
  119. public void start(){
  120. int x;
  121. for(int i=0;i<subConcurs.length;i++)
  122. {
  123. super.start();
  124. x=super.nrConc();
  125. conc[x++]=subConcurs[i].getCastigator();
  126. }
  127. super.start();
  128. }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement