https://codeforces.com/gym/105229
A
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,m;
cin>>n>>m;
for (int a = 0; a <= n; a++) {
for (int b = 0; b <= m; b++) {
int ans = 0;
for (int c = 0; c <= n; c++) {
for (int d = 0; d <= m; d++) {
if (a == c && b == d) continue;
// 正方形面积不为零,所以对角线上的两个点不能重合
if ((b + c - a - d) % 2 != 0) continue;
int num = (b + c - a - d) / 2;
int x1 = a + num, y1 = d + num;
int x2 = c - num, y2 = b - num;
if (x1 >= 0 && x1 <= n && y1 >= 0 && y1 <= m && x2 >= 0 && x2 <= n && y2 >= 0 && y2 <= m) ans++;
}
}
printf("%d ", ans);
}
puts("");
}
return 0;
}
M
#include <bits/stdc++.h>
using namespace std;
const int N=1e3+10;
int a[N][N];
vector<pair<int,int>>v1,v2;
int main()
{
int n;
cin>>n;
int t=sqrt(n);
if(n-t*t>t)t++;
int cnt=0;
for(int i=1;i<=t+1;i++)
{
for(int j=1;j<=t;j++)
{
a[i][j]=++cnt;
if(cnt>n)
a[i][j]=0;
}
}
for(int i=1;i<=t+1;i++)
{
for(int j=1;j<=t;j++)
{
if(a[i+1][j])v1.push_back({a[i][j],a[i+1][j]});
if(a[i][j+1])v2.push_back({a[i][j],a[i][j+1]});
}
}
int size = min(v1.size(), v2.size());
printf("%d\n", size);
for (int i = 0; i < size; i++) printf("%d %d\n", v1[i].first, v1[i].second);
for (int i = 0; i < size; i++) printf("%d %d\n", v2[i].first, v2[i].second);
}
E
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
void solve()
{
int n;
cin >> n;
string s;
cin >> s;
array<int,26> cnt{};
for(auto &c : s) {
c = tolower(c);
cnt[c - 'a'] ++;
}
cout << min({cnt['s'-'a'],cnt['h'-'a']/2,cnt['a'-'a']/2,cnt['n'-'a'],cnt['g'-'a'],cnt['i'-'a']}) << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int T=1;
//cin>>T;
while(T--)
solve();
return 0;
}
J
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
vector<int> pri;
bool not_prime[N];
void pre(int n) {
for (int i = 2; i <= n; ++i)
{
if (!not_prime[i])
{
pri.push_back(i);
}
for (int pri_j : pri)
{
if (i * pri_j > n) break;
not_prime[i * pri_j] = true;
if (i % pri_j == 0) {
// i % pri_j == 0
// 换言之,i 之前被 pri_j 筛过了
// 由于 pri 里面质数是从小到大的,所以 i 乘上其他的质数的结果一定会被
// pri_j 的倍数筛掉,就不需要在这里先筛一次,所以这里直接 break
// 掉就好了
break;
}
}
}
}
void solve()
{
int n;
cin >> n;
vector<int> a(n + 1);
for(int i = 1 ; i <= n ; i ++)
{
cin >> a[i];
}
for(int k = 0 ; k <= n ; k ++)
{
for(int i = 1 ; i <= n ; i ++)
{
int s = 0;
for(int j = i ; j - i <= k && j <= n; j ++)
{
s += a[j];
}
if(not_prime[s]) {
cout << k << endl;
return ;
}
}
}
cout << -1 << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t = 1;
cin >> t;
pre(N);
//cout<<not_prime[9]<<endl;
while(t--)
solve();
return 0;
}