-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
289 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <iostream> | ||
#include <map> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
int n, m; | ||
cin >> n; | ||
map<string, string> alias; | ||
for(int i = 0; i < n; ++i){ | ||
string a, b; | ||
cin >> a >> b; | ||
alias[a] = b; | ||
} | ||
cin >> m; | ||
for(int i = 0; i < m; ++i){ | ||
string a, b; | ||
cin >> a >> b; | ||
if(alias.count(b)){ | ||
cout << a << " " << alias[b] <<endl; | ||
} | ||
else{ | ||
cout << a << " 0.0.0.0" << endl; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <iostream> | ||
#include <vector> | ||
|
||
using namespace std; | ||
|
||
const int ms = 100005; | ||
|
||
int n, m, vis[ms]; | ||
vector<int> edges[ms]; | ||
|
||
void dfs(int u){ | ||
vis[u] = true; | ||
for(int e : edges[u]){ | ||
if(!vis[e]) dfs(e); | ||
} | ||
} | ||
|
||
int main(){ | ||
cin >> n >> m; | ||
for(int i = 0; i < m; ++i){ | ||
int a,b; | ||
cin>>a>>b; | ||
a--, b--; | ||
edges[a].push_back(b); | ||
edges[b].push_back(a); | ||
} | ||
int ans = 0; | ||
for(int i = 0; i < n; ++i){ | ||
if(!vis[i]) { | ||
dfs(i); | ||
ans++; | ||
} | ||
} | ||
cout << ans << endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
#include <iostream> | ||
#include <vector> | ||
#include <string> | ||
#include <algorithm> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
int n, x; | ||
cin >> n >> x; | ||
string s; | ||
cin >> s; | ||
vector<string> v; | ||
vector<vector<int>> ans(n, vector<int>(n)); | ||
for (int i = 0; i < n; i++) { | ||
string s; | ||
cin >> s; | ||
v.push_back(s); | ||
} | ||
int words = 0; | ||
for (int i = 0; i < n; i++) { | ||
for (int j = 0; j < n; j++) { | ||
// Horizontal derecha | ||
if (j <= n - x) { | ||
string tmp; | ||
for (int k = j; k < j + x; k++) { | ||
tmp.push_back(v[i][k]); | ||
} | ||
if (tmp == s) { | ||
words++; | ||
for (int k = j; k < j + x; k++) { | ||
ans[i][k]++; | ||
} | ||
} | ||
} | ||
// Horizontal izquierda | ||
if (j >= x - 1) { | ||
string tmp; | ||
int limite = j - (x - 1); | ||
for (int k = j; k >= limite; k--) { | ||
tmp.push_back(v[i][k]); | ||
} | ||
if (tmp == s) { | ||
words++; | ||
for (int k = j; k >= limite; k--) { | ||
ans[i][k]++; | ||
} | ||
} | ||
} | ||
// Abajo | ||
if (i <= n - x) { | ||
string tmp; | ||
for (int k = i; k < i + x; k++) { | ||
tmp.push_back(v[k][j]); | ||
} | ||
if (tmp == s) { | ||
words++; | ||
for (int k = i; k < i + x; k++) { | ||
ans[k][j]++; | ||
} | ||
} | ||
} | ||
// Arriba | ||
if (i >= x - 1) { | ||
string tmp; | ||
int limite = (i - (x - 1)); | ||
for (int k = i; k >= limite; k--) { | ||
tmp.push_back(v[k][j]); | ||
} | ||
if (tmp == s) { | ||
words++; | ||
for (int k = i; k >= limite; k--) { | ||
ans[k][j]++; | ||
} | ||
} | ||
} | ||
// Diagonal arriba derecha | ||
if (i >= x - 1 and j <= n - x) { | ||
string tmp; | ||
int limite1 = (i - (x - 1)); | ||
int limite2 = j + x - 1; | ||
for (int k = i, l = j; k >= limite1 and l <= limite2; k--, l++) { | ||
tmp.push_back(v[k][l]); | ||
} | ||
if (tmp == s) { | ||
words++; | ||
for (int k = i, l = j; k >= limite1 and l <= limite2; k--, l++) { | ||
ans[k][l]++; | ||
} | ||
} | ||
} | ||
// Diagonal arriba izquierda | ||
if (i >= x - 1 and j >= x - 1) { | ||
string tmp; | ||
int limite1 = (i - (x - 1)); | ||
int limite2 = j - (x - 1); | ||
for (int k = i, l = j; k >= limite1 and l >= limite2; k--, l--) { | ||
tmp.push_back(v[k][l]); | ||
} | ||
if (tmp == s) { | ||
words++; | ||
for (int k = i, l = j; k >= limite1 and l >= limite2; k--, l--) { | ||
ans[k][l]++; | ||
} | ||
} | ||
} | ||
// Diagonal abajo derecha | ||
if (x > 1 and i <= n - x and j <= n - x) { | ||
string tmp; | ||
int limite1 = i + (x - 1); | ||
int limite2 = j + (x - 1); | ||
for (int k = i, l = j; k <= limite1 and l <= limite2; k++, l++) { | ||
tmp.push_back(v[k][l]); | ||
} | ||
if (tmp == s) { | ||
words++; | ||
for (int k = i, l = j; k <= limite1 and l <= limite2; k++, l++) { | ||
ans[k][l]++; | ||
} | ||
} | ||
} | ||
// Diagonal abajo izquierda | ||
if (i <= n - x and j >= x - 1) { | ||
string tmp; | ||
int limite1 = i + (x - 1); | ||
int limite2 = j - (x - 1); | ||
for (int k = i, l = j; k <= limite1 and l >= limite2; k++, l--) { | ||
tmp.push_back(v[k][l]); | ||
} | ||
if (tmp == s) { | ||
words++; | ||
for (int k = i, l = j; k <= limite1 and l >= limite2; k++, l--) { | ||
ans[k][l]++; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
int max_ = -1; | ||
for (int i = 0; i < n; i++) { | ||
int tmp = *max_element(ans[i].begin(), ans[i].end()); | ||
max_ = max(max_, tmp); | ||
} | ||
words -= max_; | ||
cout << words << endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <iostream> | ||
#include <algorithm> | ||
|
||
using namespace std; | ||
|
||
const int ms = 1e5 + 5; | ||
|
||
int n, a[ms], sum[ms]; | ||
|
||
int main(){ | ||
cin >> n; | ||
for(int i = 0; i < n; ++i){ | ||
cin >> a[i]; | ||
} | ||
sort(a, a+n); | ||
int cur = 0, ans = 0; | ||
for(int i = 0; i < n; ++i){ | ||
if(a[i] >= cur){ | ||
cur += a[i]; | ||
ans++; | ||
} | ||
} | ||
cout << ans << endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
int n; | ||
cin >> n; | ||
for(int i = 0; i < n; ++i){ | ||
if(i % 2 == 0){ | ||
for(int j = 0; j < n; ++j){ | ||
cout << i * n + j + 1 << " "; | ||
} | ||
} | ||
else{ | ||
for(int j = 0; j < n; ++j){ | ||
cout << (i + 1) * n - j << " "; | ||
} | ||
} | ||
cout<<endl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <iostream> | ||
#include <vector> | ||
|
||
using namespace std; | ||
|
||
vector<int> get_divs(int x){ | ||
vector<int> ans; | ||
for(int cur = 2; cur * cur <= x; cur++){ | ||
if(x % cur == 0){ | ||
ans.push_back(cur); | ||
while(x % cur == 0){ | ||
x /= cur; | ||
} | ||
} | ||
} | ||
if(x > 1){ | ||
ans.push_back(x); | ||
} | ||
return ans; | ||
} | ||
|
||
int main(){ | ||
int a, b; | ||
cin >> a >> b; | ||
vector<int> fa = get_divs(a); | ||
vector<int> fb = get_divs(b); | ||
for(int i : fa){ | ||
for(int j : fb){ | ||
if(i != j){ | ||
cout << "Party" << endl; | ||
cout << i << " " << j <<endl; | ||
return 0; | ||
} | ||
} | ||
} | ||
cout << "Sadge" << endl; | ||
} |