Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin ("marte.in");
- ofstream fout ("marte.out");
- int n,e,p,st,dr,mat[105][105],roci=0,st2,dr2,indice,indice2,ok,copie;
- int main()
- {
- fin >> n >> e >> p >> st >> dr;
- for(int i=1;i<=n;++i)
- {
- for(int j=1;j<=n;++j)
- fin >> mat[i][j];
- }
- for(int i=1;i<=p;++i)
- {
- fin >> st2 >> dr2;
- if(st>st2)
- {
- indice = st;
- indice2 = dr;
- copie = 1;
- ok=1;
- while(ok==1)
- {
- if(abs(mat[st][dr]-mat[indice][indice2-copie]))
- {
- ok=1;
- if(indice==st2 && indice2-copie==dr2)
- {
- roci++;
- ok=0;
- }
- else if(indice2-copie==1)
- {
- indice--;
- indice2 = n;
- if(indice==st2 && indice2==dr)
- {
- roci++;
- ok=0;
- }
- else
- copie=1;
- }
- copie++;
- }
- }
- }
- else if(st2>st)
- {
- indice = st;
- indice2 = dr;
- copie = 1;
- ok=1;
- while(ok==1)
- {
- if(abs(mat[st][dr]-mat[indice][indice2+copie])<=e)
- {
- ok=1;
- if(indice==st2 && indice2+copie == dr2)
- {
- roci++;
- ok=0;
- }
- if(indice2+copie==n)
- {
- indice++;
- indice2=1;
- if(st2==indice && indice2 == dr2)
- {
- roci++;
- ok=0;
- }
- else
- copie = 0;
- }
- copie++;
- }
- else
- ok=0;
- }
- }
- else if(st==st2)
- {
- if(dr2>dr)
- {
- indice = st;
- indice2 = dr;
- ok=1;
- copie = 1;
- while(ok==1)
- {
- if(abs(mat[st][dr]-mat[indice][indice2+copie])<=e)
- {
- ok=1;
- if(indice==st2 && indice2+copie == dr2)
- {
- roci++;
- ok=0;
- }
- if(dr+indice2==n)
- {
- indice++;
- indice2 = 1;
- if(st2==indice && dr2==indice2)
- {
- roci++;
- ok=0;
- }
- else
- copie = 1;
- }
- copie++;
- }
- else
- ok=0;
- }
- }
- else if(dr>dr2)
- {
- indice = st;
- indice2 = dr;
- copie = 1;
- ok=1;
- while(ok==1)
- {
- if(abs(mat[st][dr]==mat[indice][indice2-copie]))
- {
- if(indice==st2 && indice2-copie == dr2)
- {
- roci++;
- ok=0;
- }
- if(indice2-copie==1)
- {
- indice--;
- indice2 = n;
- if(indice==st2 && indice2==dr2)
- {
- roci++;
- ok=0;
- }
- else
- copie=0;
- }
- copie++;
- }
- }
- }
- else if(dr==dr2)
- roci++;
- }
- }
- fout << roci;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement