1. C++ / Говнокод #19254

    −19

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    void main_calc(double *j0, double  *v0, double  *r0, double  *L, double  *L1, double  *w0, double  *gamma1, int *Num, double **array, int *Ng)
    {
    	double *jc, *Pvh, *h, *vf, *R, *j0, *v0, *r0, *L,*L1, *w0, *gamma1, cm, vfm, *xi, *w, *b, *BB, *Num, E, v, z, t, k1[2], k2[2], k3[2], k4[2],TimeF,C0[mmax][pmax], gamma2[mmax][pmax];
    	const double PI = 3.14159265358979323;
    	int i, m, j, k, p, Size1, Size2;   
    	const int mmax = 3000, pmax = 20;
    	double *jc2, *Pvih;
    	double CJ, x;
    	int i1;
    	/*j0=new double;
    	v0=new double;
    	r0=new double;
    	L=new double;
    	L1=new double;
    	w0=new double;
    	gamma1=new double;
    	Num=new int;*/
    	ofstream fil;
    	fil.open("current");
    	Pvh = new double[*Num];
    	h = new double[*Num];
    	vf = new double[*Num];
    	R = new double[*Num];
    	//entry(j0,v0,r0,L,L1,w0,gamma1,Num, Pvh, h, vf, R); 
    	TimeF = *Ng*dt;
    	for (i = 0; i < *Num; i++){
    		Pvh[i] = array[0][i];
    		h[i] = array[1][i];
    		vf[i] = array[2][i];
    		R[i] = array[3][i];
    	}
    	Size1 = *L1 / dz1;
    	for (i = 0; i<*Num; i++) {
    		if (TimeF<(2 * PI / (h[i] * (*w0)))) {
    			TimeF = (2 * PI / (h[i] * (*w0)));
    		}
    	}
    	cout << "TimeF=" << TimeF << endl;
    	Size2 = 20 * PI / (*w0*dt1);
    	if (Size1>mmax) { cout << "Error: increase mmax!" << endl; }
    	cout << "Size1=" << Size1 << "  Size2=" << Size2 << endl;
    	//C0=new double[(Size1+5)*(Size2+5)];
    	//gamma2=new double[(Size1+5)*(Size2+5)];
    	jc = new double[*Ng];
    	jc2 = new double[*Ng];
    	b = new double[*Num];
    	w = new double[*Num];
    	xi = new double[*Num];
    	BB = new double[*Num];
    	ofstream fil2;
    	fil2.open("w");
    	for (i = 0; i<*Num; i++) {
    		w[i] = h[i] * (*w0);
    		fil2 << w[i] << endl;
    		b[i] = w[i] / vf[i];
    		cm = 3.0; vfm = vf[i] / 1e8;
    		xi[i] = w[i] * sqrt(1.0 / (cm*cm) + 1.0 / (vfm*vfm)) / 1e8;
    		BB[i] = (I0(xi[i] * (*r0))*I0(xi[i] * (*r0)) - I1(xi[i] * (*r0))*I1(xi[i] * (*r0)) - 1.0);
    		BB[i] = b[i] * sqrt(2.0*R[i] * Pvh[i] / (BB[i]));
    	}
    	fil2.close();
    	m = 0;
    	t = 0;
    	do  {
    		m = m + 1;
    		t = t + dt;
    		jc[m] = 0.0;
    	} while (t<TimeF);
    	//cout <<F1n(0.03,0,jc,BB,w,b,xi,r0) << endl;

    for (j = 0; j<*Num; j++) {
    i = 0;
    z = 0.0;
    do {
    C0[i][j] = BB[j]; //initial data
    gamma2[i][j] = 0.0; //initial data
    i = i + 1;
    z = z + dz1;
    } while (z<*L1);
    t = 0;
    do {
    C0[0][j] = BB[j]; //initial data
    gamma2[0][j] = 0.0; //initial data
    z = dz1;
    p = 1;
    do {
    C0[p][j] = C0[p][j] - (vf[j] * dt / dz1)*(C0[p][j] - C0[p - 1][j]) - vf[j] * dt*exp(-5 * z)*(F1n(z, j, jc2, BB, w, b, xi, r0)*cos(gamma2[p][j] * z) - F2n(z, j, jc2, BB, w, b, xi, r0)*sin(gamma2[p][j] * z)) / (4.0*PI*Pvh[j]);
    gamma2[p][j] = gamma2[p][j] - (vf[j] * dt / dz1)*(gamma2[p][j] - gamma2[p - 1][j]) + (vf[j] * dt / (C0[p][j] * z))*exp(-5 * z)*(F1n(z, j, jc2, BB, w, b, xi, r0)*sin(gamma2[p][j] * z) + F2n(z, j, jc2, BB, w, b, xi, r0)*cos(gamma2[p][j] * z)) / (4.0*PI*Pvh[j]);
    //this string for checking the result:
    cout << C0[p][j] << " " << gamma2[p][j] << endl;
    z = z + dz1;
    p = p + 1;
    } while (z<*L1);
    t = t + dt;
    } while (t<TimeF);
    Pvih[j] = C0[p - 3][j] * C0[p - 3][j] * (I0(xi[j] * (*r0))*I0(xi[j] * (*r0)) - I1(xi[j] * (*r0))*I1(xi[j] * (*r0)) - 1.0) / (2.0*R[j] * b[j] * b[j]);
    cout <<w[j]<<" "<< Pvih[j] << endl;
    fil1 << Pvih[j] << endl;
    }

    Запостил: GreatMASTERcpp, 27 Декабря 2015

    Комментарии (9) RSS

    • for (i = 1; i <= *Ng; i++) {
      v = *v0;
      z = 0.0;
      t = (i - 1)*dt;
      m = i - 1;
      jc2[0] = *j0;
      for (j = 0; j<*Num; j++) {
      i1 = 0;
      x = 0.0;
      do {
      C0[i1][j] = BB[j];
      gamma2[i1][j] = 0.0;
      i1 = i1 + 1;
      x = x + dz1;
      } while (x<*L1);
      }
      do {
      E = 0.0;
      for (j = 0; j<*Num; j++) {
      C0[0][j] = BB[j];
      gamma2[0][j] = 0.0;
      x = dz1;
      p = 1;
      do {C0[p][j] = C0[p][j] - (vf[j] * dt / dz1)*(C0[p][j] - C0[p - 1][j]) - vf[j] * dt*exp(-5 * x)*(F1n(x, j, jc, BB, w, b, xi, r0)*cos(gamma2[p][j] * x) - F2n(x, j, jc, BB, w, b, xi, r0)*sin(gamma2[p][j] * x)) / (4.0*PI*Pvh[j]);
      gamma2[p][j] = gamma2[p][j] - (vf[j] * dt / dz1)*(gamma2[p][j] - gamma2[p - 1][j]) + (vf[j] * dt / (C0[p][j] * x))*exp(-5 * x)*(F1n(x, j, jc, BB, w, b, xi, r0)*sin(gamma2[p][j] * x) + F2n(x, j, jc, BB, w, b, xi, r0)*cos(gamma2[p][j] * x)) / (4.0*PI*Pvh[j]);
      x = x + dz1;
      //cout <<x<<" "<< C0[p][j] <<" "<<gamma2[p][j]<<endl;
      p = p + 1;
      } while (x<*L1);
      x = 0.0;
      p = 0;
      do {
      if ((z<(x + dz1))&(z>x)) {
      CJ = C0[p][j] * exp(5 * z)*cos(z*gamma2[p][j]);
      }
      p = p + 1;
      x = x + dz1;
      } while (x<*L1);
      E = E + CJ*I0(xi[j] * (*r0))*cos(2.0*PI*(j + 1)*z / (*L))*cos(w[k] * t);
      }
      k1[1] = eta*E;
      k1[2] = v;

      v = v + (k1[1])*dt;
      z = z + (k1[2])*dt;
      t = t + dt;
      m = m + 1;
      //cout << z <<" "<< v <<endl;
      if (z <= *L1) {
      jc2[m] = jc2[m] + *j0*(*v0) / v;
      }
      else {
      t = TimeF;
      }
      cout << i << " " << m << " " << z << " " << v << endl;
      //fil3 << i << " " << m << " " << z << " " << v << endl;
      } while (t<TimeF);
      }
      Ответить
    • Ну и в таком же духе вся функция
      Ответить
    • main_kampf
      Ответить
    • я с вас фигею, уважаемые. Как будто обязательно выкладывать сюда каждую олимпиадную задачу которую вам сдали студенты, которых ВЫ же сами должны были научить кодить
      Ответить
      • Кто бы этого господина самого bbcode юзать научил для начала
        Ответить
    • >void main_calc(double *j0, double *v0, double *r0, double *L, double *L1, double *w0, double *gamma1, int *Num, double **array, int *Ng)

      > double *jc, *Pvh, *h, *vf, *R, *j0, *v0, *r0, *L,*L1, *w0, *gamma1, cm, vfm, *xi, *w, *b, *BB, *Num, E, v, z, t, k1[2], k2[2], k3[2], k4[2],TimeF,C0[mmax][pmax], gamma2[mmax][pmax];

      Можно было не продолжать. Потому дальше не читал.
      Ответить

    Добавить комментарий