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;
}
D
link