Codeforces Round #692 (Div. 2, based on Technocup 2021 Elimination Round 3)A-C题
rating上1200,名字终于绿了,目前Div2能2题,下次继续保持,争取3题
1 #include<iostream> 2 #include<stdio.h> 3 #include<string> 4 using namespace std; 5 6 7 int main() 8 { 9 int t; 10 string s; 11 cin >> t; 12 int n; 13 while(t--){ 14 cin >> n; 15 cin>>s; 16 int x = 0; 17 int len = s.size(); 18 for (int i = s.size() - 1; i >= 0;i--){ 19 if(s[i]==')') 20 x++; 21 else 22 break; 23 } 24 if(x>len-x) 25 cout << "Yes" << endl; 26 else 27 cout << "No" << endl; 28 } 29 return 0; 30 }
本来以为是找规律,结果能直接莽过去......
1 #include<iostream> 2 #include<stdio.h> 3 using namespace std; 4 5 6 int main() 7 { 8 int t; 9 long long n; 10 cin >> t; 11 while(t--){ 12 cin >> n; 13 long long k = n; 14 int flag = 1; 15 while(1){ 16 k = n; 17 flag = 1; 18 while(k){ 19 if(k%10){ 20 if(n%(k%10)!=0){ 21 flag = 0; 22 break; 23 } 24 25 } 26 k /= 10; 27 } 28 if(flag){ 29 cout << n << endl; 30 break; 31 }else{ 32 n++; 33 } 34 } 35 } 36 return 0; 37 }
C题:(补题)(日常C题不会写...)
开始想到了走到对角线只有0,1,2三种情况
没有想到是并查集(其实不会并查集)
于是补了一下并查集
1 #include<iostream> 2 #include<stdio.h> 3 #include<map> 4 #include<string.h> 5 #include<cstring> 6 #include<stdbool.h> 7 #include<algorithm> 8 using namespace std; 9 10 //并查集:找图中是否又环 11 //这里是对着横纵坐标查找: 12 int n; 13 int m; 14 int x, y; 15 int ans; 16 int x_root; 17 int y_root; 18 int parent[200005] = {-1}; 19 20 int find_parent(int a) 21 { 22 int a_root=a; 23 while(parent[a_root]!=-1) 24 a_root = parent[a_root]; 25 return a_root; 26 } 27 28 void solve() 29 { 30 ans = 0; 31 cin >> n >> m; 32 for (int i = 1; i <= n;i++) 33 parent[i] = -1; 34 for (int i = 1; i <= m;i++){ 35 cin>>x>>y; 36 if(x==y) 37 continue; 38 ans++; 39 x_root = find_parent(x); 40 y_root = find_parent(y); 41 if(x_root==y_root) 42 ans++; 43 else 44 parent[x_root] = y_root; 45 } 46 cout << ans << endl; 47 } 48 49 int main() 50 { 51 int t; 52 cin >> t; 53 while(t--){ 54 solve(); 55 } 56 return 0; 57 }