ACM实验室2020.10.03 天梯赛一
7-1 谁先倒 (15分)
做法:就是先都输进去,之后判断,谁输谁就--,最后看谁先减到-1就行
//去吧马里奥!把AC公主救回来! // ******** // ************ // ####....#. // #..###.....##.... // ###.......###### // ........... // ##*####### // ####*******###### // ...#***.****.*###.... // ....**********##..... // ....**** *****.... // #### #### // ###### ###### #include<iostream> #include<algorithm> #include<cstdio> #include<cmath> #include<string> #include<map> #include<sstream> #include<cstring> #include<vector> #include<iomanip> #include<queue> #include<set> #define LL long long #define _64 __int64 const double PI = atan(1.)*4.; using namespace std; int main(){ int ajiu,bjiu; cin >> ajiu >> bjiu; int aa,bb; aa = ajiu; bb = bjiu; int t; cin >> t; int flaga = 0,flagb = 0; while(t--){ int a1,a2,b1,b2; cin >> a1 >> a2 >> b1 >> b2; int sum; sum = a1+b1; if(a2 == sum && b2 != sum){ ajiu--; }else if(b2 == sum && a2 != sum){ bjiu--; }else if(a2 == sum && b2 == sum && a2 == b2){ continue; }else{ continue; } if(ajiu == -1){ flaga =1; break; }else if(bjiu == -1){ flagb = 1; break; } } //cout << bb << ' ' << bjiu << endl; if(flaga == 1){ cout << "A" << endl; cout << bb-bjiu << endl; }else if(flagb == 1){ cout << "B" << endl; cout << aa-ajiu << endl; } }
7-2 重要的话说三遍 (5分)
代码:pass
7-3 奇偶分家 (10分)
做法:pass
代码:pass
7-4 输出GPLT (20分)
做法:就硬统计,硬输出
代码:
//去吧马里奥!把AC公主救回来! // ******** // ************ // ####....#. // #..###.....##.... // ###.......###### // ........... // ##*####### // ####*******###### // ...#***.****.*###.... // ....**********##..... // ....**** *****.... // #### #### // ###### ###### #include<iostream> #include<algorithm> #include<cstdio> #include<cmath> #include<string> #include<map> #include<sstream> #include<cstring> #include<vector> #include<iomanip> #include<queue> #include<set> #define LL long long #define _64 __int64 const double PI = atan(1.)*4.; using namespace std; int a[5]; int main(){ string s; cin >> s; for(int i = 0;i <s.size();i++){ if(s[i] == 'G' || s[i] == 'g'){ a[1]++; }else if(s[i] == 'P' || s[i] == 'p'){ a[2]++; }else if(s[i] == 'L' || s[i] == 'l'){ a[3]++; }else if(s[i] == 'T' || s[i] == 't'){ a[4]++; } } //cout << a[1] << a[2] << a[3] << a[4] << endl; while(a[1] > 0 || a[2] > 0 || a[3] > 0 || a[4] > 0){ if(a[1] > 0){ cout << 'G'; a[1] -= 1; } if(a[2] > 0){ cout << 'P'; a[2] -= 1; } if(a[3] > 0){ cout << 'L'; a[3] -= 1; } if(a[4] > 0){ cout << 'T'; a[4]-= 1; } //if(a[1] == 0 && a[2] == 0 && a[3] == 0 && a[4] == 0){ // break; //} } }
7-5 点赞
做法:循环统计出现的次数,因为数据范围很小,所以可以直接一个个枚举,找最大的就行
代码:
//去吧马里奥!把AC公主救回来! // ******** // ************ // ####....#. // #..###.....##.... // ###.......###### // ........... // ##*####### // ####*******###### // ...#***.****.*###.... // ....**********##..... // ....**** *****.... // #### #### // ###### ###### #include<iostream> #include<algorithm> #include<cstdio> #include<cmath> #include<string> #include<map> #include<sstream> #include<cstring> #include<vector> #include<iomanip> #include<queue> #include<set> #define LL long long #define _64 __int64 const double PI = atan(1.)*4.; using namespace std; int a[100005]; int main(){ int n; cin >> n; int k; int num; for(int i = 0;i < 100005;i++)a[i] = 0; int maxn,maxnum; maxn = 0,maxnum = 0; for(int i = 0;i <n;i++){ cin >> k; for(int j = 0;j < k;j++){ cin >> num; a[num]++; } } for(int i = 0;i <100005;i++){ if(a[i] >= maxn){ maxn = a[i]; maxnum = i; } } cout << maxnum <<" "<< maxn << endl; }
7-6 情人节 (15分)
代码:
//去吧马里奥!把AC公主救回来! // ******** // ************ // ####....#. // #..###.....##.... // ###.......###### // ........... // ##*####### // ####*******###### // ...#***.****.*###.... // ....**********##..... // ....**** *****.... // #### #### // ###### ###### #include<iostream> #include<algorithm> #include<cstdio> #include<cmath> #include<string> #include<map> #include<sstream> #include<cstring> #include<vector> #include<iomanip> #include<queue> #include<set> #define LL long long #define _64 __int64 const double PI = atan(1.)*4.; using namespace std; string a[20005]; int main(){ int i = 0; while(1){ string x; cin >>x; if(x == "."){ break; }else{ a[i] = x; } i++; } if(i >= 13){ cout << a[1] << ' ' << "and" << ' '<< a[13] << ' ' <<"are inviting you to dinner..."<< endl; }else if(i <13 && i>1 ){ cout << a[1] << ' ' << "is the only one for you..." << endl; }else{ cout << "Momo... No one is for you ..." << endl; } }
7-7 最佳情侣身高差 (10分)
做法:pass
//去吧马里奥!把AC公主救回来! // ******** // ************ // ####....#. // #..###.....##.... // ###.......###### // ........... // ##*####### // ####*******###### // ...#***.****.*###.... // ....**********##..... // ....**** *****.... // #### #### // ###### ###### #include<iostream> #include<algorithm> #include<cstdio> #include<cmath> #include<string> #include<map> #include<sstream> #include<cstring> #include<vector> #include<iomanip> #include<queue> #include<set> #define LL long long #define _64 __int64 const double PI = atan(1.)*4.; using namespace std; int main(){ int t; cin >> t; while(t--){ char sex; double length; cin >> sex >> length; double ans; if(sex == 'F'){ ans = length * 1.09; }else{ ans = length / 1.09; } printf("%.2f\n",ans); } }
7-8 宇宙无敌大招呼 (5分)
做法:pass
代码:pass
7-9 排座位 (25分)
代码:
//去吧马里奥!把AC公主救回来! // ******** // ************ // ####....#. // #..###.....##.... // ###.......###### // ........... // ##*####### // ####*******###### // ...#***.****.*###.... // ....**********##..... // ....**** *****.... // #### #### // ###### ###### #include<iostream> #include<algorithm> #include<cstdio> #include<cmath> #include<string> #include<map> #include<sstream> #include<cstring> #include<vector> #include<iomanip> #include<queue> #include<set> #define LL long long #define _64 __int64 const double PI = atan(1.)*4.; using namespace std; int a[200][200]; int main(){ int n,m,k; cin >> n >> m >> k; for(int i = 0;i < m;i++){ int x,y,z; cin >> x >> y >> z; a[x][y] = z; a[y][x] = a[x][y]; } for(int i = 0;i < k;i++){ int f1,f2; cin >> f1 >> f2; int flag = 0; if(a[f1][f2] == -1){ for(int j = 0;j < n;j++){ if(a[f1][j] * a[j][f2] == 1){ flag = 1; break; } } if(flag == 1){ cout << "OK but..." << endl; }else{ cout << "No way" << endl; } }else if(a[f1][f2] == 1){ cout << "No problem" << endl; }else{ cout << "OK" << endl; } } }
7-10 最长对称子串 (25分)
代码:
//去吧马里奥!把AC公主救回来! // ******** // ************ // ####....#. // #..###.....##.... // ###.......###### // ........... // ##*####### // ####*******###### // ...#***.****.*###.... // ....**********##..... // ....**** *****.... // #### #### // ###### ###### #include<iostream> #include<algorithm> #include<cstdio> #include<cmath> #include<string> #include<map> #include<sstream> #include<cstring> #include<vector> #include<iomanip> #include<queue> #include<set> #define LL long long #define _64 __int64 const double PI = atan(1.)*4.; using namespace std; bool com(string x){ for(int i = 0;i < x.length();i++){ if(x[i] == x[x.length()-1-i]){ continue; }else{ return false; } } return true; } int main(){ string s1,s2; getline(cin,s1); int ans = 0; int maxans = 0; //cout << s1 << endl; for(int i = 0;i <= s1.length()-1;i++){ for(int j = s1.length()-1;j >= i;j--){ if(s1[i] == s1[j]){ s2 = s1.substr(i,j-i+1); if(com(s2) == 1){ ans = s2.length(); if(ans > maxans){ maxans = ans; } } } } } cout << maxans << endl; return 0; }
7-11 重排链表
做法:看的题解,什么链表地址的看不太明白,意思和思路倒是知道了,思路就是开一个结构体,储存地址,数据以及后驱地址,开一个容器用来存所有的地址(其实我感觉用数组应该也行),之后开始print,注意控制格式,一次输出三个,上一行的后驱地址,下一行的地址以及数据,注意第一组数据和后来数据的输出差异,以及总数为奇数时处理
代码:
//去吧马里奥!把AC公主救回来! // ******** // ************ // ####....#. // #..###.....##.... // ###.......###### // ........... // ##*####### // ####*******###### // ...#***.****.*###.... // ....**********##..... // ....**** *****.... // #### #### // ###### ###### #include<iostream> #include<algorithm> #include<cstdio> #include<cmath> #include<string> #include<map> #include<sstream> #include<cstring> #include<vector> #include<iomanip> #include<queue> #include<set> #define LL long long #define _64 __int64 const double PI = atan(1.)*4.; using namespace std; struct x{ int add; int data; int nextadd; }ListNode[200005];; int main(){ vector<int>List; int addfirst,n; cin >> addfirst >> n; for(int i = 0;i < n;i++){ int x; cin >> x; cin >> ListNode[x].data ; cin >> ListNode[x].nextadd; ListNode[x].add = x; } while(addfirst != -1){ List.push_back(addfirst); addfirst = ListNode[addfirst].nextadd; } for(int i = 0;i < List.size()/2;i++){ if(i == 0){ printf("%05d %d ",List[List.size()-1-i],ListNode[List[List.size()-i-1]].data); }else{ printf("%05d\n%05d %d ",List[List.size()-1-i],List[List.size()-1-i],ListNode[List[List.size()-i-1]].data); } printf("%05d\n%05d %d ",List[i],List[i],ListNode[List[i]].data); } if(List.size() % 2 == 1){ printf("%05d\n%05d %d ",List[List.size()/2],List[List.size()/2],ListNode[List[List.size()/2]].data); } cout << -1; }
7-12 分而治之 (25分)
做法:题目目的是要每个城市孤立无援,即他周围的城市全部被灭,开一个结构体存每组的两个城市,开一个map用来储存某城市是否被灭,再循环判断即可,要是列出的城市所连接的城市都被灭了,那就是孤立无援,否则反之
//去吧马里奥!把AC公主救回来! // ******** // ************ // ####....#. // #..###.....##.... // ###.......###### // ........... // ##*####### // ####*******###### // ...#***.****.*###.... // ....**********##..... // ....**** *****.... // #### #### // ###### ###### #include<iostream> #include<algorithm> #include<cstdio> #include<cmath> #include<string> #include<map> #include<sstream> #include<cstring> #include<vector> #include<iomanip> #include<queue> #include<set> #define LL long long #define _64 __int64 const double PI = atan(1.)*4.; using namespace std; struct Type{ int c1,c2; }a[200005]; int b[20005]; int main(){ int N,M; cin >> N >> M; for(int i = 0;i < M;i++){ cin >> a[i].c1 >> a[i].c2; } int K; cin >> K; while(K--){ int np; cin >> np; map<int,int>mp; for(int i = 0;i < np;i++){ cin >> b[i]; mp[b[i]] = 1; } int flag = 1; for(int i = 0;i < M;i++){ if(mp[a[i].c1] != 1 && mp[a[i].c2] != 1){ cout << "NO" << endl; flag = 0; break; } } if(flag == 1){ cout << "YES" << endl; } } }

ACM实验室2020.10.03 天梯赛一
浙公网安备 33010602011771号