#include<stdio.h>#include<algorithm>#include<string.h>#include<iostream>#include<map>#include<set>#definelllonglong#definef(i, s, e)for(int i = s; i <= e; i++)#defineff(i, s, e)for(int i = s; i >= e; i--)#definemaxn(ll)(2e5+5000)usingnamespace std;// set<int>::iterator it;char s[maxn];intmain(void){scanf("%s", s);int t =strlen(s);
s[t -1]='4';f(i,0, t -1){printf("%c", s[i]);}return0;}
B - Tetrahedral Number
思路:就是暴力枚举
AC Code
#include<stdio.h>#include<algorithm>#include<string.h>#include<iostream>#include<map>#include<set>#definelllonglong#definef(i, s, e)for(int i = s; i <= e; i++)#defineff(i, s, e)for(int i = s; i >= e; i--)#definemaxn(ll)(2e5+5000)usingnamespace std;// set<int>::iterator it;intmain(void){int n;scanf("%d",&n);f(i,0, n){f(j,0, n){f(k,0, n){if(i + k + j <= n){printf("%d %d %d\n", i, j, k);}}}}return0;}
C - Loong Tracking
思路:维护一个双端队列,根据题意得到一个新的点放进队首,去除队尾
AC Code
#include<stdio.h>#include<algorithm>#include<string.h>#include<iostream>#include<map>#include<set>#include<utility>#include<deque>#include<array>#definelllonglong#definef(i, s, e)for(int i = s; i <= e; i++)#defineff(i, s, e)for(int i = s; i >= e; i--)#definemaxn(ll)(2e5+5000)usingnamespace std;// set<int>::iterator it;
deque<array<int,2>> w;intmain(void){int n, Q;scanf("%d%d",&n,&Q);f(i,1, n){
w.push_back({i,0});}int t;char te;int p;int x =1, y =0;f(i,1, Q){scanf("%d",&t);if(t ==1){scanf("%s",&te);if(te =='U'){
y++;}if(te =='D'){
y--;}if(te =='L'){
x--;}if(te =='R'){
x++;}
w.pop_back();
w.push_front({x, y});}elseif(t ==2){scanf("%d",&p);printf("%d %d\n", w[p -1][0], w[p -1][1]);}}return0;}
D - Loong and Takahashi
思路:构造一个蛇形数组即可
AC Code
#include<stdio.h>#include<algorithm>#include<string.h>#include<iostream>#include<map>#include<set>#definelllonglong#definef(i, s, e)for(int i = s; i <= e; i++)#defineff(i, s, e)for(int i = s; i >= e; i--)#definemaxn(ll)(2e5+5000)usingnamespace std;// set<int>::iterator it;int a[50][50]={0};intmain(void){int n;scanf("%d",&n);int k =1;int x =1, y =1;int l = n, r =1;while(k < n * n){while(a[x][y +1]==0&& y < n){
a[x][y]= k;
k++;
y++;}while(a[x +1][y]==0&& x < n){
a[x][y]= k;
k++;
x++;}while(a[x][y -1]==0&& y >1){
a[x][y]= k;
k++;
y--;}while(a[x -1][y]==0&& x >1){
a[x][y]= k;
k++;
x--;}}int t =(n +1)/2;f(i,1, n){f(j,1, n -1){if(i == t && j == t){printf("T ");continue;}else{printf("%d ", a[i][j]);}}printf("%d\n", a[i][n]);}return0;}