Advertisement
Fahim_7861

DDA ALGORITHRM

Mar 3rd, 2021
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. typedef unsigned long long ull;
  5. typedef pair<ll,ll>pll;
  6. typedef pair<ll,pair<ll,ll>>plll;
  7. #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
  8. #define vll(v) v.begin(),v.end()
  9. #define all(x) x.rbegin(),x.rend()
  10. #define min3(a, b, c) min(a, min(b, c))
  11. #define max3(a, b, c) max(a, max(b, c))
  12. #define sf(a) scanf("%d",&a)
  13. #define pf(a) printf("%d",a);
  14. #define F first
  15. #define S second
  16. #define in freopen("input.txt", "r", stdin)
  17. #define out freopen("output.txt", "w", stdout)
  18. #define minheap int,vector<int>,greater<int>
  19. #define pb push_back
  20. #define eb emplace_back
  21. #define ischar(x) (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
  22. #define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
  23. #define bug cout<<"BUG"<<endl;
  24. const int Max = 2e6 + 10;
  25. const int Mod = 1e9 + 7;
  26. const double PI =3.141592653589793238463;
  27. bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
  28. {
  29. return (a.first > b.first);
  30. }
  31. ll lcm(ll a,ll b)
  32. {
  33. if(a==0 || b==0)return 0;
  34.  
  35. return a/__gcd(a,b)*b;
  36. }
  37.  
  38. void input(ll ara[],ll n)
  39. {
  40. for(ll i=0; i<n; i++)cin>>ara[i];
  41. }
  42. void print(ll ara[],ll n)
  43. {
  44. for(ll i=0; i<n; i++)
  45. cout<<ara[i]<<" ";
  46. cout<<endl;
  47. }
  48.  
  49.  
  50. int main()
  51. {
  52.  
  53. fastread();
  54.  
  55. ll i,j,n,p,a,sum=0,k,t,c,d,cnt=0,q,l,r,ans=0;
  56.  
  57. bool flag=false;
  58.  
  59. string str;
  60.  
  61. double x1,x2,y1,y2,x,y,b;
  62.  
  63. cin>>x1>>y1>>x2>>y2;
  64.  
  65. double m=(y2-y1)/(x2-x1);
  66.  
  67.  
  68.  
  69. b=y1-(m*x1);
  70.  
  71.  
  72.  
  73. if( abs(m)<=1)
  74. {
  75. if(x1>x2)
  76. {
  77. swap(x1,x2);
  78. swap(y1,y2);
  79.  
  80. }
  81.  
  82. x=x1;
  83. y=y1;
  84.  
  85. while(x<=x2)
  86. {
  87. cout<<x<<" "<<round(y)<<endl;
  88.  
  89.  
  90.  
  91. x++;
  92. y+=m;
  93.  
  94. }
  95. }
  96. else
  97. {
  98.  
  99. if(y1>y2)
  100. {
  101. swap(x1,x2);
  102. swap(y1,y2);
  103.  
  104. }
  105.  
  106. x=x1;
  107. y=y1;
  108.  
  109. while(y<=y2)
  110. {
  111. cout<<round(x)<<" "<<y<<endl;
  112.  
  113. x+=(1.0/m);
  114. y++;
  115.  
  116. }
  117. }
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125. return 0;
  126.  
  127.  
  128. }
  129.  
  130.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement