【题解】10-8入门组模拟

A.Uim的情人节礼物·其之壱

lnk

1
2
3
4
5
6
7
8
9
10
11
12
13
// Problem:Luogu P2525 Uim的情人节礼物·其之壱

#include<bits/stdc++.h>
using namespace std;
int n,a[10];
int main()
{
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
prev_permutation(a+1,a+1+n);
for(int i=1;i<=n;i++)cout<<a[i]<<" ";
return 0;
}

B. [入门赛 #7] 狠狠地切割 (Hard Version)

lnk

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
// Problem:Luogu P8889  [入门赛 #7] 狠狠地切割 (Hard Version)

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN=500010;
int n,m,cnt,a[MAXN],b[MAXN];
bool flag;
bool check(int val)
{
return binary_search(b+1,b+m+1,val);
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=m;i++)cin>>b[i];
sort(b+1,b+1+m);
for(int i=1;i<=n;i++)
{
if(check(a[i]))
{
if(flag)flag=0;
}
else if(!flag)flag=1,cnt++;
}
cout<<cnt;
}

C.「JYLOI Round 1」箭头调度

lnk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Problem:Luogu P6635 「JYLOI Round 1」箭头调度

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN=200,MAXM=2010;
int n,m,k,res[MAXN],pos[MAXN];
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n>>m>>k;
for(int i=1;i<=n;i++)res[i]=i;
for(int i=1;i<k;i++)next_permutation(res+1,res+1+n);
for(int i=1;i<=n;i++)pos[res[i]]=i;
for(int i=1;i<=m;i++)
{
int u,v;
cin>>u>>v;
cout<<(pos[u]>pos[v]);
}
return 0;
}

D.[SNOI2017] 英雄联盟

lnk

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
// Problem:Luogu P5365 [SNOI2017] 英雄联盟

#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,m,k[300],c[300],sum,dp[114514];
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>k[i];
for(int i=1;i<=n;i++)cin>>c[i],sum+=k[i]*c[i];
dp[0]=1;
for(int i=1;i<=n;i++)
for(int j=sum;j>=0;j--)
for(int l=1;l<=k[i]&&l*c[i]<=j;l++)
dp[j]=max(dp[j],dp[j-l*c[i]]*l);
for(int i=0;i<=sum;i++)
if(dp[i]>=m)
{
cout<<i;
return 0;
}
}

这就只是一个多重背包(?)的模板,就成了蓝?


【题解】10-8入门组模拟
http://j27egu.github.io/2025/10/18/【题解】10-8入门组模拟/
作者
j27eGU
发布于
2025年10月18日
许可协议