Skip to content

Commit ea6aeda

Browse files
committed
simple
1 parent 51651b7 commit ea6aeda

File tree

7 files changed

+311
-51
lines changed

7 files changed

+311
-51
lines changed

Graph Practice/adj_list.cpp

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
#define flush cin.ignore(numeric_limits<streamsize>::max(),'\n')
5+
#define FASTERIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
6+
#define NL cout<<'\n';
7+
#define pi acos(-1.0) //3.1415926535897932384626
8+
#define pb push_back
9+
#define mx 10000007
10+
#define AC int
11+
#define EPS 1e-10
12+
#define dpoint(x) fixed<<setprecision(x)
13+
typedef long long int ll;
14+
typedef double dl;
15+
typedef unsigned long long ul;
16+
template <class T> T digitsum(T n){T sum=0;while(n!=0){sum+=n%10;n/=10;}return sum;}
17+
int gcd(int a, int b){ int x ; return x = __gcd(a, b);}
18+
int lcm(int a, int b){int y; return y = ((a)*((b)/gcd(a,b)));}
19+
20+
// Debugger
21+
#define debugNS(a,b) cout<<a<<" = "<<b<<endl;
22+
#define debugN(b) cout<<b<<endl;
23+
24+
string DecimalToBinary(int n){
25+
26+
string res="";
27+
for(int i=31; i>=0; i--){
28+
int k = n & (1<<i);
29+
res += (n&k)?'1':'0';
30+
}
31+
return res;
32+
}
33+
int BinaryToDecimal(string s){
34+
int ans = 0;
35+
for(int i=0; i<s.size(); i++){
36+
ans = (2*ans)+s[i]-'0';
37+
}
38+
return ans;
39+
}
40+
41+
42+
int main(){
43+
44+
#ifdef anikakash
45+
clock_t tStart = clock();
46+
freopen("INPUT.txt","r",stdin);
47+
freopen("OUTPUT.txt","w",stdout);
48+
#endif
49+
50+
FASTERIO;
51+
int NumberofNode, NumberofEdge;
52+
cin>>NumberofNode>>NumberofEdge;
53+
54+
vector<int>Edge[11];
55+
vector<int>cost[11];
56+
57+
58+
for(int i=0; i<NumberofEdge; i++){
59+
int x,y,c; cin>>x>>y>>c;
60+
Edge[x].pb(y); cost[x].pb(c);
61+
Edge[y].pb(x); cost[y].pb(c);
62+
}
63+
64+
for(int i=1; i<=NumberofNode; i++){
65+
cout<<i<<" -> ";
66+
for(int j=0; j<Edge[i].size(); j++){
67+
cout<<Edge[i][j]<<" ";
68+
}
69+
NL;
70+
cout<<"Cost ";
71+
for(int j=0; j<cost[i].size(); j++){
72+
cout<<cost[i][j]<<" ";
73+
}
74+
NL;
75+
}
76+
77+
int a,b; cin>>a>>b;
78+
bool flg = false;
79+
for(int i=0; i<Edge[a].size(); i++){
80+
if(Edge[a][i]==b){
81+
cout<<"Coast IS : "<<cost[a][i]<<endl;
82+
flg = true; break;
83+
}
84+
}
85+
if(!flg)cout<<-1<<endl;
86+
87+
#ifdef anikakash
88+
fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
89+
#endif
90+
return 0;
91+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
#define flush cin.ignore(numeric_limits<streamsize>::max(),'\n')
5+
#define FASTERIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
6+
#define NL cout<<'\n';
7+
#define pi acos(-1.0) //3.1415926535897932384626
8+
#define pb push_back
9+
#define mx 10000007
10+
#define AC int
11+
#define EPS 1e-10
12+
#define dpoint(x) fixed<<setprecision(x)
13+
typedef long long int ll;
14+
typedef double dl;
15+
typedef unsigned long long ul;
16+
template <class T> T digitsum(T n){T sum=0;while(n!=0){sum+=n%10;n/=10;}return sum;}
17+
int gcd(int a, int b){ int x ; return x = __gcd(a, b);}
18+
int lcm(int a, int b){int y; return y = ((a)*((b)/gcd(a,b)));}
19+
20+
// Debugger
21+
#define debugNS(a,b) cout<<a<<" = "<<b<<endl;
22+
#define debugN(b) cout<<b<<endl;
23+
24+
25+
int main(){
26+
27+
#ifdef anikakash
28+
clock_t tStart = clock();
29+
freopen("INPUT.txt","r",stdin);
30+
freopen("OUTPUT.txt","w",stdout);
31+
#endif
32+
33+
FASTERIO;
34+
35+
36+
int t;cin>>t;
37+
for(int caseno=1; caseno<=t; caseno++){
38+
int n; cin>>n;
39+
vector<pair<ll,ll>>vp;
40+
41+
for(int i=0; i<n; i++){
42+
int x,y; cin>>x>>y;
43+
vp.pb(make_pair(x,y));
44+
}
45+
46+
sort(vp.begin(), vp.end());
47+
48+
dl ans = 0.0;
49+
50+
for(int i=0; i<n; i++){
51+
ll time = vp[i+1].first - vp[i].first;
52+
ll distance = abs(vp[i+1].second - vp[i].second);
53+
ans = max(ans, (dl)distance/time);
54+
}
55+
cout<<"Case #"<<caseno<<": "<<dpoint(2)<<ans<<endl;
56+
57+
}
58+
59+
#ifdef anikakash
60+
fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
61+
#endif
62+
return 0;
63+
}

Template/Help

4.1 KB
Binary file not shown.

Template/Help.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ typedef unsigned long long ul;
1717
#define debugNS(a,b) cout<<a<<" = "<<b<<endl;
1818
#define debugN(b) cout<<b<<endl;
1919

20-
20+
int dx[] = {0, 0, -1, 1, -1, -1, 1, 1}; //Graph Move;
21+
int dy[] = {1, -1, 0, 0, -1, 1, -1, 1};
2122

2223
int main(){
2324

@@ -26,19 +27,13 @@ int main(){
2627
freopen("INPUT.txt","r",stdin);
2728
freopen("OUTPUT.txt","w",stdout);
2829
#endif
30+
2931
FASTERIO;
32+
33+
3034

3135

32-
bool m[5][5]={true};
33-
for(int i=0; i<5; i++){
34-
for(int j=0; j<5; j++){
35-
36-
cout<<m[i][j]<<" ";
37-
}
38-
NL;
39-
}
40-
41-
36+
4237
#ifdef anikakash
4338
fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
4439
#endif

Template/Main

5.23 KB
Binary file not shown.

Template/Main.cpp

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ int lcm(int a, int b){int y; return y = ((a)*((b)/gcd(a,b)));}
2121
#define debugNS(a,b) cout<<a<<" = "<<b<<endl;
2222
#define debugN(b) cout<<b<<endl;
2323

24+
int dx[] = {0, 0, -1, 1, -1, -1, 1, 1}; //Graph Move;
25+
int dy[] = {1, -1, 0, 0, -1, 1, -1, 1};
26+
2427
string DecimalToBinary(int n){
2528

2629
string res="";
@@ -38,58 +41,63 @@ int BinaryToDecimal(string s){
3841
return ans;
3942
}
4043

41-
void An(int i,int n){
42-
if(i==n+1)return;
43-
cout<<"sin("<<i;
44-
if(i%2==1 && i!=n)cout<<"-";
45-
else if(i%2==0 && i!=n) cout<<"+";
46-
An(i+1, n);
47-
cout<<")";
48-
}
49-
void Sn(int i, int n){
50-
if(n==0)return;
51-
An(1,i);
52-
//cout<<")";
53-
cout<<"+"<<n;
54-
if(n>1)cout<<")";
55-
Sn(i+1,n-1);
44+
vector<string>v;
45+
int n;
46+
47+
void dfs(int i, int j){
48+
49+
if(v[i][j]=='1'){
50+
v[i][j]='0';
51+
if(j<n-1)dfs(i,j+1); // right
52+
if(j>0)dfs(i,j-1); // left
53+
if(i>0)dfs(i-1,j); // upper
54+
if(i<n-1)dfs(i+1, j); // Down
55+
if(i>0 && j>0)dfs(i-1, j-1); // upper left
56+
if(i>0 && j<n-1)dfs(i-1, j+1); // upper right
57+
if(i<n-1 && j>0)dfs(i+1, j-1); // down left
58+
if(i<n-1 && j<n-1)dfs(i+1, j+1); // dwon right
59+
}
60+
else return;
61+
5662
}
63+
5764
int main(){
5865

5966
#ifdef anikakash
6067
clock_t tStart = clock();
6168
freopen("INPUT.txt","r",stdin);
62-
freopen("OUTPUT.txt","w",stdout);
69+
freopen("OUTPUT.txt","w",stdout);
6370
#endif
6471

65-
FASTERIO;
66-
67-
int n, i=0;
68-
cin>>n;
69-
while(n--){
70-
int a,b; cin>>a>>b;
71-
vector<int>v;
72-
for(int i=0; i<a; i++){
73-
if(a-(b+i)>0)v.pb(0);
74-
else v.pb(1);
75-
}
76-
if(i>0)NL;
77-
do{
78-
for(auto i:v)
79-
cout<<i;
80-
NL;
81-
}while(next_permutation(v.begin(), v.end()));
82-
i++;
72+
FASTERIO; //cmt when use scanf & printf ;
8373

74+
int caseno=0;
75+
while(cin>>n){
76+
caseno++;
77+
for(int i=0; i<n; i++){
78+
string s; cin>>s;
79+
v.pb(s);
8480
}
81+
int cnt=0;
82+
for (int i = 0; i<n; i++){
83+
for(int j=0; j<n; j++){
84+
if(v[i][j]=='1'){
85+
cnt++;
86+
dfs(i,j);
87+
}
88+
}
89+
}
90+
cout<<"Image number "<<caseno<<" contains "<<cnt<<" war eagles."<<endl;
91+
v.clear();
92+
}
93+
94+
95+
96+
8597

8698
#ifdef anikakash
8799
fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
88100
#endif
89-
return 0;
90-
}
91-
/*
92-
93-
94101

95-
*/
102+
return 0;
103+
}

0 commit comments

Comments
 (0)