寒假营第五场题解

题目难度

Easy:A B J I

Mid:E C

Hard:L D H

AK:K F

A L 的三则运算

签到题

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;
using u32 = unsigned;
#define i128 __int128;
using ll = long long;
#define int ll
using u64 = unsigned long long;
const ll inf = 1e9;
const ll INF = 1e18;

signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int shu;
char ch;
cin>>shu>>ch;
if(ch=='*')cout<<1<<' '<<shu<<'\n';
else if(ch=='+')cout<<1<<' '<<shu-1<<'\n';
else cout<<shu+1<<' '<<1<<'\n';
return 0;
}

B L 出师了

https://ac.nowcoder.com/acm/contest/95337/B

小思维题。

转化一下,就是我们考虑用 k 个隔板把 n k 个排成一排的箱子分成 k + 1 份,转化

后就允许为空了。然后使其尽可能多的份数大于等于 t ,所以答案就是 min((n-k)/t

, k* + 1) 。

一次回答复杂度 O(1)

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
#include<bits/stdc++.h>
using namespace std;
using u32 = unsigned;
#define i128 __int128
using ll = long long;
#define int ll
using u64 = unsigned long long;
const ll inf = 1e9;
const ll INF = 1e18;
void solve(){
int n,t,k;
cin>>n>>t>>k;
int shu=n-k;
int ret=min(shu/t,k+1);
cout<<ret<<'\n';
}

signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tt;cin>>tt;
while(tt--){
solve();
}


return 0;
}

J L 的汽车行驶问题

https://ac.nowcoder.com/acm/contest/95337/J

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
38
39
40
41
42
43
#include<bits/stdc++.h>
using namespace std;
using u32 = unsigned;
#define i128 __int128;
using ll = long long;
#define int ll
using u64 = unsigned long long;
const ll inf = 1e9;
const ll INF = 1e18;

signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin>>n;
string s;
cin>>s;
int v=0;
int ans=0;
for(auto ch:s)
{
if(ch=='0')
{
v+=10;
ans+=v;
}
else if(ch=='1')
{
v=max(v-5,0ll);
ans+=v;
}
else
{
int shu=v;
v=max(v-10,0ll);
ans+=v;
v=shu;
}
}
cout<<ans<<'\n';
return 0;
}

I L 的数学题

https://ac.nowcoder.com/acm/contest/95337/I

一道可以猜猜就过的题。

nm 中仅有一个是 0 ,就是 No

如果都是 0 ,就是 Y es

否则,大于 0 的正整数是一定可以互相转换的,证明如下:

首先,任何正整数都能达到 1 。

考虑一个数 k 2 j

x < (k + 1)2 j

,那么 xj 次 sqrt 就可以得到 k

两边取 log2,j 足够大的时候 2 j (log2(k + 1) log2(k)) > 1 ,所以一定有整数 i

2 j log2(k) 和 2 j log2(k + 1) 之间。

x = 2i

即可得到 k

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
#include<bits/stdc++.h>
using namespace std;
using u32 = unsigned;
#define i128 __int128
using ll = long long;
//#define int ll
using u64 = unsigned long long;
const ll inf = 1e9;
const ll INF = 1e18;
void solve(){
int a,b;
cin>>a>>b;
if(a==b)cout<<"Yes\n";
else if(a==0||b==0)cout<<"No\n";
else cout<<"Yes\n";
}

signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tt;cin>>tt;
while(tt--){
solve();
}


return 0;
}