这场打的div1 …

C

把因子2和3除去比较是否相等即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<bits/stdc++.h>
using namespace std;

int main()
{
int n;
scanf("%d",&n);
int cur = -1;
bool flag = true;
for(int i=0;i<n;++i)
{
int x;
scanf("%d",&x);
if(flag == false) continue;
while(x%2 == 0) x/=2;
while(x%3 == 0) x/=3;
if(cur != -1 && cur!=x) flag = false;
cur = x;
}
puts(flag?"Yes":"No");
return 0;
}

D

题目是给出一列高度不同的积木,每次可以消除与空气接触的块
d[i] 表示消除当前块最少需要多少次,我们可以发现
d[i] = min(h[i],i,n-i+1,d[i-1]+1,d[i+1]+1)
然后需要 max(d[i]) 次可以全部消除

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include<bits/stdc++.h>
using namespace std;

const int maxn = 100010;
const int INF = 0x3f3f3f3f;
int a[maxn],n,res[maxn];

void ch(int &a,int b)
{
if(a>b) a = b;
}

int main()
{
//freopen("test.txt","r",stdin);
while(scanf("%d",&n)==1)
{
for(int i = 1;i<=n;++i) scanf("%d",a+i);
a[0] = a[n+1] = 0;
for(int i=1;i<=n;++i)
{
res[i] = a[i];
ch(res[i],i);
ch(res[i],n-i+1);
ch(res[i],res[i-1]+1);
// printf("%d %d\n",i,res[i]);
}
int ans = 1;
for(int i=n;i>=1;--i)
{
ch(res[i],res[i+1]+1);
ans = max(ans,res[i]);
}
printf("%d\n",ans);
}
return 0;
}