A
Good morning |
题意:
高桥A点过B分起床,赤木C点过D分起床(晚一秒,如果高桥和赤木时间一样高桥先起床)。求谁先起床。
题解:
先比较A,C的大小,C大说明赤木晚起。
如果A,C大小相同,那么再比较B,D如果D大于B说明赤木晚起。
代码:
#include<iostream>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 2 * 1e5 + 10, inf = 1e9, mod = 998244353;
int n;
int a, b, c, d;
void solve()
{
cin >> a >> b >> c >> d;
if (a < c)
cout << "Takahashi";
else if (a == c)
if (b <= d)
cout << "Takahashi";
else
cout << "Aoki";
else
cout << "Aoki";
}
int main()
{
int t = 1;
//cin >> t;
while (t--)
{
solve();
}
return 0;
}
B
题意:
由N个数组成的序列判断其中未出现的最小的非负整数。
题解:
将序列中的数存入map中计为1,然后从0开始遍历,直到出现map未出现的数,输出这个数。
代码:
#include<iostream>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 2 * 1e5 + 10, inf = 1e9, mod = 998244353;
int n;
int a[N];
map<int, int>m;
void solve()
{
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> a[i];
m[a[i]] = 1;
}
for (int i = 0;; i++)
{
if (m[i] == 0)
{
cout << i;
return;
}
}
}
int main()
{
int t = 1;
//cin >> t;
while (t--)
{
solve();
}
return 0;
}
C
题意:
给你两个序列A,B,判断序列X对于每个i,Xi=Ai or Bi,是否都能满足|Xi-Xi+1|<=k。
题解:
这题可用动态规划来做。
首先我们用dp[1][i]=1来表示a[i]可用。
用dp[0][i]=1来表示b[i]可用。
那么判断当前数字是否可用只需要判断当前数字与a[i-1],b[i-1]中可用的数字之差绝对值小于等于k。
如果当前数字可用如果为a[i]那么标记dp[1][i]=1,反之标记dp[0][i]=1。
注意在最开始时要注意要使dp[1][1],dp[0][1]初始化为1,因为第一个数字肯定是可以选的。
代码:
#include<iostream>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 2 * 1e5 + 10, inf = 1e9, mod = 998244353;
int n, k;
int a[N], b[N];
int dp[2][N], p[N];
map<int, int>m;
void solve()
{
cin >> n >> k;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
cin >> b[i];
dp[1][1] = 1; dp[0][1] = 1;
for (int i = 2; i <= n; i++)
{
if ((dp[1][i - 1] && abs(a[i] - a[i - 1]) <= k) || (dp[0][i - 1] && abs(a[i] - b[i - 1]) <= k))
dp[1][i] = 1;
if ((dp[0][i - 1] && abs(b[i] - b[i - 1]) <= k) || (dp[1][i - 1] && abs(b[i] - a[i - 1]) <= k))
dp[0][i] = 1;
}
if (dp[0][n] == 0 && dp[1][n] == 0)
cout << "No";
else
cout << "Yes";
}
int main()
{
int t = 1;
//cin >> t;
while (t--)
{
solve();
}
return 0;
}