Skip to content

Commit 70c9a46

Browse files
committed
leetcode contest
1 parent ee4ccfa commit 70c9a46

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
typedef long long ll ;
6+
typedef vector<int> vl;
7+
typedef vector<vector<int>> vvl;
8+
#define speed cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
9+
/* Abbrevations */
10+
#define ff first
11+
#define ss second
12+
#define mp make_pair
13+
#define pb push_back
14+
// Some print
15+
#define no cout<<"NO"<<endl;
16+
#define yes cout<<"YES"<<endl;
17+
// sort
18+
#define all(V) (V).begin(),(V).end()
19+
#define srt(V) sort(all(V))
20+
#define srtGreat(V) sort(all(V),greater<ll>())
21+
// some extra
22+
#define printv(v) for(ll i=0;i<ll(v.size());i++){cout<<v[i]<<" ";} cout<<endl;
23+
#define precision(x) cout<<fixed<<setprecision(x);
24+
#define sz(V) ll(V.size())
25+
26+
27+
/* ascii value
28+
A=65,Z=90,a=97,z=122
29+
*/
30+
31+
/* Some syntax
32+
//Syntax to create a min heap for priority queue
33+
//priority_queue <int, vector<int>, greater<int>>pq;
34+
*/
35+
/* --------------------MAIN PROGRAM----------------------------*/
36+
// to run ctrl+b
37+
const ll INF=1e18;
38+
const ll mod1=1e9+7;
39+
const ll mod2=998244353;
40+
// Techniques :
41+
// divide into cases, brute force, pattern finding
42+
// sort, greedy, binary search, two pointer
43+
// transform into graph
44+
45+
// Experience :
46+
// Cp is nothing but only observation and mathematics.
47+
48+
49+
//Add main code here
50+
51+
class Solution {
52+
public:
53+
int countLatticePoints(vector<vector<int>>& circles) {
54+
set<pair<int,int>> s;
55+
for(auto v:circles){
56+
int x_cordinates_start=v[0]-v[2];
57+
int x_cordinates_end=v[0]+v[2];
58+
int y_cordinates_start=v[1]-v[2];
59+
int y_cordinates_end=v[1]+v[2];
60+
// equation of cirlce with (h,k) as center and r as radius
61+
// (x-h)^2+(y-k)^2=r^2
62+
for(int x=x_cordinates_start;x<=x_cordinates_end;x++){
63+
for(int y=y_cordinates_start;y<=y_cordinates_end;y++){
64+
int value=((x-v[0])*(x-v[0]))+((y-v[1])*(y-v[1]))-v[2]*v[2];
65+
if(value<=0){
66+
s.insert({x,y});
67+
}
68+
}
69+
}
70+
}
71+
return s.size();
72+
}
73+
};
74+
75+
76+
/* -----------------END OF PROGRAM --------------------*/
77+
/*
78+
* stuff you should look before submission
79+
* constraint and time limit
80+
* int overflow
81+
* special test case (n=0||n=1||n=2)
82+
* don't get stuck on one approach if you get wrong answer
83+
*/

0 commit comments

Comments
 (0)