Bhaiya , how can we make hashmap in this question?
Hashing right angled triangle
Hello @CODER_JATIN
U just have to store count of occurences of x and y so u can use two map of type map < int , int > or u can use array/ vector as hashmap where array indices can be treated as key and content as its value
bhaiya ye samajh ni aaya?
Tumhe is problem ka logic to pata hai na?
haa bs ye smjh ni aaya hashmap kese use krna isme
yaha pe mai ye bol raha tha ->
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
map<int, int> x_cnt, y_cnt;
vector<int> x(n), y(n);
for (int i = 0; i < n; ++i) {
cin >> x[i] >> y[i];
x_cnt[x[i]]++;
y_cnt[y[i]]++;
}
int ans = 0;
for (int i = 0; i < n; ++i) {
ans += (x_cnt[x[i]] - 1) * (y_cnt[y[i]] - 1);
}
cout << ans;
return 0;
}
agar ab bhi samjh nahi aaya to pucho
BHAIYA, hashmap mai bydefault value 0 hoti hai key ki ?
jese ham ye kar rhe hai x_cnt[x[i]]++; y_cnt[y[i]]++;
ha agar value hamari int hai to bydefault 0 hota hai
thik hai bhaiya ,
to Answer seedha yeh hi hoga na … (x_cnt[x[i]] - 1) * (y_cnt[y[i]] - 1);
loop ki kya jarurat
jarurat hai , tumhe har corrdinate ke corresponding ye formula lagana hoga na.
isme (x[i],y[i]) coordinate hi to hai.
hmm aa gya smjh bhaiya, thank you!
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.
bhaiya jese isme aapne do alag alag vector liye , to vector of pairr bhi le skte naa?
ha . . . . . . . . . . . . .
okay bhaiya . . . …
#include
#include
#include
using namespace std;
int main()
{
int n;
vector<pair<int , int > > p;
cin>>n;
int x, y;
for(int i=0;i<n;i++)
{
cin>>x>>y;
p.push_back({x,y});
}
for(int i=0;i<n;i++)
{
cout<<p[i].first<<",";
cout<<p[i].second<<"\n";
}
return 0;
}
dekhna bhaiya ese galat kyo aari output
bro code ko ide pe save karke send karo link
save nahi kiya hai tumne