2021暑假康复性训练
Codeforces Round #731 (Div. 3)
A Shortest Path with Obstacle
input
7 1 1 3 3 2 2 2 5 2 1 2 3 1000 42 1000 1 1000 1000 1 10 3 10 2 10 3 8 7 8 3 7 2 1 4 1 1 1 1 344 1 10 1 1
output
4 6 41 4 4 2 334
code:
int main() { int _ = read; while(_ --){ int x1 = read,y1 = read; int x2 = read,y2 = read; int tx1 = read,ty1 = read; int ans = abs(x1 - x2) + abs(y1 - y2); if(x1 == x2 && x2 == tx1 && ty1 >= min(y1,y2) && ty1 <= max(y2,y1)) ans += 2; if(y1 == y2 && y2 == ty1 && tx1 >= min(x1,x2) && tx1 <= max(x1,x2)) ans += 2; printf("%d\n",ans); } return 0; }
B. Alphabetical Strings
input
11 a ba ab bac ihfcbadeg z aa ca acb xyz ddcba
output:
YES YES YES YES YES NO NO NO NO NO NO
Note
The example contains test cases from the main part of the condition.
code:
int main() { int _ = read; while(_ --){ char str[100]; cin >> (str + 1); int len = strlen(str + 1); int l = 1,r = len; int flag = 0; for(int i = len;i >= 1;i--){ char c = i + 96; if(c == str[l]) l ++; else if(c == str[r]) r --; else flag = 1; } if(flag) puts("NO"); else puts("YES"); } return 0; } /** **/
C. Pair Programming
input:
5 3 2 2 2 0 0 5 4 3 2 2 0 5 0 6 0 2 2 1 0 2 3 5 4 4 6 0 8 0 0 7 0 9 5 4 1 8 7 8 0 0
output:
2 0 0 5 0 2 0 6 5 -1 0 6 0 7 0 8 0 9 -1
int main() { int _ = read; while(_ --){ int k = read,n = read,m = read; for(int i=1;i<=n;i++) a[i] = read; for(int i=1;i<=m;i++) b[i] = read; int p1 = 1,p2 = 1; vector<int> vet; int flag = 0; while(p1 <= n || p2 <= m){ if(p1 <= n && a[p1] <= k){ if(a[p1] == 0) k++; vet.push_back(a[p1]); p1 ++; } else if(p2 <= m && b[p2] <= k){ if(b[p2] == 0) k ++; vet.push_back(b[p2]); p2 ++; } else{ flag = 1; break; } } if(flag) puts("-1"); else{ int siz = n + m; for(int i=1;i<=siz;i++){ printf("%d ",vet[i-1]); }puts(""); } } return 0; }