A题(搜索)
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define ll long long
#define INF 1e18
using namespace std;
const int mod = 1e9 + 7;
const int MAXN = 1e6 + 10;
int m, n;
string mp[MAXN];
void DFS(int x, int y) {
if (mp[x][y] != '.')return;
mp[x][y] = '*';
if (x + 1 < n)DFS(x+1,y);
if (x - 1 >= 0)DFS(x-1,y);
if (y + 1 < m)DFS(x,y+1);
if (y - 1 >=0)DFS(x,y-1);
return;
}
int main() {
ios::sync_with_stdio(false);
cin >> n >> m;
forn(i, 0, n - 1)cin >> mp[i];
forn(i, 0, n - 1)if (mp[i][0] == '.')DFS(i,0);
forn(i, 0, n - 1)if (mp[i][m-1] == '.')DFS(i,m-1);
forn(i, 0, m - 1)if (mp[0][i] == '.')DFS(0,i);
forn(i, 0, m- 1)if (mp[n-1][i] == '.')DFS(n-1,i);
int ans = 0;
forn(i, 0, n - 1)forn(j, 0, m - 1)if (mp[i][j] != '*')ans++;
cout << ans << endl;
return 0;
}
B题(找规律)
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define ll long long
#define INF 1e18
using namespace std;
const int mod = 1e9 + 7;
const int MAXN = 1e6 + 10;
int m, n;
string mp[MAXN];
void DFS(int x, int y) {
if (mp[x][y] != '.')return;
mp[x][y] = '*';
if (x + 1 < n)DFS(x + 1, y);
if (x - 1 >= 0)DFS(x - 1, y);
if (y + 1 < m)DFS(x, y + 1);
if (y - 1 >= 0)DFS(x, y - 1);
return;
}
int main() {
ios::sync_with_stdio(false);
int t; cin >> t;
while (t--) {
int n; cin >> n;
if (n == 1) printf("Kozilek, Butcher of Truth\n");
else
printf("Ulamog, the Infinite Gyre\n");
}
return 0;
}
D题(模拟)
#include <iostream>
#include <bits/stdc++.h>
#include <set>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
string str,com;
cin>>str>>com;
string::iterator i=com.begin();
int ind=0;
int mod=0;
while(i!=com.end()){
char c=*(i++);
char t;
int ii;
if(mod){
if(c=='e')
mod=0;
else str.insert(str.begin()+ind++,c);
continue;
}
switch(c){
case 'i':mod=1;break;
case 'f':t=*(i++);
ii=ind+1;
while(ii<str.size()){
if(str[ii]==t){
ind=ii;
break;
}
ii++;
}break;
case 'x':str.erase(str.begin()+ind);break;
case 'l':if(ind<str.size()) ind++;break;
case 'h':if(ind>0)ind--;break;
default :break;
}
}
cout<<str<<endl;
return 0;
}
E题(思维)
#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
if(n==1){
cout<<"0 0 1 1"<<endl;
cout<<"0 0 1 0"<<endl;
continue;
}
for(int i=0;i<n-1;i+=2){
printf("%d %d %d %d\n",i,0,n,n-1-i);
}
for(int i=1;i<n-1;i+=2){
printf("%d %d %d %d\n",0,i,n-1-i,n);
}
printf("%d %d %d %d\n",0,n,n,n-1);
printf("%d %d %d %d\n",n,0,n-1,n);
}
return 0;
}