HHKB Programming Contest 2023(AtCoder Beginner Contest 327)
A a.b(略)
B A^A(略)
题意:
You are given an integer B.If there exists a positive integer A such that A^A = B, print its value; otherwise, output -1.
思路:预处理,然后循环遍历输出
C - Number Place(模拟题)
题意:找出行列以及3x3格子内是否完全出现1-9的数
思路:用map存出现的次数,查找然后模拟。
#include <bits/stdc++.h>
using namespace std;
int mp[20][20];
int main()
{
for (int i = 1; i <= 9; i++)
{
for (int j = 1; j <= 9; j++)
{
cin >> mp[i][j];
}
}
int fl1 = 0, fl2 = 0, fl3 = 0;
for (int i = 1; i <= 9; i++)
{
map <int, bool>nummp;
nummp.clear();
for (int j = 1; j <= 9; j++)
{
nummp[mp[i][j]] = true;
}
for (int i = 1; i <= 9; i++)
{
if (!nummp.count(i))
{
cout << "No" << endl;
return 0;
}
}
}
for (int i = 1; i <= 9; i++)
{
map <int, bool>nummp;
nummp.clear();
for (int j = 1; j <= 9; j++)
{
nummp[mp[j][i]] = true;
}
//cout << endl << endl;
for (int i = 1; i <= 9; i++)
{
if (!nummp.count(i))
{
cout << "No" << endl;
return 0;
}
}
}
for (int i = 1; i <= 9; i += 3) //1,1 1,4 1,7 4,1
{
for (int j = 1; j <= 9; j += 3)
{
//枚举起点
map <int, bool>nummp;
nummp.clear();
for (int k = i; k < i + 3; k++)
{
for (int kk = j; kk < j + 3; kk++)
{
//cout << mp[k][kk] << ' ';
nummp[mp[k][kk]] = true;
}
//cout << endl;
}
for (int i = 1; i <= 9; i++)
{
if (!nummp.count(i))
{
cout << "No" << endl;
return 0;
}
}
cout << endl;
}
}
cout << "Yes" << endl;
return 0;
}
D - Good Tuple Problem
题意:给一个长度为n的数列a,由0和1构成,给两个长度为m的数列b,c。使得a[b[i]]!=a[c[i]]。
思路: 符合二分图的特性,把关系相连可作图:
1.若产生回路:回路的点和为偶数。
2.若无回路:都可以。
用染色法。
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1e6+50, M = 1e6+50;
int n, m;
int h[N], e[M], ne[M], idx;
int color[N];
void add(int a, int b)
{
e[idx] = b, ne[idx] = h[a], h[a] = idx ++ ;
}
bool dfs(int u, int c)
{
color[u] = c;
for (int i = h[u]; i != -1; i = ne[i])
{
int j = e[i];
if (!color[j])
{
if (!dfs(j, 3 - c)) return false;
}
else if (color[j] == c) return false;
}
return true;
}
int aa[N];
int bb[N];
int main()
{
scanf("%d%d", &n, &m);//n个点,m条变
int rem = m;
memset(h, -1, sizeof h);
while (m -- )
{
cin>>aa[m];
//cout<<aa[m];
}
m = rem;
//cout<<endl;
while (m -- )
{
cin>>bb[m];
//cout<<bb[m];
}
//cout<<endl;
m = rem;
while(m--)
{
add(aa[m],bb[m]);
add(bb[m],aa[m]);
}
bool flag = true;
for (int i = 0; i <= N-20; i ++ )
if (!color[i])
{
if (!dfs(i, 1))
{
flag = false;
break;
}
}
if (flag) puts("Yes");
else puts("No");
return 0;
}
E - Maximize Rating(DP)
思路:我们需要剖析在这个式子:
首先 分母为定值,可以预处理。
设dp[k][n],意为当k一定的时候,选n个的方式
剖析分子:
当k=1的时候 :
k=1: 0.9^0 * q1
k=2 : 0.9^1 * q1 + 0.9^0*q2
k=3 : 0.9^2q1 + 0.9^1q2 + 0.9^0+q3
结论:可以发现:dp[k][n] = dp[k-1][n-1] * 0.9+qi;找出最大值即可
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
vector<double>num(n+1);
num[1] = 1;//分母
for(int i=2;i<=n;i++)
{
num[i] = num[i-1]*0.9+1;
}//预处理分母
vector<double>dp(n+1,-1e23);
dp[0] = 0;
vector<double>p(n+1);
for(int i=1;i<=n;i++)
{
cin>>p[i];
}
for(int i=1;i<=n;i++)
{
for(int j=i;j>0;j--)
{
dp[j] = max(dp[j],dp[j-1]*0.9+p[i]);
}
}
double ans = -1e23;
for(int i=1;i<=n;i++)
{
ans = max(ans,dp[i]/num[i]-1200/sqrt(i));
}
printf("%.15f", ans);
}