Advertisement
a53

masterplace002_100PUNCTE

a53
Mar 14th, 2018
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <cmath>
  4. #define Dmax 505050
  5. using namespace std;
  6. unsigned short int TI[Dmax]; /// TI=Partea intreaga
  7. unsigned char TF[Dmax]; /// iar TF=partea fractionara
  8.  
  9. unsigned short readInt() /// Citirea numerelor intregi prin parsare
  10. {
  11. bool semn=false;
  12. unsigned short raspuns=0;
  13. char c;
  14. while(true)
  15. {
  16. c=getchar();
  17. if(c==EOF)
  18. return 1001;
  19. if(c=='-')
  20. {
  21. semn=true;
  22. break;
  23. }
  24. if(c>='0'&&c<='9')
  25. {
  26. raspuns=c-'0';
  27. break;
  28. }
  29. }
  30. while(true)
  31. {
  32. c=getchar();
  33. if(c<'0'||c>'9')
  34. break;
  35. raspuns=10*raspuns+c-'0';
  36. }
  37. if(semn)
  38. return -raspuns;
  39. return raspuns;
  40. }
  41.  
  42. int main()
  43. {
  44. int n=0; /// n=nr de segmente simple
  45. unsigned short X1,Y1,X2,Y2,a,b,r;
  46. bool SF_FIS=false;
  47. freopen("masterpiece002.in", "r",stdin);
  48. while(!SF_FIS)
  49. {
  50. X1=readInt();
  51. if(X1==1001)
  52. {
  53. SF_FIS=true;
  54. break;
  55. }
  56. Y1=readInt();X2=readInt();Y2=readInt();
  57. a=abs(X2-X1),b=abs(Y2-Y1); /// a=latura orizontala si b=latura verticala ale triunghiului
  58. if(b!=0)
  59. do /// Calculam CMMDC(a,b)
  60. {
  61. r=a%b;
  62. a=b;
  63. b=r;
  64. }
  65. while(r); /// in final a va fi cel mai mare divizor comun
  66. else
  67. if(a==0) /// pentru a prinde cazul particular in care ambele valori sunt 0
  68. a=1;
  69. /// (Y1==Y2&&abs(X2-X1)==1) <=> Segment orizontal de lungime 1
  70. /// (X1==X2&&abs(Y2-Y1)==1) <=> Segment vertical de lungime 1
  71. /// (X2==X1&&Y2==Y1&&abs(Y1-X1)==1) <=> Segment oblic de lungime 1
  72. float x;
  73. if(a==1||(Y1==Y2&&abs(X2-X1)==1)||(X1==X2&&abs(Y2-Y1)==1)||(X2==X1&&Y2==Y1&&abs(Y1-X1)==1)) /// Daca e segment simplu,
  74. {
  75. x=sqrt((X2-X1)*(X2-X1)+(Y2-Y1)*(Y2-Y1)); /// calculam distanta
  76. TI[n]=(int)x;TF[n++]=100*(x-(int)x); /// si o memoram in cei doi vectori
  77. }
  78. }
  79. int mij,st,dr,Lmax=0;
  80. short int M_2[n]; /// M_2 este M fara ultimele 2 cifre
  81. char M2[n]; /// M2 este M cu ultimele doua cifre
  82. for(int i=0;i<n;++i)
  83. {
  84. st=1;
  85. dr=Lmax;
  86. while(st<=dr) /// Cautare binara
  87. {
  88. mij=(st+dr)/2;
  89. int mij_c=M_2[mij]*100+M2[mij]; /// Valoarea lui M[mij]
  90. if(TI[mij_c]<=TI[i])
  91. {
  92. if(TI[mij_c]<TI[i]) /// Intregii sunt in relatia <
  93. st=mij+1;
  94. else /// Intregii sunt egali
  95. if(TF[mij_c]<=TF[i]) /// Fractiile sunt mai mici sau egale
  96. st=mij+1;
  97. else /// Fractiile sunt mai mari
  98. dr=mij-1;
  99. }
  100. else /// Intregii sunt mai mari
  101. dr=mij-1;
  102. }
  103. if(st>Lmax)
  104. Lmax=st;
  105. M_2[st]=i/100;M2[st]=i%100; /// pun pe i in cei doi vectori
  106. }
  107. freopen ("masterpiece002.out","w",stdout);
  108. cout<<Lmax<<'\n';
  109. return 0;
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement