欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 产业 > 牛客周赛 round 63

牛客周赛 round 63

2024/10/24 2:02:19 来源:https://blog.csdn.net/its_a_win/article/details/142926010  浏览:    关键词:牛客周赛 round 63

A

int n;void solve()
{cin >> n;if (n / 100 == 0){int a = n % 10;int b = n / 10;if (a == b) cout << "Yes" << endl;	else cout << "No" << endl;}else cout << "No" << endl;} 

B

要求:原串不是回文串且只需改变一个元素即可变成回文串 。

分类讨论,所给的长度是奇数还是偶数;

cnt是记录破坏回文关系的元素个数,当且仅当cnt = 1时才满足题目要求


int n,k;
int a[N];
LL ans;void solve()
{cin >> n >> k;for (int i = 1;i <= n;i ++) cin >> a[i];for (int i = 1;i + k - 1 <= n;i ++){int j = i + k - 1;int cnt = 0;if (k & 1){int mid = (i + j) >> 1;int st = mid,ed = mid;while(st >= i && ed <= j){if (a[st] != a[ed]) cnt++;st --;ed ++;}if (cnt == 1) ans ++;}else {int st = i,ed = j;while(st < ed){if (a[st] != a[ed]) cnt ++;st ++;ed --;}if (cnt == 1) ans ++;}}cout << ans << endl;
} 

C

一个搜索问题,要求是走过的格子中的数字和起点的数字相同

int n,m;
int a[N][N];
bool st[N][N];
int dx[] = {1,0};
int dy[] = {0,1};bool bfs(int sx,int sy)
{queue<PII> q;q.push({sx,sy});int flag = a[1][1];while(q.size()){auto t = q.front();q.pop();for (int i = 0;i < 2;i ++){int x = t.fi + dx[i],y = t.se + dy[i];if (x < 1 || x > n || y < 1 || y > m) continue;if (a[x][y] != flag) continue;st[x][y] = true;q.push({x,y});}			}return st[n][m];
}void solve()
{cin >> n >> m;memset(a,0,sizeof a);memset(st,false,sizeof st);for (int i = 1;i <= n;i ++)for (int j = 1;j <= m;j ++)cin >> a[i][j];if (bfs(1,1)) cout << "Yes" << endl;else cout << "No" << endl;} 

构造一般是有机可乘的,构造方法如下

1 a 1
d 1 b  => ab + cd - ad - bc => (a - c) * (b - d)
1 c 1   a = 2,c = 1  => b - d = x
int n;
int a[4][4];void solve()
{cin >> n;a[1][1] = 1,a[1][2] = 2,a[1][3] = 1,a[2][1] = 200,a[2][2] = 1,a[2][3] = n + 200,a[3][1] = 1,a[3][2] = 1,a[3][3] = 1;for (int i = 1;i <= 3;i ++){for (int j = 1;j <= 3;j ++)cout << a[i][j] << " ";cout << endl;}} 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com