FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Source File · Jai4/Algorithms@1d241a7 · GitHub

Repository navigation

Commit 1d241a7

Browse files
committed
Source File
1 parent 40c7630 commit 1d241a7

3 files changed

Lines changed: 1260 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
typedef string sp;
5+
typedef char c;
6+
#define sz size_T
7+
#define forl(i,a,b) for(sz i=a;i<b;i++)
8+
#define pb push_back
9+
#define mp make_pair
10+
class solve
11+
{
12+
sp temp;
13+
public:
14+
void inpg()
15+
{
16+
cin >> temp;
17+
if(temp[1]=='+')
18+
{
19+
ll t1 = temp[0] - '0' ;
20+
ll t2 = temp[2] - '0' ;
21+
cout << t1+t2 << endl;
22+
}
23+
else if(temp[1]=='-')
24+
{
25+
ll t3 = temp[0] - '0' ;
26+
ll t4 = temp[2] - '0' ;
27+
if(t3>t4)
28+
{
29+
cout << t3-t4 << endl;
30+
}
31+
else if(t4>t3)
32+
{
33+
cout << -(t4-t3) << endl;
34+
}
35+
else
36+
{
37+
cout << 0 << endl;
38+
}
39+
}
40+
}
41+
};
42+
int main()
43+
{
44+
solve s;
45+
s.inpg();
46+
return 0;
47+
}
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
typedef vector<ll> vll;
5+
typedef pair<ll,ll> pll;
6+
typedef pair<pll,ll> ppll;
7+
typedef queue<ppll> qpll;
8+
#define sz size_t
9+
#define forl(i,a,b) for(sz i=a;i<b;i++)
10+
#define pb push_back
11+
#define mp make_pair
12+
ll a[301][301] = {0}; ll visited[301][301] = {0};
13+
class laptop
14+
{
15+
ll no,noq,xcor,ycor,weight,currweight;
16+
pll temp1,xy; ppll temp2,tem;
17+
qpll wait;
18+
vll xarray,yarray,power;
19+
ll maxweight=0,x1,y1 ;
20+
public:
21+
void inp()
22+
{
23+
cin >> no;
24+
cin >> noq;
25+
while(noq--)
26+
{
27+
cin >> xcor >> ycor >> weight ;
28+
// a[xcor][ycor] += weight;
29+
xarray.pb(xcor);
30+
yarray.pb(ycor);
31+
power.pb(weight);
32+
}
33+
forl(i,0,xarray.size())
34+
{
35+
36+
temp1 = mp(xarray[i],yarray[i]);
37+
temp2 = mp(temp1,power[i]);
38+
wait.push(temp2); // pushing (x,y) pair and weight as second cor ; pair((x,y),weight) :)
39+
a[xarray[i]][yarray[i]] += power[i];
40+
if( a[xarray[i]][yarray[i]]>maxweight)
41+
{
42+
maxweight = a[xarray[i]][yarray[i]];
43+
}
44+
while(wait.empty()==false)
45+
{
46+
tem = wait.front();
47+
wait.pop();
48+
movement();
49+
}
50+
51+
for(int i=0;i<no;i++)
52+
{
53+
for(int j=0;j<no;j++)
54+
{
55+
visited[i][j]=0;
56+
}
57+
}
58+
}
59+
/* for(int i=0;i<no;i++)
60+
{
61+
for(int j=0;j<no;j++)
62+
{
63+
cout << a[i][j] <<" " ;
64+
}
65+
cout << endl;
66+
}*/
67+
cout << maxweight << endl;
68+
}
69+
void movement()
70+
{
71+
72+
xy = tem.first ; currweight = tem.second;
73+
x1 = xy.first ; y1 = xy.second ; //x-cordinate and y-cordinate :)
74+
visited[x1][y1]=1;
75+
if(currweight>maxweight)
76+
{
77+
maxweight = currweight;
78+
}
79+
if (((x1+1 >=0)&&(x1+1<=no-1)) && ((y1+1>=0)&&(y1+1<=no-1))) //lowerrightdiag
80+
{
81+
if(currweight!=1)
82+
{
83+
if(visited[x1+1][y1+1]==0) // not visited before
84+
{
85+
visited[x1+1][y1+1]=1;
86+
a[x1+1][y1+1] = a[x1+1][y1+1] + currweight-1;
87+
if(a[x1+1][y1+1]>maxweight)
88+
{
89+
maxweight = a[x1+1][y1+1] ;
90+
}
91+
wait.push(mp(mp(x1+1,y1+1),currweight-1)); //pushed here :)
92+
}
93+
}
94+
}
95+
if (((x1+1 >=0)&&(x1+1<=no-1)) && ((y1>=0)&&(y1<=no-1))) //lowerpoint
96+
{
97+
if(currweight!=1)
98+
{
99+
if(visited[x1+1][y1]==0) // not visited before
100+
{
101+
visited[x1+1][y1]=1;
102+
a[x1+1][y1] = a[x1+1][y1] + currweight-1;
103+
if(a[x1+1][y1]>maxweight)
104+
{
105+
maxweight = a[x1+1][y1] ;
106+
}
107+
wait.push(mp(mp(x1+1,y1),currweight-1)); //pushed here :)
108+
}
109+
}
110+
}
111+
if (((x1+1 >=0)&&(x1+1<=no-1)) && ((y1-1>=0)&&(y1-1<=no-1))) //lowerleftdiag
112+
{
113+
if(currweight!=1)
114+
{
115+
if(visited[x1+1][y1-1]==0) // not visited before
116+
{
117+
visited[x1+1][y1-1]=1;
118+
a[x1+1][y1-1] = a[x1+1][y1-1] + currweight-1;
119+
if(a[x1+1][y1-1]>maxweight)
120+
{
121+
maxweight = a[x1+1][y1-1] ;
122+
}
123+
wait.push(mp(mp(x1+1,y1-1),currweight-1)); //pushed here :)
124+
}
125+
}
126+
}
127+
if (((x1 >=0)&&(x1<=no-1)) && ((y1-1>=0)&&(y1-1<=no-1))) //leftpoint
128+
{
129+
if(currweight!=1)
130+
{
131+
if(visited[x1][y1-1]==0) // not visited before
132+
{
133+
visited[x1][y1-1]=1;
134+
a[x1][y1-1] =a[x1][y1-1] + currweight-1;
135+
if(a[x1][y1-1]>maxweight)
136+
{
137+
maxweight = a[x1][y1-1] ;
138+
}
139+
wait.push(mp(mp(x1,y1-1),currweight-1)); //pushed here :)
140+
}
141+
}
142+
}
143+
if (((x1 >=0)&&(x1<=no-1)) && ((y1+1>=0)&&(y1+1<=no-1))) //rightpoint
144+
{
145+
if(currweight!=1)
146+
{
147+
if(visited[x1][y1+1]==0) // not visited before
148+
{
149+
visited[x1][y1+1]=1;
150+
a[x1][y1+1] = a[x1][y1+1] + currweight-1;
151+
if(a[x1][y1+1]>maxweight)
152+
{
153+
maxweight = a[x1][y1+1] ;
154+
}
155+
wait.push(mp(mp(x1,y1+1),currweight-1)); //pushed here :)
156+
}
157+
}
158+
}
159+
if (((x1-1 >=0)&&(x1-1 <=no-1)) && ((y1+1>=0)&&(y1+1<=no-1))) //upperrightdiag
160+
{
161+
if(currweight!=1)
162+
{
163+
if(visited[x1-1][y1+1]==0) // not visited before
164+
{
165+
visited[x1-1][y1+1]=1;
166+
a[x1-1][y1+1] = a[x1-1][y1+1] + currweight-1;
167+
if(a[x1-1][y1+1] > maxweight)
168+
{
169+
maxweight = a[x1-1][y1+1] ;
170+
}
171+
wait.push(mp(mp(x1-1,y1+1),currweight-1)); //pushed here :)
172+
}
173+
}
174+
}
175+
if (((x1-1 >=0)&&(x1-1 <=no-1)) && ((y1-1>=0)&&(y1-1<=no-1))) //upperleftdiag
176+
{
177+
if(currweight!=1)
178+
{
179+
if(visited[x1-1][y1-1]==0) // not visited before
180+
{
181+
visited[x1-1][y1-1]=1;
182+
a[x1-1][y1-1] = a[x1-1][y1-1] + currweight-1;
183+
if(a[x1-1][y1-1]>maxweight)
184+
{
185+
maxweight = a[x1-1][y1-1];
186+
}
187+
wait.push(mp(mp(x1-1,y1-1),currweight-1)); //pushed here :)
188+
}
189+
}
190+
}
191+
if (((x1-1 >=0)&&(x1-1 <=no-1)) && ((y1>=0)&&(y1<=no-1))) //upperpoint
192+
{
193+
if(currweight!=1)
194+
{
195+
if(visited[x1-1][y1]==0) // not visited before
196+
{
197+
visited[x1-1][y1]=1;
198+
a[x1-1][y1] = a[x1-1][y1] + currweight-1;
199+
if(a[x1-1][y1]> maxweight)
200+
{
201+
maxweight = a[x1-1][y1];
202+
}
203+
wait.push(mp(mp(x1-1,y1),currweight-1)); //pushed here :)
204+
}
205+
}
206+
}
207+
208+
209+
210+
}
211+
};
212+
int main()
213+
{
214+
laptop p;
215+
p.inp();
216+
return 0;
217+
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL