A
link
把\(1\)$l-1$和$r+1$\(n\)部分顺序输出\(l\)~\(r\)部分逆序输出。
点击查看代码
#include<bits/stdc++.h>
using namespace std;
int n,l,r;
signed main(){
cin >> n >> l >> r;
for(int i = 1;i < l;++ i)
cout << i << " ";
for(int i = r;i >= l;-- i)
cout << i << " ";
for(int i = r+1;i <= n;++ i)
cout << i << " ";
return 0;
}
B
link
把摄入的所有营养分类加起来(竖着加)与\(a_i\)作比较。
点击查看代码
#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[105];
int x[105];
signed main(){
cin >> n >> m;
for(int i = 1;i <= m;++ i)
cin >> a[i];
for(int i = 1;i <= n;++ i)
for(int j = 1;j <= m;++ j){
int x1;
cin >> x1;
x[j] += x1;
}
for(int i = 1;i <= m;++ i)
if(a[i] > x[i]){
cout << "No";
return 0;
}
cout << "Yes";
return 0;
}
C
link
深搜每一种可能,判断符不符合条件。(每个条件算这些钥匙中实钥匙的个数,够/不够\(K\)个就行)
点击查看代码
#include<bits/stdc++.h>
using namespace std;
int n,m,k;
int ans;
int c[105];
int a[105][25];
char r[105];
int cn,q[25];
void dfs(int x){
if(x > n){
for(int i = 1;i <= m;++ i){
int t = 0;
for(int j = 1;j <= c[i];++ j){
if(q[a[i][j]] == 1) t++;
}
if(t >= k&&r[i] == 'x'
||t < k&&r[i] == 'o'){
return;
}
}
ans++;
return;
}
q[x] = 0;
dfs(x+1);
q[x] = 1;
dfs(x+1);
}
signed main(){
cin >> n >> m >> k;
for(int i = 1;i <= m;++ i){
cin >> c[i];
for(int j = 1;j <= c[i];++ j)
cin >> a[i][j];
cin >> r[i];
}
dfs(1);
cout << ans;
return 0;
}