H - Writing a Numeral
思路:预处理所有*10取模的操作,用队列进行2,3操作,需要调成long long大小,不然报错
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(fast)
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<cstring>
#include<math.h>
#include<map>
#include<vector>
#include<stack>
#include<string>
#define ms(x,y) memset(x,y,sizeof x);
#define YES cout<<"YES"<<'\n';
#define NO cout<<"NO"<<'\n';
#define endl cout<<'\n';
#define int long long
typedef long long ll;
const int maxn=6e5+10,inf = 1e18 ;
using namespace std;
int a[maxn];
int mod = 998244353;
string s = "1";
int ans = 1;
queue<int>q;
void solve(){
int n;
cin >> n;
if (n == 3) {
cout << ans%mod << '\n';
}
if (n == 1) {
int c;
cin >> c;
q.push(c);
ans = (ans * 10 + c) % mod;
}
if (n == 2) {
int x;
x = q.front();
q.pop();
ans = (ll)(ans - x*a[q.size()] % mod + mod)%mod;
}
}
void init() { //预处理
a[0] = 1;
for (int i = 1; i < maxn; i++) {
a[i] = a[i - 1] * 10 % mod;
}
}
signed main()
{
ios::sync_with_stdio(false);
init();
q.push(1);
int t;
cin >> t;
while (t--) {
solve();
}
}
C - Cross
统计各个长度X的数量,暴力枚举位置,如果遇到#,枚举长度,判断是否符合
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(fast)
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<cstring>
#include<math.h>
#include<map>
#include<vector>
#include<stack>
#define ms(x,y) memset(x,y,sizeof x);
#define YES cout<<"YES"<<'\n';
#define NO cout<<"NO"<<'\n';
#define endl cout<<'\n';
typedef long long ll;
const int maxn=2e5+10,inf = 1e18 ;
const int mod = 1e9 + 7;
using namespace std;
char a[110][110];
int h, w;
int check(int x, int y) {
if (a[x][y] != '#') {
return 0;
}
for (int i = 0; i <= min(h, w); i++) { //枚举长度
for (int j = -1; j <= 1; j += 2) {
for (int k = -1; k <= 1; k += 2) {
int dx = x + j * i;
int dy = y + k * i;
if (dx < 0 || dx >= h || dy < 0 || dy >= w) {
return i - 1;
}
if (a[dx][dy]!='#') {
return i - 1;
}
}
}
}
return min(h, w);
}
void solve(){
cin >> h >> w;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
cin >> a[i][j];
}
}
map<int, int>ans;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
ans[check(i, j)]++;
}
}
for (int i = 1; i <= min(h,w); i++) { //
cout << ans[i] << ' ';
}
endl
}
signed main()
{
ios::sync_with_stdio(false);
solve();
}
Same Map in the RPG World
思路:直接暴力枚举,用加取余的方式
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(fast)
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<cstring>
#include<math.h>
#include<map>
#include<vector>
#include<stack>
#define ms(x,y) memset(x,y,sizeof x);
#define YES cout<<"YES"<<'\n';
#define NO cout<<"NO"<<'\n';
#define endl cout<<'\n';
typedef long long ll;
const int maxn=2e5+10,inf = 1e18 ;
const int mod = 1e9 + 7;
using namespace std;
char a[35][35];
char b[35][35];
int h, w;
bool check(int x,int y) {
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (a[(i + x) % h][(j + y) % w] != b[i][j]) {
return false;
}
}
}
return true;
}
void solve(){
cin >> h >> w;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
cin >> a[i][j];
}
}
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
cin >> b[i][j];
}
}
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (check(i, j)) {
cout << "Yes" << '\n';
return;
}
}
}
cout << "No" << '\n';
}
signed main()
{
ios::sync_with_stdio(false);
solve();
}